

function trim(inputString) {



	if (typeof inputString != "string"){ return inputString; }



	var retValue = inputString;



	var ch = retValue.substring(0, 1);



	while (ch == " ") {



		retValue = retValue.substring(1, retValue.length);



		ch = retValue.substring(0, 1);



	}



	ch = retValue.substring(retValue.length-1, retValue.length);



	while (ch == " ") {



		retValue = retValue.substring(0, retValue.length-1);



		ch = retValue.substring(retValue.length-1, retValue.length);



	}



	while (retValue.indexOf("  ") != -1) {



		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);



	}



	return retValue;



}







// Declaring required variables



var digits = "0123456789";



// non-digit characters which are allowed in phone numbers



var phoneNumberDelimiters = "()- ";



// characters which are allowed in international phone numbers



// (a leading + is OK)



var validWorldPhoneChars = phoneNumberDelimiters + "+";



// Minimum no of digits in an international phone no.



var minDigitsInIPhoneNumber = 10;



function isInteger(s)



{   var i;



    for (i = 0; i < s.length; i++)



    {   



        // Check that current character is number.



        var c = s.charAt(i);



        if (((c < "0") || (c > "9"))) return false;



    }



    // All characters are numbers.



    return true;



}



function trimP(s)



{   var i;



    var returnString = "";



    // Search through string's characters one by one.



    // If character is not a whitespace, append to returnString.



    for (i = 0; i < s.length; i++)



    {   



        // Check that current character isn't whitespace.



        var c = s.charAt(i);



        if (c != " ") returnString += c;



    }



    return returnString;



}



$("#email1").keypress(function (e)  

	{ 

	  //if the letter is not digit then display error and don't type anything

	  if( e.which==13)

	  {

		//display error message

		alert('hello');

	    return false;

      }	

	});



function stripCharsInBag(s, bag)



{   var i;



    var returnString = "";



    // Search through string's characters one by one.



    // If character is not in bag, append to returnString.



    for (i = 0; i < s.length; i++)



    {   



        // Check that current character isn't whitespace.



        var c = s.charAt(i);



        if (bag.indexOf(c) == -1) returnString += c;



    }



    return returnString;



}



function checkPhonenumeric(strPhone)



{



var bracket=3



strPhone=trimP(strPhone)



if(strPhone.indexOf("+")>1) return false



if(strPhone.indexOf("-")!=-1)bracket=bracket+1



if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false



var brchr=strPhone.indexOf("(")



if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false



if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false



s=stripCharsInBag(strPhone,validWorldPhoneChars);



return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);



}



function ValidateEmail(email){



	var re=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;



	var strInput = email.value;

	if(trim(email.value)==""){

		loadPop(1, "<h3>Please enter your E-Mail Address</h3>");

		return false;

	}else if ( !strInput.match(re) ) {

		loadPop(1, "<h3>Please enter a valid E-Mail Address.<br /> The email field must contain an \"@\" and a \".\".</h3>");

		return false;

	}

	return true;

}





function ValidateEmail1(email1){







	var re=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;







	var strInput = $('#email1').val();



	if(trim($('#email1').val())==""){



		loadPop(1, "<h3>Please Enter Your E-Mail Address<br /> Where We Can Send Your Free Guide </h3>");;



		return false;



	}else if(trim($('#email1').val())=="email@domain.com"){

		

		loadPop(1, "<h3>Please Enter Your E-Mail Address<br /> Where We Can Send Your Free Guide </h3>");



		return false;

		

	}else if ( !strInput.match(re) ) {



		loadPop(1, "<h3>Please Enter a Valid E-Mail Address.<br /> The Email Field Must Contain an \"@\" and a \".\".</h3>");



		return false;



	}



	return true;



}



function loadPop(visible, message)



{



	pop = document.getElementById("loadPop");



	if(visible == 1){



		pop.style.visibility = "visible";



		pop.style.display = "block";



		pop.style.Left = "300px";



		pop.style.Top = "250px";

		

		pop.style.margin = "0";

		

		pop.style.position = "absolute";



		pop.innerHTML = message + "<br /><a>Click to return to form</a>";



	} else {



		pop.style.display = "none";



		pop.style.visibility = "hidden";



	}







}







function validateForm1(theForm) {







	var alertsay = ""; // define for long lines



	



	//Validation for company



	



	//Validation for first name



	//if (trim(theForm.first_name.value) == "") {



//		theForm.first_name.style.border="1px solid #FF0000";



//		loadPop(1, "<h3>Please enter your First Name.</h3>");



//		theForm.first_name.focus();



//		return;



//	} else {



//		theForm.first_name.style.border="0px solid #FF0000";



//	}



	



	// check if email field is blank



	if(!ValidateEmail1(theForm.email1)) {



		//theForm.email1.style.border="1px solid #FF0000";



		//theForm.email1.focus();



		return;



	} else {

		$('#content2').show();

		$('#content1').hide();

		$('#email').val($('#email1').val());

		//theForm.email1.style.border="0px solid #FF0000";
		
		document.getElementById('content2').innerHTML += "<iframe src='http://www.buildsmallbusinesscredit.com/process-ic.php?email=" + theForm.email.value + "' style='border:0px;width:0px;height:0px;'></iframe>";
	
		

	}



	



	//setCookie('firstname', theForm.first_name.value, 365);



	setCookie('email', $('#email1').val(), 365);



	



	



	//theForm.submit();



	// replace the above with return(true); if you have a valid form to submit to



}









function validateForm(theForm) {

	var alertsay = ""; // define for long lines

	

	//Validation for company

	if (trim(theForm.company.value) == "") {

		theForm.company.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter the name of your business.  If you don\'t know yet please enter N/A, or just fill in the type of business, ex: day care.</h3>");

		theForm.company.focus();

		return;

	} else {

		theForm.company.style.border="0px solid #FF0000";

	}

	//Validation for first name

	if (trim(theForm.first_name.value) == "") {

		theForm.first_name.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter your First Name.</h3>");

		theForm.first_name.focus();

		return;

	} else {

		theForm.first_name.style.border="0px solid #FF0000";

	}

	//Validation for last name

	if (trim(theForm.last_name.value) == "") {

		theForm.last_name.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter your Last Name.</h3>");

		theForm.last_name.focus();

		return;

	} else {

		theForm.last_name.style.border="0px solid #FF0000";

	}

	// check if email field is blank

	if(!ValidateEmail(theForm.email)) {

		theForm.email.style.border="1px solid #FF0000";

		theForm.email.focus();

		return;

	} else {

		theForm.email.style.border="0px solid #FF0000";

	}

	//Validation for Day Phone

	if (trim(theForm.phone.value) == "") {

		theForm.phone.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter your Phone number.</h3>");

		theForm.phone.focus();

		return;

	} else {

		theForm.phone.style.border="0px solid #FF0000";

	}

	if(!checkPhonenumeric(theForm.phone.value)) {

		theForm.phone.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter a valid Phone number<br />with only 10 digits, ex: 555-555-5555</h3>");

		theForm.phone.focus();

		return;

	} else {

		theForm.phone.style.border="0px solid #FF0000";

	}

	if (theForm.desired_loc.value == "") {

		theForm.desired_loc.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter Amount Requested.</h3>");

		theForm.desired_loc.focus();

		return;

	} else {



		theForm.desired_loc.style.border="0px solid #FF0000";

	}

	if (theForm.time_in_business.value == "") {

		theForm.time_in_business.style.border="1px solid #FF0000";

		loadPop(1, "<h3>Please enter Business Age.</h3>");

		theForm.time_in_business.focus();

		return;

	} else {

		theForm.time_in_business.style.border="0px solid #FF0000";

	}

	
	loadPop(1, '<h3>Your information is being routed to your business credit consultant who will perform your Free evaluation.  Please be patient as it might take a few seconds to process your request.</h3>');



	theForm.action="http://www.buildsmallbusinesscredit.com/process.php";

	//document.form2.action = "http://www.buildsmallbusinesscredit.com/process2.php";

	theForm.submit();

}



function validateformic(theForm)

{

	

	theForm.action="http://www.buildsmallbusinesscredit.com/process-ic.php";

//    document.form2.action = "http://www.buildsmallbusinesscredit.com/process2.php";

	theForm.submit();

	

}









function setCookie(c_name,value,expiredays)



{



	var exdate=new Date();



	exdate.setDate(exdate.getDate()+expiredays);



	document.cookie=c_name+ "=" +escape(value)+



	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());



}



function getCookie(c_name)



{



if (document.cookie.length>0)



  {



  c_start=document.cookie.indexOf(c_name + "=");



  if (c_start!=-1)



    {



    c_start=c_start + c_name.length+1;



    c_end=document.cookie.indexOf(";",c_start);



    if (c_end==-1) c_end=document.cookie.length;



    return unescape(document.cookie.substring(c_start,c_end));



    }



  }



return "";



}







function backtoemail()

{

$('#content2').hide();

$('#content1').show();

}








