String.prototype.trim = function()  {
    // skip leading and trailing whitespace and return everything in between
    return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function chkAdminLogin() {
    var f = $('frmMain');
    var username = f['txt_username'];
    var pass = f['txt_password'];
	if ($F(username).search(/\S/) == -1) {
		alert('Please enter user name');
		$(username).focus();
		return false;
	}
	if ($F(pass).search(/\S/) == -1) {
		alert('Please enter password');
		$(pass).focus();
		return false;
	}
	return true;
}
// end of chkLogin

function Mass_Mail_Validity_Check(action) {
    var f = $('frmMain');
    var pga = f['hdnPgaction'];
    var str = "";
    var is_selected = 0;
    var len = document.frmMain.member.length;
    if(len>0) {
        for(i=0;i<len;i++) {
            if(document.frmMain.member[i].selected==true) {
                str+=document.frmMain.member[i].value+",";
                is_selected = 1;
            }
        }
    }
    else {
        if(document.frmMain.member.selected==true) {
                str+=document.frmMain.member.value+",";
                is_selected = 1;
        }
    }
    if(is_selected == 0) {
        alert("Please select atleast one subscriber");
        return false;
    }
    var subject = f['subject'];
    if($F(subject).search(/\S/)==-1) {
        alert('Please enter subject');
        $(subject).focus();
        return false;
    }
    var oEditor = FCKeditorAPI.GetInstance('mail_message') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
    if(test_content=="") {
        alert("Please enter message");
        return false;
    }
    $(pga).value = action;
    var sel_subscrider = f['sel_subscrider'];
    $(sel_subscrider).value = str;
    return true;
}
// end Mass_Mail_Validity_Check

function Admin_Change_Password_Check(action) {
    //alert("HEllo");
    var f = $('frmMain');
    var pga = f['hdnPgaction'];
    var current_pass = f['current_password'];
    var new_pass = f['new_password'];
    var con_new_pass = f['con_new_password'];
    
    if ($F(current_pass).search(/\S/) == -1) {
        alert('Please enter your current password');
        $(current_pass).focus();
        return false;
    }
    if ($F(new_pass).search(/\S/) == -1) {
        alert('Please enter your new password');
        $(new_pass).focus();
        return false;
    }
    if ($F(con_new_pass).search(/\S/) == -1) {
        alert('Please enter your confirm new password');
        $(con_new_pass).focus();
        return false;
    }
    if ($F(new_pass) != $F(con_new_pass)) {
        alert('New Password and confirm password mismatch');
        $(con_new_pass).focus();
        return false;
    }
    $(pga).value = action;
    return true;
}
// end of Admin_Change_Password_Check

function Add_Press_Check() {
	var oEditor = FCKeditorAPI.GetInstance('press_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
	
	if(document.getElementById("press_title").value=="")
	{
		alert('Please enter press title');
		document.getElementById("press_title").focus();
		return false;
	}
	else if(test_content=="") {
        alert("Please enter press content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_News_Check

function Add_Aboutus_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('aboutus_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter aboutus content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Aboutus_Check

function Add_Terms_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('terms_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter terms content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Terms_Check

function Add_Kinsurance_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('kinsurance_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter keyman insurance content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Kinsurance_Check

function Add_Process_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('process_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter process content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Process_Check

function Add_Benefits_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('benefits_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter benefits content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Benefits_Check

function Add_Glossary_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('glossary_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter glossary content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Glossary_Check

function Add_Contactus_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('contactus_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(document.getElementById("contactus_tel").value=="")
	{
		alert("Please enter Tel.");
		document.getElementById("contactus_tel").focus();
		return false
	}
	if(document.getElementById("contactus_fax").value=="")
	{
		alert("Please enter Fax.");
		document.getElementById("contactus_fax").focus();
		return false
	}
	if(test_content=="") {
        alert("Please enter contactus content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Contactus_Check

function Add_Hlifeinsurance_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('hlifeinsurance_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter history of life insurance content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Hlifeinsurance_Check

function Add_Faq_Check() {
	//alert("Hello");
    var oEditor = FCKeditorAPI.GetInstance('faq_body') ; // Get the editor instance that we want to interact with
    var test_content = oEditor.GetXHTML( true ) ;
	//alert(test_content);
    if(test_content=="") {
        alert("Please enter faq content.");
        return false;
    }
	else
	{
		return true;
	}
}
// end of Add_Faq_Check

function Add_Image(show_page,action) {
	/*alert(show_page);
	alert(action);*/
	if(action == 'insert') {
		if(document.frmMain.image_path.value.trim() == "") {
			alert('Please upload image');
			document.frmMain.image_path.focus();
			return false;
		}
	}
	var p_image = document.frmMain.image_path.value;
	if((action == 'insert') || p_image != "") {
		var image_arr = p_image.split(".");
		var prod_img = image_arr[1].toUpperCase();
		if(prod_img!="GIF" && prod_img!="JPG" && prod_img!="JPEG" && prod_img!="PNG" && prod_img!="BMP"){
			alert("Please upload a .GIF/.JPG/.JPEG/.PNG/.BMP file in image");
			document.frmMain.image_path.focus();
			return false;
		}
	}

	return true;
}

function emailCheck(entry) {
    if ( (/^[a-zA-Z0-9-._]+(@[a-zA-Z0-9-.]{1,}[a-zA-Z0-9_.-]+\.)+[a-zA-Z]{2,4}$/).exec(entry) == null) {
        return false;
    }
    return true;
}

function insurance_check(action) {
	
	document.getElementById('hdnPgaction').value = action;
	
	if(document.getElementById("state").value=="")
	{
		alert("Please select state.");
		document.getElementById("state").focus();
		return false;
	}
	else if(document.getElementById("month").value=="")
	{
		alert("Please select month.");
		document.getElementById("month").focus();
		return false;
	}
	else if(document.getElementById("day").value=="")
	{
		alert("Please select day.");
		document.getElementById("day").focus();
		return false;
	}
	else if(document.getElementById("year").value=="")
	{
		alert("Please select year.");
		document.getElementById("year").focus();
		return false;
	}
	else if(document.getElementById("gender").value=="")
	{
		alert("Please select gender.");
		document.getElementById("gender").focus();
		return false;
	}
	else if(document.getElementById("feet").value=="")
	{
		alert("Please select feet.");
		document.getElementById("feet").focus();
		return false;
	}
	else if(document.getElementById("inches").value=="")
	{
		alert("Please select inches.");
		document.getElementById("inches").focus();
		return false;
	}
	else if(document.getElementById("weight").value=="")
	{
		alert("Please select weight.");
		document.getElementById("weight").focus();
		return false;
	}
	else if(document.getElementById("tobacco").value=="")
	{
		alert("Please select tobacco use.");
		document.getElementById("tobacco").focus();
		return false;
	}
	if(document.getElementById("email").value!="" && emailCheck(document.getElementById("email").value)== false) 
	{
		alert('Please provide correct mail format.');
		document.getElementById("email").focus();
		return false;
	}

	return true;
}
// end of insurance_check

function step1_check(action) {
	
	document.getElementById('hdnPgaction').value = action;
	
	if(action=="step2")
	{
		if(document.getElementById("firstname").value=="")
		{
			alert("Please mention your first name.");
			document.getElementById("firstname").focus();
			return false;
		}
		else if(document.getElementById("lastname").value=="")
		{
			alert("Please mention your last name.");
			document.getElementById("lastname").focus();
			return false;
		}
		else if(document.getElementById("month").value=="")
		{
			alert("Please select month.");
			document.getElementById("month").focus();
			return false;
		}
		else if(document.getElementById("day").value=="")
		{
			alert("Please select day.");
			document.getElementById("day").focus();
			return false;
		}
		else if(document.getElementById("year").value=="")
		{
			alert("Please select year.");
			document.getElementById("year").focus();
			return false;
		}
		else if(document.getElementById("feet").value=="")
		{
			alert("Please select feet.");
			document.getElementById("feet").focus();
			return false;
		}
		else if(document.getElementById("inches").value=="")
		{
			alert("Please select inches.");
			document.getElementById("inches").focus();
			return false;
		}
		else if(document.getElementById("weight").value=="")
		{
			alert("Please select weight.");
			document.getElementById("weight").focus();
			return false;
		}
		else if(document.getElementById("gender").value=="")
		{
			alert("Please select gender.");
			document.getElementById("gender").focus();
			return false;
		}
		else if(document.getElementById("phone").value=="")
		{
			alert("Please mention phone.");
			document.getElementById("phone").focus();
			return false;
		}
		else if(document.getElementById("zipcode").value=="")
		{
			alert("Please mention zipcode.");
			document.getElementById("zipcode").focus();
			return false;
		}
		else if(document.getElementById("email").value=="")
		{
			alert("Please mention email.");
			document.getElementById("email").focus();
			return false;
		}
		else if(emailCheck(document.getElementById("email").value)== false) 
		{
			alert('Please provide correct mail format.');
			document.getElementById("email").focus();
			return false;
		}
		/*else if(!document.getElementById("agree").checked)
		{
			alert("Please select I Agree.");
			document.getElementById("agree").focus();
			return false;
		}*/
		return true;
	}
	else if(action=="step3")
	{
		if(document.getElementById("street_address").value=="")
		{
			alert("Please mention street address.");
			document.getElementById("street_address").focus();
			return false;
		}
		return true;
	}
	else
	{
		return true;
	}
}
// end of step1_check

function contactus_check(action) {
	
	document.getElementById('hdnPgaction').value = action;
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var message = document.getElementById('message');

	if(name.value=='') {
	alert('Indtast dit navn');
	(name).focus();
	return false;
	}		
	if(email.value=='') {
	alert('Indtast din e-mail');
	(email).focus();
	return false;
	}
	if(emailCheck(email.value)== false) {
	alert('E-mail-formatet er ikke gyldig');
	(email).focus();
	return false;
	}
	if(message.value=='') {
	alert('skriv din besked');
	(message).focus();
	return false;
	}

	return true;
}
// end of contactus_check

function Admin_Create_User(action)
{
	document.getElementById('hdnPgaction').value = action;
	
	if(action=="update")
	{
		if(document.getElementById("password").value=="")
		{
			alert("Please give a password.");
			document.getElementById("password").focus();
			return false;
		}
		else if(document.getElementById("cpassword").value=="")
		{
			alert("Please confirm the password.");
			document.getElementById("cpassword").focus();
			return false;
		}
		else if(document.getElementById("password").value!=document.getElementById("cpassword").value)
		{
			alert("Confirmed password does not match with new password.");
			document.getElementById("cpassword").focus();
			return false;
		}
		return true;
	}
	else
	{
		if(document.getElementById("username").value=="")
		{
			alert("Please give a username.");
			document.getElementById("username").focus();
			return false;
		}
		else if(document.getElementById("password").value=="")
		{
			alert("Please give a password.");
			document.getElementById("password").focus();
			return false;
		}
		return true;
	}
	return false;
}
