
// Java cript Validations for Subscription page.

function CheckForm()
{	
	var myRegxp = /[a-zA-Z]/;
	if(form.FirstName.value == "")
		{
			alert( "Please enter your 'First Name'." );
			form.FirstName.focus();
			return false ;
		}
	else if(!myRegxp.test(form.FirstName.value))
		{
			alert( "For FirstName only alphabets allowed." );
			form.FirstName.focus();
			return false ;
		}
	
	if(form.LastName.value == "")
	{
		alert( "Please enter your 'Last Name'." );
		form.LastName.focus();
		return false ;
	}
	else if(!myRegxp.test(form.LastName.value))
		{
			alert( "For Last Name only alphabets allowed." );
			form.LastName.focus();
			return false ;
		}
		
	if (form.Email.value == "")
		{
			alert( "Please enter your 'E-mail' address." );
			form.Email.focus();
			return false ;
		}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.Email.value))
		{
			//return (true)
		}
	else
		{
			alert("Please enter a valid 'E-mail' address.")
			form.Email.select();
			return false ;
		}
		
    if(form.State.value == "none")
		{
			alert( "Please select your 'State'." );
			form.State.focus();
			return false ;
		}
	
	if(form.substype.value == "none")
		{
			alert( "Please select your 'Subscription Type'." );
			form.substype.focus();
			return false ;
		}
}


// Validation for Contact Us

function CheckContactForm()
{	
	var myRegxp = /[a-zA-Z]/;
	if(form.FirstName.value == "")
		{
			alert( "Please enter your 'First Name'." );
			form.FirstName.focus();
			return false ;
		}
	else if(!myRegxp.test(form.FirstName.value))
		{
			alert( "For FirstName only alphabets allowed." );
			form.FirstName.focus();
			return false ;
		}
	if(form.LastName.value == "")
		{
			alert( "Please enter your 'Last Name'." );
			form.LastName.focus();
			return false ;
		}
	else if(!myRegxp.test(form.LastName.value))
		{
			alert( "For LastName only alphabets allowed." );
			form.LastName.focus();
			return false ;
		}
	if (form.Email.value == "")
		{
			alert( "Please enter your 'E-mail' address." );
			form.Email.focus();
			return false ;
		}
	else
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.Email.value))
				{
					//return (true)
				}
			else
				{
					alert("Please enter a valid 'E-mail' address.")
					form.Email.select();
					return false ;
				}
		}
    if(form.State.value == "none")
		{
			alert( "Please select your 'State'." );
			form.State.focus();
			return false ;
		}
	
	if(form.substype.value == "none")
		{
			alert( "Please select your 'Subscription Type'." );
			form.substype.focus();
			return false ;
		}
}

// Validation for small Sbscription form

function checkSubscribe()
{
	if (frm.Email.value == "Enter Your Email" || frm.Email.value == "")
		{
			alert( "Please enter your 'E-mail' address." );
			frm.Email.focus();
			return false ;
		}
		else
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.Email.value))
				{
					//return (true)
				}
			else
				{
					alert("Please enter a valid 'E-mail' address.")
					frm.Email.select();
					return false ;
				}
		}
}

function SetImage(obj,mode)
{	
	if(mode==1)
	{	
		document.getElementById(obj.id).style.backgroundImage="url(images/mouseover_btn.gif)";					
	}
	else
	{
		document.getElementById(obj.id).style.backgroundImage="url(images/mouseout_btn.gif)";					
	}
}	
	
function RemoveLabel(obj,action)
{
	var FldArray = new Array();
	FldArray['email']="Your Email";		
				
	if(document.getElementById(obj.id).value == FldArray[obj.id])
	{
		document.getElementById(obj.id).value=''
	}
	else if(document.getElementById(obj.id).value=="")
	{
		document.getElementById(obj.id).value=FldArray[obj.id]
	}
	else
	{
		return 
	}
}

function AddToMailerList()
{
	location.href="subscription.php"
}
/* Amount Formatting Function */
/**********************************
/******* Parameters ***************
	num 	: amount(Value)
************************************/	
function FormatCurrency(num) 
{	
	if(num!='' )
	{
		if(isNaN(num))
		{
			return	"0.00";
		}
		var data = num.toString();
		var arr = data.split(".");

		if(arr.length ==1)
		{
			num = arr[0]+"."+"00";
		}
		
		if(arr.length ==2)
		{
			if(arr[1].length == 1)
			{			
				num = arr[0] + "." + arr[1]+"0";			
			}
			else
			{
				num = arr[0] + "." + arr[1];
			}	
		}
		return num;
	}
	else
		return '';
}
/*************************************/
function MyCheckEnteredValue(val) 
{	
	valid = true;
	allowed = "0123456789()-,.$";
	digits = "0123456789";
	numCount=0;
	for(i=0;i<val.length;i++)
	{
		if(allowed.indexOf(val.charAt(i))<0)
			valid=false;
		if(digits.indexOf(val.charAt(i))>-1)
			numCount++;	
	}
	/*
	if(valid && numCount==0)
	{
		alert("Only numeric values are allowed!");
		return false;
	}
	*/
	return true;
}
/***This Function is used in fourth step of FIVE STEP application form ************/
function dosum()
{
	var frm = document.myForm;
	var tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7
	
	tmp1 =  parseFloat(frm.expensesByrent.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp1)) tmp1=0;
	tmp2 = parseFloat(frm.expensesMPayement.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp2)) tmp2=0;
	tmp3 = parseFloat(frm.expensesPayement.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp3)) tmp3=0;
	tmp4 = parseFloat(frm.expensesHomeIns.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp4)) tmp4=0;
	tmp5 = parseFloat(frm.expensesrealTax.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp5)) tmp5=0;
	tmp6 = parseFloat(frm.expensesMortIns.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp6)) tmp6=0;
	tmp7 = parseFloat(frm.expensesHownerAss.value.toString().replace(/\$|\,/g,''));
	if (isNaN(tmp7)) tmp7=0;
	
	frm.expensesTotal.value=FormatCurrency(tmp1+tmp2+tmp3+tmp4+tmp5+tmp6+tmp7);
}
/* Auto Tab Function */
/**********************************
/******* Parameters ***************
	field 	: this
	len		: Max( Required ) Length
	next	: Next tab field name
************************************/
function AutoTabs(field,len,next) 
{	
	if(field.value.length == len)
	{
		document.myForm[next].focus()
	}		
}
function CopyMailAddress(mode)
{
	switch(mode)
	{
		case "postal":
			if(document.myForm.sameaddress.checked)
			{
				document.myForm.ns_borrowerPostAddres.value=document.myForm.rs_borrowerStreet.value
				document.myForm.ns_borrowerPostCity.value=document.myForm.ns_borrowerCity.value   
				document.myForm.ns_borrowerPostState.value=document.myForm.ns_borrowerState.value  
				document.myForm.ns_borrowerPostZip1.value=document.myForm.ns_borrowerZip1.value   
				document.myForm.ns_borrowerPostZip2.value=document.myForm.ns_borrowerZip2.value   
			}
			else
			{
				document.myForm.ns_borrowerPostAddres.value=''
				document.myForm.ns_borrowerPostCity.value=''
				document.myForm.ns_borrowerPostState.value=''
				document.myForm.ns_borrowerPostZip1.value=''
				document.myForm.ns_borrowerPostZip2.value=''
			}
		break;
		case "coborrower":
			if(document.myForm.sameasapplicant.checked)
			{
				document.myForm.ns_coborrowerStreet.value=document.myForm.rs_borrowerStreet.value
				document.myForm.ns_coborrowerCity.value=document.myForm.ns_borrowerCity.value   
				document.myForm.ns_coborrowerState.value=document.myForm.ns_borrowerState.value  
				document.myForm.ns_coborrowerZip1.value=document.myForm.ns_borrowerZip1.value   
				document.myForm.ns_coborrowerZip2.value=document.myForm.ns_borrowerZip2.value   
			}
			else
			{
				document.myForm.ns_coborrowerStreet.value=''
				document.myForm.ns_coborrowerCity.value=''
				document.myForm.ns_coborrowerState.value=''
				document.myForm.ns_coborrowerZip1.value=''
				document.myForm.ns_coborrowerZip2.value=''
			}
		break;
	}
}

function CallAjaxPDF(file,params)
{
	var url=file+'?'+params
	var myWindow = window.open(url, "myWindow", 'toolbar,width=850,height=500') 
}
function clearFrm()
  		{
  			document.getElementById("err").innerHTML="&nbsp;";
  			document.form.FirstName.focus();
  			document.form.FirstName.value="";
  			document.form.LastName.value="";
  			document.form.Email.value="";
  			document.form.Addr1.value="";
  			document.form.Addr2.value="";
  			document.form.City.value="";
  			document.form.State.value=null;
  			document.form.Zip.value="";
  			document.form.HomePhone.value="";
  			document.form.WorkPhone.value="";
  			document.form.CellPhone.value="";
  			document.form.substype.value=null;
  			return false;
  		}
function user_login()
{
			document.getElementById("err").innerHTML="&nbsp;";
  			document.myForm.username.focus();
  			document.myForm.username.value="";
  			document.myForm.password.value="";
  			return false;

}