
function ViewLoan(thisForm) 
{	
	thisForm.action = "Loan.asp"		
	thisForm.WhatToDo.value  = "View"
	thisForm.submit ();
}

function AssignLoan(thisForm) 
{
	thisForm.action = "LenderAssigment.asp"
	thisForm.WhatToDo.value  = "Assign"
	thisForm.submit ();
}

function LoanFunded(thisForm) 
{
	thisForm.action = "LoanFunded.asp"
	thisForm.WhatToDo.value  = "LoanFunded"
	thisForm.submit ();
}

function LoanRemove(thisForm) 
{
	thisForm.action = "LoanRemove.asp"
	thisForm.WhatToDo.value  = "LoanRemove"
	thisForm.submit ();
}


function HistoryLoan(thisForm)
{
	thisForm.action = "AssignHistory.asp"
	thisForm.WhatToDo.value  = "AssignHistory"
	thisForm.submit ();		
}
		

function LenderSummary(thisForm)
{
	thisForm.action = "LenderListSummary.asp"	
	thisForm.submit ();
}

function visit(newURL) 
{  
	if (newURL != "") 
	{
		location.href=newURL;
	}
}

function test() 
{
	form1.submit();   
}	

function IsAnyCheckBoxSelected(form)
{
	for (i=0; i<form.elements.length; i++)
	{
	   if (form.elements[i].type == "checkbox")
	   {
	 		if (form.elements[i].checked)
	         {            
	 			return true;
	         }
	    }
	}
   alert("You must select at least one lender.");
   return false;
}


function SelectAll(form,myvalue, x)
{
	var nextcheck;

	if (myvalue.value == 0)
	{
		nextcheck = 1;
		x.value = "Deselect All";
	}
	else
	{
		nextcheck = 0;
		x.value = "Select All"
	}

	for (i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].type == "checkbox")
		{
			form.elements[i].checked = nextcheck;
		}
	}
	
	myvalue.value = nextcheck;

	return true;

}   


function IsValidZip(item)
 {
	//item.value=item.value.Trim();
	if (!(/^\d{5}$/.test(item.value) || /^\d{5}-\d{4}$/.test(item.value))) {
		item.focus();
		alert("Please enter a valid zip code");
		return false;
	}
	return true;
}



function IsValidPhone(item)
 {
 
	if (!(/^\d{3}-\d{3}-\d{4}$/.test(item.value))) {
		
		alert("Please enter a valid phone number\n(e.g  888-737-9977)");
		item.focus();
	
		return false;
	}
	return true;
}

function IsValidFax(item)
 {
 
	if (!(/^\d{3}-\d{3}-\d{4}$/.test(item.value))) {
		
		alert("Please enter a valid fax number\n(e.g  888-737-9977)");
				item.focus();

		
		return false;
	}
	return true;
}


function SetPhoneNumber(thisone, max)
{	
	var x=thisone.value;
	var r, re;              //Declare variables.

	 re = /,/g;             //Create regular expression pattern.
		 

	x= x.replace(re, "");    		
	x= x.replace(/\D/g,'');	

	if ((x== "") ||(x== ''))
	{
		thisone.value = x ;
	      return true;
	}		
		
	var anum=/(^\d+$)|(^\d+\.\d+$)/
		
	if (anum.test(x))
	{
			
		var nLength =x.length;
		var newValue ="";

		for(i = 0; (i<nLength && (i < max) ) ; i++)
		{				
			if(i == 0)
			{
				newValue = newValue + "(" ;
			}
			if(i == 3)
			{
				newValue = newValue + ") " ;
			}
			if(i == 6)
			{
				newValue = newValue + "-" ;
			}
			if ((i == 10) && (i < max))
			{
				newValue = newValue + " x " ;
			}
			if(i < max)
			{
				newValue=newValue+ x.charAt(i)					
			}
		}
								
		thisone.value = newValue ;
	}
}

