// JavaScript Document



function doOpen()

{

	window.open("http://www.pixelcrayons.com", "newWin");

}





function checkPhone(phone)

{

	var phoneRequired = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/

	if(!phoneRequired.test(phone))

		return false;

	return true;

}





function checkEmail(address)

{

	if ((address == "") || (address.indexOf ('@') == -1) || (address.indexOf ('.') == -1))

		return false;

	return true;

}



function getMasterString()

{

	return "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n";

}



function checkError(error)

{

	var flag=false;

	var MasterString = getMasterString();

	

	if(error != "")

	{

		MasterString = MasterString + error;

		flag=true;

	}

	

	if(flag == true)

	{

		alert(MasterString);

		return false;

	}

	else

		return true;

}







var btnType;

function validator(btnType,formname)

{

	

	var obj = formname;

	var error="", flagCheck=0;

	

	var len = obj.elements.length; 

	var i=0;

	for(i=0;i<len;i++) 

	{

		if(obj.elements[i].type=='checkbox')

		{

			if(obj.elements[i].checked)

			{

				//if(btnType == 'Delete')

					return askConfirm(btnType);

				//else

					//return true;

			}

			else

				flagCheck = 1;

		}

	}

	

	if(flagCheck == 1)

		error += "\nPlease select at least one record.";

			

	return checkError(error);

}



//////////////////////////////////////////All validation below this function/////////////////////////////////



/*

'clientPassword', 'password','RisEqualconfpassword: confpassword'

'age','Age','RinRange10:30'

*/



function validateForm() 

{ 

	var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;

	j=0;

	//	/^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;

	var regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

	var regBlank = /[^\s]/;

	//var regAlphaNum = /^([a-zA-Z0-9-/_ :;#!@\n\r.,$*&%?^~`=+(){}\[\]\"\'\\]+)$/;

	var regAlphaNum = /^([a-zA-Z0-9_]+)$/;

	 var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/; 

  /* var regDate = /^([0-9_]{4}+-[0-9]{2}+-[0-9]{2}+)$/;*/

	

	//alert (validateForm.arguments[1].name);

	//alert("sss--->"+document.forms[""+args[0]].elements[""+args[0]].value);

	for (i=1; i<(args.length-2); i+=3) 

	{	

		mesg=args[i+1];

		test=args[i+2]; 

		val=document.forms[""+args[0]].elements[""+args[i]];

		

		    if (val) 

			{	

			nm=mesg; 

			noVal = val;

			val = val.value;

			if(test=='BLNK')

			{					

			 if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';			

			 }

			 else

				{

			//if ((val=val.value)!="") 

			if(regBlank.test(val))

			{

				if(test.indexOf('isEqual')!=-1)

				{

					result = trim(val);



				if(result.length==0){

										

				errors += '- '+nm+' is required.\n'; 

				}else{

					

					equal_obj_val = test.substring(8,test.indexOf(":"));

					mesg_string =test.substring((test.indexOf(":")+1));



					if(val != document.forms[""+args[0]].elements[""+equal_obj_val].value)

					{ 

						errors+='- '+nm+' must be same as '+mesg_string+'.\n';

					}

				}

				}

				else if(test.indexOf('isAlphaNum')!=-1)

				{

				result = trim(val);

				if(result.length==0){

				errors += '- '+nm+' is required.\n'; 

				}else{

					if(!regAlphaNum.test(val))

					{

						errors+='- '+nm+': Only Alpha Numeric and "_ , . - ! @ # () {} [] " coma,  single cots and Chars Allowed.\n';

					}

				}

				}

				else if (test.indexOf('isDate')!=-1) 

				{ 

					p=val.indexOf('-');

			       // alert(test.indexOf('isDate'));

			       	var sliptdate	= val.split("-");

					

					/*******************Added by rupesh Date is not before current date and month*********************/

					var today=new Date(),TY=today.getFullYear(),TM=today.getMonth(),TD=today.getDate(),TH=today.getHours();

					TM+=1;			

					if(TM<=9) 

					{	

						TM='0'+TM;

					}

					if(TD<=9)

					{

						TD='0'+TD;

					}

					/*******************Added by rupesh*********************/

					

					var sY=sliptdate[0];

					var sM=sliptdate[1];

					var sD=sliptdate[2];

					

					/*******************Added by rupesh*********************/

					if(sM<TM ) {

						

						errors+='- '+nm+' should be later than current date.\n';

					}

					else if(sM==TM && sD>TD) { 



						errors+='- '+nm+' should be later than current date.\n';

						

					}/*************************Added by rupesh********************/

					else if (p != 4 || sY.length != 4 || sM.length != 2 || sD.length != 2 )

					{

						errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';

		

					}

					else if(!regDate.test(val))

					{

						errors+='- '+nm+'  must contain Valid Date YYYY-MM-DD.\n';

					}

					else if(sM>12 || sD>31 || sY<2006)

					{

						errors+='- '+nm+'  must contain Valid Date YYYY-MM-DD.\n';

					}

			     }

				else if (test.indexOf('isEmail')!=-1) 

				{ 

					p=val.indexOf('@');

					s=val.indexOf('.');

			        if (p<1 || p==(val.length-1))

					{

						errors+='- '+nm+' must contain an e-mail Address.\n';

		

					}

					//else if(s<p || s==(val.length-1))

					else if(!regEmail.test(val))

					{

						errors+='- '+nm+' must contain a valid e-mail Address.\n';

					}

			     }

				else if (test.indexOf('isUrl')!=-1) 

				{ 

					p=val.indexOf('http://');

					s=val.indexOf('.');

			        if (p<0 || p==(val.length-1))

					{

						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';

		

					}

					else if(s<p || s==(val.length-1))

					{

						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';

					}

			     }

				 else if (test.indexOf('isChar')!=-1) 

				 { 

					var first_char;

					first_char= val.charAt(0);

					if(first_char==0||first_char==1||first_char==2||first_char==3||first_char==4||first_char==5||first_char==6||first_char==7||first_char==8||first_char==9)

					{

					 errors+='- '+nm+' must starts with  a char.\n';

					}

			     }

				 else if(test.indexOf('isCheckbox')!=-1)//Check is check box is not checked generate error

				{	

					var valueCheckbox = noVal.checked;

					if(!valueCheckbox)

					{

						errors+='- '+' Accept terms and Policy.\n';

					}



				}

	   			 else if (test!='R') 

				 {

				 result = trim(val);

					if(result.length==0){

					errors += '- '+nm+' is required.\n'; 

					}

				    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

					if (test.indexOf('inRange') != -1) 

					{ num = parseFloat(val);

						p=test.indexOf(':');

						min=test.substring(8,p); 

						max=test.substring(p+1);

						

						

						if (num<min || max<num) 

							if(min==max)

						{

							errors+='- '+nm+' should be '+min+'.\n';

						}

						else

						{

						errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

						}

					} 

					if (val.indexOf('-') != -1) 

					{ 

						errors='- '+nm+' must contain a number.\n';

					} 

					if (val.indexOf('+') != -1) 

					{ 

						errors='- '+nm+' must contain a number.\n';

					}

					

				}else if (test.charAt(0)=='R')

				{

				result = trim(val);

				if(result.length==0){

				errors += '- '+nm+' is required.\n'; 

				}

				} 

			}

			else if (test.charAt(0) == 'R'){

				errors += '- '+nm+' is required.\n'; 

			}

		}

			}

		if(errors !="")

		{	if(j<=0)

			{

				

				focusitem = document.forms[""+args[0]].elements[""+args[i]];

				j++;

			}	

			

		}

	} 

	

//return errors;

  

  if (errors)

  {

	var MasterString = getMasterString();



	alert(MasterString+'\n'+errors);

	

	focusitem.focus();

	return false;

   }

   else

	return true;



//  document.MM_returnValue = (errors == '');

	

}





function stripHTML(str){

      var re= /<\S[^><]*>(&nbsp;)*/g ;

      return str.replace(re, "") ;

}



function ltrim(str) { 

	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);

	return str.substring(k, str.length);

}

function rtrim(str) {

	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;

	return str.substring(0,j+1);

}



function trim(str) {

	return ltrim(rtrim(str));

}



function isWhitespace(charToCheck) {

	var whitespaceChars = " \t\n\r\f";

	return (whitespaceChars.indexOf(charToCheck) != -1);

}



//Check Team Member form

function validatefrmContactUsfrm(formname)

{

	

	if(validateForm(document.getElementById('frmContactUs').id,'frmName','Name','R', 'frmCompany','Company','R', 'frmPosition','Position','R','frmEmail','Email','RisEmail', 'frmPhone','Phone','R','frmFax','Fax','BLNK'))

	{		

	var  errors = '';

	document.frmContactUs = document.getElementById('frmContactUs');

	

		if(document.frmContactUs.frmComments.value == "")

		{

		  errors +='- Comments are Required .\n';

		}

		if(errors!='')

		{

			

			checkError(errors);

			return false;

		}

		else

		{

		  return true;

		}

	} 

	else 

	{

		return false;

	} 

}

//validate search team member form

function validateApprovedfrm(formname)

{

	if(validateForm(document.getElementById('frmApproved').id,'frmFullName','Full Name','R','frmPhone','Phone','RisNaN','frmEquipmentCost','Equipment Cost','RisNaN','frmCreditScore','Credit Score','BLNK','frmTime','Time in Business','BLNK'))

	{	

		

		  return true;

		

	} 

	else 

	{

		return false;

	} 

}



function validateQuotefrm(formname)

{

	if(validateForm(document.getElementById('frmquote').id,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmCompanyAddress','Company Address','R','frmCity','City, State and Zip Code','R','frmPhone','Telephone Number','RisNaN','frmTime','Years In Business','RisNaN','frmEquipmentCost','Estimated Equipment Cost','RisNaN','frmEquipmentDescription','Equipment Description','R'))

	{	

		return true;

	} 

	else 

	{

		return false;

	} 

	

}

function validatefrmLeasefrm(formname)

{

	if(validateForm(document.getElementById('frmLeaseApplication').id,'frmName','Name','R','frmAddress','Complete Address (incl. City/State/Zip)','R','frmPhone','Phone Number','RisNaN','frmBusinessType','Business Type','R','frmTime','Year started','BLNK','frmOwners','Number of owners','BLNK','frmOwnerName','Owner Full Legal Name','R','frmOwnerPer','Percentage of ownership','RinRange100:100','frmAssetNew','New or Used Asset','R','frmAssetYear','Asset Year','RisNan','frmAssetModel','Asset Model','R','frmEquipmentDescription','Description of Mounted Equipment','R','frmEquipmentCost','Price (excluding sales tax)','RisNaN','frmVendorName','Vendor/Seller Name','R'))

	{	

		

		  return true;

	} 

	else 

	{

		return false;

	} 

}



function validateBrokerfrm(formname)

{

	if(validateForm(document.getElementById('frmBroker').id,'frmCompanyName','Company Name','R','frmDate','Date Established','R','frmCompanyAddress','Company Address','R','frmCity','City','R','frmState','State','R','frmZip','Zip','RisNaN','frmPhone','Telephone Number','RisNaN','frmFax','Fax','BLNK','frmEmail','Email','RisEmail','frmPrincipalName','Principals Legal Name','R','frmPrincipalTitle','Principal: Title','R','frmPrincipalDOB','Principal: DOB','R','frmPrincipalSSN','Principal: SSN','R','frmPrincipalAddress','Principal: Home Address','R','frmPrincipalCity','Principal: City','R','frmPrincipalState','Principal: State','R','frmPrincipalZip','Principal: Zip','RisNan','frmAccountType','Account Type','R','frmAccount','Account Number','R','frmBankName','Bank Name','R','frmBranch','Bank Branch','R','frmBankPhone','Bank Telephone Number','RisNan','frmCompanyName1','Funding Source References: Company Name','R','frmCompanyContact1','Funding Source References: Contact','R','frmCompanyPhone1','Funding Source References: Telephone Number','RisNan','frmCompanyPhone2','Funding Source References 2 : Telephone Number','BLNK','frmCompanyPhone3','Funding Source References 3 : Telephone Number','BLNK'))

	{	

		

		  return true;

	}	

	else 

	{

		return false;

	} 

}

