//========== Email Validation =================
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

//============== User Registration validation ===================
function user_validate()
{
	if((trim(jQuery('#username').val())==''))
	{
		alert("Please Enter a Unique username.");
		jQuery('#username').focus();
		return false;
	}
	if((trim(jQuery('#password').val())).length < 6 )
	{
		alert("Password should be more than 6 characters..");
		jQuery('#password').focus();
		return false;
	}
	if(trim(jQuery('#password').val()) != trim(jQuery('#repassword').val()))
	{
		alert("Passwords should be matched.");
		jQuery('#password').focus();
		return false;
	}
	if((trim(jQuery('#fname').val())).length < 3 )
	{
		alert("First Name should be more than 3 characters..");
		jQuery('#fname').focus();
		return false;
	}
	if((trim(jQuery('#lname').val())).length < 3 )
	{
		alert("Last Name should be more than 3 characters..");
		jQuery('#lname').focus();
		return false;
	}
	if(!isValidEmailAddress(jQuery('#admin_email').val()))
	{
		alert("Please enter a valid email address.");
		jQuery('#admin_email').focus();
		return false;
	}
}

//=====================Facebook==============================
function show_fb_login()
{
	var inviteuser=jQuery('#invite_user_id').val();
	window.open("/revelri/fb/login",'_new','width=900,height=500,toolbar=0,status=0');
}

//=====================Admin USerType==============================
function usertype_valid()
{
	if((trim(jQuery('#usertype').val())==''))
	{
		alert("Please Enter a Unique usertype.");
		jQuery('#usertype').focus();
		return false;
	}
	if((trim(jQuery('#usertype').val())).length < 2 )
	{
		alert("Usertype should not be less than 2 characters .");
		jQuery('#usertype').focus();
		return false;
	}
	if((trim(jQuery('#usertype').val())).length > 30 )
	{
		alert("Usertype should not be greater than 30 characters .");
		jQuery('#usertype').focus();
		return false;
	}
	
}


//====================Admin User Type==================================
function adminuser_valid()
{
	if((trim(jQuery('#username').val())==''))
	{
		alert("Please Enter a Unique username.");
		jQuery('#username').focus();
		return false;
	}
	if((trim(jQuery('#password').val())==''))
	{
		alert("Please Enter strong Password.");
		jQuery('#password').focus();
		return false;
	}
	if((trim(jQuery('#password').val())).length < 6 )
	{
		alert("Password should not be less than 6 characters .");
		jQuery('#password').focus();
		return false;
	}
	if((trim(jQuery('#repassword').val())==''))
	{
		alert("Please Re Enter Password.");
		jQuery('#repassword').focus();
		return false;
	}
	// if((trim(jQuery('#repassword').val())).length < 6 )
	// {
		// alert("Password should not be less than 6 characters .");
		// jQuery('#repassword').focus();
		// return false;
	// }
	if(trim(jQuery('#password').val()) != trim(jQuery('#repassword').val()))
	{
		alert("Passwords should be matched.");
		jQuery('#password').focus();
		return false;
	}
	if((trim(jQuery('#fname').val())).length < 3 )
	{
		alert("First Name should be more than 3 characters..");
		jQuery('#fname').focus();
		return false;
	}
	if((trim(jQuery('#lname').val())).length < 3 )
	{
		alert("Last Name should be more than 3 characters..");
		jQuery('#lname').focus();
		return false;
	}
	if(!isValidEmailAddress(trim(jQuery('#admin_email').val())))
	{
		alert("Please enter a valid email address.");
		jQuery('#admin_email').focus();
		return false;
	}
}



function validateForm(formId)
{
	if( $.trim($('#ddlstCMS').val()) )
	{
		alert("Please select a type!");
		jQuery('#ddlstCMS').focus();
		return false;
	}
	if( $.trim(CKEDITOR.instances['txtContentDescription'].getData()) )
	{
		alert("Please proveide some content!");
		jQuery('#txtContentDescription').focus();
		return false;
	}
	
	var params = $('#' + formId).serialize();
	var url = "http://" + host + path + "cmss/update_content/" + $('#ddlstCMS').val();
	//$.ajax(url, 
	
}

//====================Condition==================================
function admincondition_valid() {
	if( (trim(jQuery('#title').val())).length == 0 )
	{
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
	if( (trim(jQuery('#url_extension').val())).length == 0 )
	{
		alert("Please enter some page url!");
		jQuery('#url_extension').focus();
		return false;
	}
}
function adminlife_valid() {
	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
	if( (trim(jQuery('#LifeChangeDesc').val())).length == 0 ) {
		alert("Please enter some description!");
		jQuery('#LifeChangeDesc').focus();
		return false;
	}
	if( (trim(jQuery('#LifeChangeAdditionalInfo').val())).length == 0 ) {
		alert("Please enter some AdditionalInfo!");
		jQuery('#LifeChangeAdditionalInfo').focus();
		return false;
	}
}

function adminproduct_valid() {
	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
/* 	if( (trim(jQuery('#video_title').val())).length == 0 )
	{
		alert("Please enter some video title!");
		jQuery('#video_title').focus();
		return false;
	}
	if( (trim(jQuery('#video_link').val())).length == 0 )
	{
		alert("Please enter some video link!");
		jQuery('#video_link').focus();
		return false;
	}
 */	
	if( !jQuery('#product_cat option').is(':selected') ) {
		alert("Please select some category!");
		jQuery('#product_cat').focus();
		return false;
	}
	if( !jQuery('#condition option').is(':selected') ) {
		alert("Please select some condition!");
		jQuery('#condition').focus();
		return false;
	}
}

function report_bug_valid() {
	if( (trim(jQuery('#user_info_id').val())).length == 0 ) {
		alert("Please enter some user info id!");
		jQuery('#user_info_id').focus();
		return false;
	}
 	if( (trim(jQuery('#username').val())).length == 0 ) {
		alert("Please enter some username!");
		jQuery('#username').focus();
		return false;
	}
	if( (trim(jQuery('#ip').val())).length == 0 ) {
		alert("Please enter some ip");
		jQuery('#ip').focus();
		return false;
	}
	if(!isValidEmailAddress(jQuery('#email').val())) {
		alert("Please enter a valid email address.");
		jQuery('#email').focus();
		return false;
	}
 	if( (trim(jQuery('#inapp_url').val())).length == 0 ) {
		alert("Please enter the inappropriate url!");
		jQuery('#inapp_url').focus();
		return false;
	}
 	if( (trim(jQuery('#send_date').val())).length == 0 ) {
		alert("Please enter some send date!");
		jQuery('#send_date').focus();
		return false;
	}
 	if( (trim(jQuery('#reply_date').val())).length == 0 ) {
		alert("Please enter some reply date!");
		jQuery('#reply_date').focus();
		return false;
	}
 	if( (trim(jQuery('#status').val())).length == 0 ) {
		alert("Please select some status!");
		jQuery('#status').focus();
		return false;
	}
}

function report_tooltip_valid() {
 	if( (trim(jQuery('#function_name').val())).length == 0 ) {
		alert("Please enter some function name!");
		jQuery('#function_name').focus();
		return false;
	}
 	if( (trim(jQuery('#page_name').val())).length == 0 ) {
		alert("Please enter some page name!");
		jQuery('#page_name').focus();
		return false;
	}
 	if( (trim(jQuery('#page_url').val())).length == 0 ) {
		alert("Please enter some page url!");
		jQuery('#page_url').focus();
		return false;
	}
}

function tooltip_fields_valid() {
 	if( (trim(jQuery('#tooltip_id').val())).length == 0 ) {
		alert("Please select some tooltip!");
		jQuery('#tooltip_id').focus();
		return false;
	}
 	if( (trim(jQuery('#display_name').val())).length == 0 ) {
		alert("Please enter some display name!");
		jQuery('#display_name').focus();
		return false;
	}
 	if( (trim(jQuery('#field_name').val())).length == 0 ) {
		alert("Please enter some field name!");
		jQuery('#field_name').focus();
		return false;
	}
 	if( (trim(jQuery('#tooltip_info').val())).length == 0 ) {
		alert("Please enter some tooltip info!");
		jQuery('#tooltip_info').focus();
		return false;
	}
}

function ArticleKeywords_valid() {
 	if( (trim(jQuery('#article_id').val())).length == 0 ) {
		alert("Please select some article!");
		jQuery('#article_id').focus();
		return false;
	}
 	if( (trim(jQuery('#keywords').val())).length == 0 ) {
		alert("Please enter some keywords!");
		jQuery('#keywords').focus();
		return false;
	}
}

function seo_valid() {
 	if( (trim(jQuery('#page_name').val())).length == 0 ) {
		alert("Please enter some page name!");
		jQuery('#page_name').focus();
		return false;
	}
 	if( (trim(jQuery('#page_title').val())).length == 0 ) {
		alert("Please enter some page title!");
		jQuery('#page_title').focus();
		return false;
	}
 	if( (trim(jQuery('#meta_description').val())).length == 0 ) {
		alert("Please select some meta description!");
		jQuery('#meta_description').focus();
		return false;
	}
 	if( (trim(jQuery('#meta_tag').val())).length == 0 ) {
		alert("Please enter some meta tag!");
		jQuery('#meta_tag').focus();
		return false;
	}
}

function pagecontents_valid() {
 	if( (trim(jQuery('#pagetitle').val())).length == 0 ) {
		alert("Please enter some page title!");
		jQuery('#pagetitle').focus();
		return false;
	}
 	if( (trim(jQuery('#page_url').val())).length == 0 ) {
		alert("Please enter some page url!");
		jQuery('#page_url').focus();
		return false;
	}
 	/*if( (trim(jQuery('#metakey').val())).length == 0 ) {
		alert("Please enter some metakey!");
		jQuery('#metakey').focus();
		return false;
	}
 	if( (trim(jQuery('#metadesc').val())).length == 0 ) {
		alert("Please enter some meta description!");
		jQuery('#metadesc').focus();
		return false;
	}
 	if( (trim(jQuery('#content').val())).length == 0 ) {
		alert("Please enter some content!");
		jQuery('#content').focus();
		return false;
	}*/
	return true;
}

function helps_valid() {
 	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
 	if( (trim(jQuery('#content').val())).length == 0 ) {
		alert("Please enter some help content!");
		jQuery('#content').focus();
		return false;
	}
	return true;
}

function inapp_content_valid() {
 	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
 	if( (trim(jQuery('#desc').val())).length == 0 ) {
		alert("Please enter some description!");
		jQuery('#desc').focus();
		return false;
	}
 	if( (trim(jQuery('#link').val())).length == 0 ) {
		alert("Please enter some URL!");
		jQuery('#link').focus();
		return false;
	}
	return true;
}

function isValidUrlTitle(url_title) {
	//var pattern = new RegExp("[abc]");
	var pattern = /[\s:]/;
	return pattern.test(url_title);
}

function adminarticle_valid() {
	if( (trim(jQuery('#article_title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#article_title').focus();
		return false;
	}
	if( (trim(jQuery('#url_title').val())).length == 0 ) {
		alert("Please enter URL Title!");
		jQuery('#url_title').focus();
		return false;
	}
	if( isValidUrlTitle(jQuery('#url_title').val()) ) {
		alert("Special characters Such as ': whitespace' are not allowed in URL Extension.");
		jQuery('#url_title').focus();
		return false;
	}
/* 	if( (trim(jQuery('#url_title').val())).length == 0 ) {
		alert("Please enter some url title!");
		jQuery('#url_title').focus();
		return false;
	}
	if( !jQuery('#article_type option').is(':selected') ) {
		alert("Please select some article type!");
		jQuery('#article_type').focus();
		return false;
	}
 */ 	
	if( !$.trim(CKEDITOR.instances['article_text'].getData()) ) {
		alert("Please enter some article text!");
		CKEDITOR.instances['article_text'].focus();
		return false;
	}
}
//================
function articletype_valid() {
 	if( (trim(jQuery('#article_type').val())).length == 0 ) {
		alert("Please enter some article type!");
		jQuery('#article_type').focus();
		return false;
	}
}


function story_valid() {
 	if( (trim(jQuery('#story_title').val())).length == 0 ) {
		alert("Please enter some story title!");
		jQuery('#story_title').focus();
		return false;
	}
 	if( (trim(jQuery('#url_title').val())).length == 0 ) {
		alert("Please enter some url title!");
		jQuery('#url_title').focus();
		return false;
	}
 	if( !jQuery('#condition option').is(':selected')) {
		alert("Please select some condition(s)!");
		jQuery('#condition').focus();
		return false;
	}
}

function video_valid() {
 	if( (trim(jQuery('#video_link').val())).length == 0 ) {
		alert("Please enter some video link!");
		jQuery('#video_link').focus();
		return false;
	}
 	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter some title!");
		jQuery('#title').focus();
		return false;
	}
 	if( !jQuery('#video_cat option').is(':selected')) {
		alert("Please select some category!");
		jQuery('#video_cat').focus();
		return false;
	}
}

function adminbooks_valid() {
 	if( (trim(jQuery('#name').val())).length == 0 ) {
		alert("Please enter some Title to display!");
		jQuery('#name').focus();
		return false;
	}
  	if( (trim(jQuery('#book').val())).length == 0 ) {
		alert("Please select some book to upload!");
		jQuery('#book').focus();
		return false;
	}
  	if( !jQuery('#booktype option').is(':selected')) {
		alert("Please select some book type!");
		jQuery('#booktype').focus();
		return false;
	}
}

function adminbooktype_valid() {
 	if( (trim(jQuery('#name').val())).length == 0 ) {
		alert("Please enter some book type!");
		jQuery('#name').focus();
		return false;
	}
}



////--------   CMS functions start here    ---------------////////

function add_content(panel) {
	var select_count = $('#select_count_'+panel).val();
	
	//alert($('#btn'+select_count).hasClass('btn-4'));
	//alert(select_count);
	//$('#cont_type'+select_count).attr("readonly", true);
	//$('#btn'+select_count).attr("disabled", true); // Disabling the previous button.
		
	//$('#btn'+select_count).val("-"); // Disabling the previous button.
	//$('#btn'+select_count).removeClass('btn-3').addClass('btn-4');
	
	//var remove_function = '$("#container' + select_count +'").remove();';
	//alert(remove_function);
	//var remove_function = "alert('hi');";
	// create a function from the "remove_function" string
	//var newclick = new Function(remove_function);
	// clears onclick then sets click using jQuery
	//$("#anchor").attr('onclick', '').attr('onclick', newclick);
	
	//document.getElementById("btn"+select_count).click = new function() { alert('hi'); };
	//$('#btn'+select_count).unbind('click').bind('click', function() {
		//alert($(this).text());
		//alert('hi');
	//});
	
	$('#btn_'+panel+'_'+select_count).hide();
	$('#rmbtn_'+panel+'_'+select_count).show();
	
	select_count = parseInt(select_count) + 1;
	//alert(select_count);
	$('#select_count_'+panel).val(select_count);	

	var content = '<div id="container_'+panel+'_' + select_count + '">\
						<div class="inner-header-top-spacer"></div>\
						<div class="admin-inner-border"></div>\
						<div class="form-body-area">\
							<div class="question-area">Choose Content Type</div>\
							<div class="answer-area">\
								<select name="data[CmsPages][cont_type_'+panel+'_' + select_count + ']" id="cont_type_'+panel+'_' + select_count + '" class="field-input-drop" onchange="content_type(\'' + panel + '\', this.value, ' + select_count + ')"  onmouseover="document.getElementById(\'conttype_' + panel + '_' + select_count + '\').style.display=\'block\'" onmouseout="document.getElementById(\'conttype_' + panel + '_' + select_count + '\').style.display=\'none\'">\
								' + $("#options").val() +
								'</select>\
								<div align="right" valign="top" style="float:right; height:24px; width:25px;">\
									<input type="button" value="+" id="btn_'+panel+'_' + select_count + '" class="btn-3" title="Add More Content" onclick="add_content(\'' + panel + '\')">\
									<input type="button" value="-" id="rmbtn_'+panel+'_' + select_count + '" class="btn-4" title="Remove Content" style="display:none;" onclick="remove_content( \'' + panel + '\', ' + select_count + ')">\
								</div>\
							</div>\
							<div class="help-callout-area2" id="conttype_'+ panel +'_' + select_count + '" style="display:none;">\
								<p>Please select content type </p>\
							</div>\
							<div class="balance"></div>\
						</div>\
						<div class="balance"></div>\
						<div id="tabs-3Content_' + panel + '_' + select_count + '">\
						</div>\
					</div>';
	// jQuery('#add-div').html(jQuery('#add-div').html() + content);
	jQuery('#add-div_' + panel).append(content);
}

function remove_content(panel, select_count) {
	remove_data_count(panel, select_count);
	//alert($('#data_count_'+panel).val());
	$('#container_' + panel + '_' + select_count).remove();
	//alert($('#data_count_'+panel).val());
}

function content_type(panel, val, select_count) {
	//if(panel == 'f') { select_count = '' }
	if(val == '1' || val == '2' || val == '3') {
		//var art_type_count = $('#art_type_count').val();
		var add_text = '<div class="form-body-area">\
							<div class="question-area">Number of Articles</div>\
							<div class="answer-area">\
								<input type="text" name="data[CmsPages][no_of_art_' + panel + '_' + select_count + ']" id="no_of_art_' + panel + '_' + select_count + '" maxlength="5" class="field-input3">\
							</div>\
							<div class="balance"></div>\
						</div>\
						<div class="balance"></div>';
		//art_type_count = parseInt(art_type_count) + 1;
		//alert(art_type_count);
		//$('#art_type_count').val(art_type_count);	
		if(panel != 'f') { add_data_count(panel, select_count); }
	} else if (val == '4') {
		//var banner_count = $('#banner_count').val();
		var add_text = '<div class="form-body-area">\
							<div class="question-area">Upload Image</div>\
							<div class="answer-area">\
								<input type="file" name="banner_' + panel + '_' + select_count + '" id="banner_' + panel + '_' + select_count + '" class="field-input" size="34" />\
							</div>\
							<div class="balance"></div>\
						</div>\
						<div class="form-body-area">\
							<div class="question-area">Banner Link</div>\
							<div class="answer-area">\
								<select name="data[CmsPages][cms_pages_'+panel+'_' + select_count + ']" id="cms_pages_'+panel+'_' + select_count + '" class="field-input-drop" onchange="showhref(\''+panel+'\',\''+select_count+'\',\''+this+'\')"  onmouseover="document.getElementById(\'conttype_' + panel + '_' + select_count + '\').style.display=\'block\'" onmouseout="document.getElementById(\'conttype_' + panel + '_' + select_count + '\').style.display=\'none\'">\
								' + $("#cms_pages").val() +
								'</select>\
							</div>\
							<div class="balance"></div>\
						</div>\
						<div class="form-body-area" id = "cms_href_div_' + panel + '_' + select_count + '" style="display:none;">\
							<div class="question-area">External Link</div>\
							<div class="answer-area">\
								<input type="text" name="data[CmsPages][img_link_' + panel + '_' + select_count + ']" id="img_link_' + panel + '_' + select_count + '" class="field-input" size="34" />\
							</div>\
							<div class="balance"></div>\
						</div>\
						<div class="balance"></div>';
		//banner_count = parseInt(banner_count) + 1;
		//alert(add_text);
		//$('#banner_count').val(banner_count);	
		if(panel != 'f') { add_data_count(panel, select_count); }
	} else {
		var add_text = '';
		if(panel != 'f') { remove_data_count(panel, select_count); }
	}
	//var select_count = $('#select_count').val();
	jQuery('#tabs-3Content_' + panel + '_' + select_count).html(add_text); 
}
// For Show the Href
function showhref(panel,select_count,t){
	var selectmenu=document.getElementById("cms_pages_"+panel+'_'+select_count);
	var chosenoption=selectmenu.options[selectmenu.selectedIndex].value;
	if(chosenoption == "-1"){document.getElementById('cms_href_div_'+panel+'_'+select_count).style.display = "block"}else{document.getElementById('cms_href_div_'+panel+'_'+select_count).style.display = "none"}

}
//var data_array = [];
function add_data_count(panel, select_count) {
	var temp_val = $('#data_count_' + panel).val();
	var split_arr = temp_val.split(",");
	select_count = "" + select_count;
	arr_index = jQuery.inArray(select_count, split_arr);
	
	if(arr_index < 0) {
		var temp_val = $('#data_count_' + panel).val();
		if(temp_val) {
			$('#data_count_' + panel).val(temp_val + ',' + select_count);
		} else {
			$('#data_count_' + panel).val(select_count);
		}
		//alert($('#data_count_'+panel).val());
	}
}

function remove_data_count(panel, select_count) {
	var temp_val = $('#data_count_' + panel).val();
	var split_arr = temp_val.split(",");
	select_count = "" + select_count;
	arr_index = jQuery.inArray(select_count, split_arr);
	if(arr_index >= 0) {
		split_arr.splice(arr_index,1);
		$('#data_count_' + panel).val(split_arr.join(","));
	}
}

function cms_valid() {
 	if( (trim(jQuery('#pagetitle').val())).length == 0 || jQuery('#pagetitle').val().indexOf(" ") >= 0) {
		alert("Please enter pagetitle without spaces!");
		jQuery('#pagetitle').focus();
		return false;
	}
 	if( (trim(jQuery('#titletag').val())).length == 0 ) {
		alert("Please enter titletag. It'll be shown on the page's title bar!");
		jQuery('#titletag').focus();
		return false;
	}
 	if( (trim(jQuery('#metakey').val())).length == 0 ) {
		alert("Please enter some meta key!");
		jQuery('#metakey').focus();
		return false;
	}
 	if( (trim(jQuery('#metadesc').val())).length == 0 ) {
		alert("Please enter some meta description!");
		jQuery('#metadesc').focus();
		return false;
	}
 	if( (trim(jQuery('#header_image').val())).length == 0 ) {
		alert("Please select some picture for header!");
		jQuery('#header_image').focus();
		return false;
	}
 	if( (trim(jQuery('#layout_id').val())).length == 0 ) {
		alert("Please select layout!");
		jQuery('#layout_id').focus();
		return false;
	}
 	if( (trim(jQuery('#cont_type_f_0').val())).length == 0 ) {
		alert("Please select some option for footer!");
		jQuery('#cont_type_f_0').focus();
		return false;
	} else {
		var val = parseInt(jQuery('#cont_type_f_0').val());
		if(( val == 1 || val == 2 || val == 3 )) {
			if(jQuery('#no_of_art_f_0').val().length == 0) {
				alert("Please enter number of article!");
				jQuery('#no_of_art_f_0').focus();
				return false;
			} else if(isNaN(jQuery('#no_of_art_f_0').val())) {
				alert("This is not a number!");
				jQuery('#no_of_art_f_0').focus();
				return false;
			}
		} else if(( val == 4 ) &&  jQuery('#banner_f_0').val().length == 0) {
			alert("Please select some file to upload!");
			return false;
		}
	}
	
 	if( (trim(jQuery('#cont_type_f_1').val())).length == 0 ) {
		alert("Please select some option for footer!");
		jQuery('#cont_type_f_1').focus();
		return false;
	} else {
		var val = parseInt(jQuery('#cont_type_f_1').val());
		if(( val == 1 || val == 2 || val == 3 )) {
			if(jQuery('#no_of_art_f_1').val().length == 0) {
				alert("Please enter number of article!");
				jQuery('#no_of_art_f_1').focus();
				return false;
			} else if(isNaN(jQuery('#no_of_art_f_1').val())) {
				alert("This is not a number!");
				jQuery('#no_of_art_f_1').focus();
				return false;
			}
		} else if(( val == 4 ) &&  jQuery('#banner_f_1').val().length == 0) {
			alert("Please select some file to upload!");
			return false;
		}
	}
	
 	if( (trim(jQuery('#cont_type_f_2').val())).length == 0 ) {
		alert("Please select some option for footer!");
		jQuery('#cont_type_f_2').focus();
		return false;
	} else {
		var val = parseInt(jQuery('#cont_type_f_2').val());
		if(( val == 1 || val == 2 || val == 3 )) {
			if(jQuery('#no_of_art_f_2').val().length == 0) {
				alert("Please enter number of article!");
				jQuery('#no_of_art_f_2').focus();
				return false;
			} else if(isNaN(jQuery('#no_of_art_f_2').val())) {
				alert("This is not a number!");
				jQuery('#no_of_art_f_2').focus();
				return false;
			}
		} else if(( val == 4 ) &&  jQuery('#banner_f_2').val().length == 0) {
			alert("Please select some file to upload!");
			return false;
		}
	}
}

var arr_deleted_id = [];
function deleted_id(id)
{
	arr_deleted_id.push(id);
	document.getElementById('deleted_id').value = arr_deleted_id.join(',');
}


function win_open(url) {
	var followup_win = window.open(url,"followup_win","width=1000p,height=300p,top=190p,left=0p,menubar=no,scrollbars=yes,resizable=yes,statusbar=no");
    followup_win.focus();
}

function render_data() {
	
}
/* function panel_content(val) {
	if(val == 'A') {
		$.ajax({
			type: "GET",
			url: '/CmsPages/article_list',
			data: dataString,
			success: function(data){
				//alert(data);
				//Show results div
				//document.f1.title.value = data;
				//$('#remove1'+prop_id).show();
				$('#'+id2).hide();
				$('#'+id1).show();
				document.getElementById(id1).innerHTML = val;
				//$('#add1'+prop_id).hide();
			}
		});
	} else if(val == 'B') {
	
	}

} */

function changeLayout(id){
	//alert(id);
	window.location.href = path+"cms_pages/add/0/"+id;
}


function download(dn_url, filename) {
	//alert(dn_url);
	//alert(filename);
	var dataString = 'filename=' + filename;
 	$.ajax({
		type: "POST",
		url: dn_url,
		//data: dataString,
		success: function(data){
			if(data == 'ERROR') {
				$.colorbox({width:'680px', inline:true, href:'#inline_example1'});
			} else {
				//alert(data);
				location.href = dn_url + '?' + dataString;
			}
		}
	});
 	//$.colorbox({html:'<p>Hello</p>'});
}

/* 
function open_nutri_lbox(host, nutri_id) {
	//alert(dn_url);
 	$.ajax({
		url: host + 'conditions/nutri_lbox/' + Base64.encode(nutri_id),
		type: "POST",
		//data: dataString,
		success: function(data){
			$('#lbox').html(data);
			$.colorbox({width:'680px', inline:true, href:'#inline_example1'});
		}
	});
 	//$.colorbox({html:'<p>Hello</p>'});
}


function open_prod_lbox(host, prod_id) {
	//alert(dn_url);
 	$.ajax({
		url: host + 'conditions/prod_lbox/' + Base64.encode(prod_id),
		type: "POST",
		//data: dataString,
		success: function(data){
			$('#lbox').html(data);
			$.colorbox({width:'680px', inline:true, href:'#inline_example2'});
		}
	});
 	//$.colorbox({html:'<p>Hello</p>'});
}
 */

function facebook_share(host, url) {
	var path = 'http://' + host + url;
	//alert(path);
	window.open("http://www.facebook.com/sharer.php?u=" + path);
}

function supplement_valid() {
 	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter Supplement name.");
		jQuery('#title').focus();
		return false;
	}
}

function supplement_detail_valid() {
	var condition_id = jQuery('#condition_id').val();
	var agegroup_id = jQuery('#agegroup_id').val();
	
 	if( (trim(condition_id)).length == 0  && (trim(agegroup_id)).length == 0) {
		alert("Please enter either Condition or Agegroup.");
		return false;
	}
}

function healthy_living_login() {
	var email = jQuery('#email').val(); 
 	if( ! isValidEmailAddress(email) ) {
		alert("Please enter valid Email.");
		jQuery('#email').focus();
		return false;
	}
 	if( (jQuery('#login_password').val()).length == 0 ) {
		alert("Please enter Password.");
		jQuery('#login_password').focus();
		return false;
	}
}

function healthy_living_signup() {
 	if( (jQuery('#fname').val()).length == 0 ) {
		alert("Please enter First Name.");
		jQuery('#fname').focus();
		return false;
	}
 	if( (jQuery('#lname').val()).length == 0 ) {
		alert("Please enter Last Name.");
		jQuery('#lname').focus();
		return false;
	}
 	if( (jQuery('#agegroup_id').val()).length == 0 ) {
		alert("Please select Agegroup.");
		jQuery('#agegroup_id').focus();
		return false;
	}
	var signup_email = jQuery('#signup_email').val(); 
 	if( ! isValidEmailAddress(signup_email) ) {
		alert("Please enter valid Email.");
		jQuery('#signup_email').focus();
		return false;
	}
 	if( (jQuery('#signup_pass').val()).length <= 6 ) {
		alert("Password must be at least six character.");
		jQuery('#signup_pass').focus();
		return false;
	}
 	if( jQuery('#signup_pass').val() != jQuery('#confirm_pass').val() ) {
		alert("Passwords do not match.");
		//jQuery('#signup_pass').val() = '';
		//jQuery('#confirm_pass').val() = '';
		jQuery('#signup_pass').focus();
		return false;
	}
}

function news_valid() {
 	if( (trim(jQuery('#title').val())).length == 0 ) {
		alert("Please enter News Title.");
		jQuery('#title').focus();
		return false;
	}
}

function showOptionsSelected(listBoxId, divId) {
	var textvalues = '';
	$('#' + listBoxId + ' :selected').each(function(i,selected) {
		//$('#' + divId).html('<p>' + $(selected).text() + '</p>');
		textvalues += '<p>' + $(selected).text() + '</p>'
	});
	$('#' + divId).html(textvalues);
	//alert(textvalues);
}
