
//---------------
function getStyleObject(objectId){
if (document.getElementById && document.getElementById(objectId)){
return document.getElementById (objectId).style;
} else if (document.all && document.all(objectId)){
return document.all(objectId).style;
} else {
return false;
}
}
//---------------
function changeDiv(the_div,the_change){
var the_style = getStyleObject(the_div);
if (the_style != false){
the_style.display = the_change;
}
}
//---------------

function hideAll(){
 changeDiv('page1','none');
 changeDiv('page2','none');
}
//---------------


function showPage1(){
 changeDiv('page1','block');
 changeDiv('page2','none');
}
//---------------

function showPage2(){
 changeDiv('page1','none');
 changeDiv('page2','block');
}
//---------------


//----------------------------------------------------------------------------------------
function showError(){
	changeDiv('error','block');
}
//----------------------------------------------------------------------------------------
function hideError(){
	changeDiv('error','none');
}
//----------------------------------------------------------------------------------------





//----------------------------------------------------------------------------------------
//--- FOR NUMBER VALIDATION (PHONE & OTHER) --------------------

function threeDigit(elm){
	var numDigits = elm.value;
	if(numDigits.length==0 || (numDigits.length==3 && numDigits.match(/^\d{3}$/))){
		return true;
	} else {
	    alert(elm.value + " is an incorrect value! You must enter three numbers!");
	    elm.value="";
	    return false;
	}
} // end threeDigits() .........

function fourDigit(elm){
	var numDigits = elm.value;
	if(numDigits.length==0 || (numDigits.length==4 && numDigits.match(/^\d{4}$/))){
		return true;
	} else {
	    alert(elm.value + " is an incorrect value! You must enter four numbers");
	    elm.value="";
	    return false;
	}
} // end fourDigits() .........


function minFiveDigit(elm){
	var numDigits = elm.value;
	//if(numDigits.length >= 5 && numDigits.match(/^\d{5}$/)){
	if(numDigits.length >= 5 && numDigits.match(/^\d{5,}$/)){
		return true;
	} else {
	    alert("You must enter at least 5 numbers");
	    elm.value="";
	    return false;
	}
} // end fourDigits() .........


function allDigit(elm){
	var numDigits = elm.value;
	if(numDigits.match(/^\d{1,}$/)){
		return true;
	} else {
	    alert("You can only enter numbers.");
	    elm.value="";
	    return false;
	}
} // end fourDigits() .........

//----------------------------------------------------------------------------------------
// check format of an email address
function validateEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (lstr > 1) {
		if (str.indexOf(at)==-1){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(at,(lat+1))!=-1){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(dot,(lat+2))==-1){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(" ")!=-1){
			alert("Your email address appears to be invalid.")
			return false
		}
		if (str.indexOf(",")!=-1){
			alert("Your email address appears to be invalid.")
			return false
		}
	}
	return true
} // end emailcheck() ..............

//----------------------------------------------------------------------------------------
function openCalculator(string){
	var url = "http://securepaydayloanapplication.com/scripts/LoanCalculator/loan_calculator.php?"+string;
	window.open(url,'LoanCalculator','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=400,height=350');
}

//----------------------------------------------------------------------------------------

