// JavaScript Document

 
//validate the non empty text field in the form.
function empty(frmObject) 
{  
	var str = frmObject.value.trim();
	var re = /.+/; 
	if(!str.match(re)) 
	{ 
		/*alert("Here");
		alert(lang[0]);*/ 
		frmObject.focus();
		return false; 
	}	
	return true; 
}
//Alphabatic characters and blank space are allow by this validator function.
function alpha(frmObject) 
{ 
	frmObject.value = frmObject.value.trim(); 
	var str= frmObject.value; 
	var re = /^[A-Za-z\s]*$/; 
	if (! str.match(re)) 
	{  
		/*alert(lang[1]);*/  
		frmObject.focus();
		return false; 
	} 
	return true; 
}

//Alphabetic and numeric values are allowed by alphanumeric function.
function alphaNumeric(frmObject)
{ 
	frmObject.value = frmObject.value.trim(); 
	var str= frmObject.value; 
	var re = /^[A-Za-z0-9\s]*$/; 
	if (! str.match(re)) 
	{ 
		/*alert(lang[2]);   */
		frmObject.focus();
		return false; 
	} 
	return true; 
}

//intNumber function is used for the numeric value either integer or decimal.
// if you have pass digit = 0 then it is round to zero decimal value if value > 0 then round for that decimal point.
function intNumber(frmObject,digit)
{ 
	frmObject.value = frmObject.value.trim(); 
	var str= frmObject.value; 
	if( digit == 0 ) 
	{	
		var re = /^[0-9]*$/; 
	} 
	else 
	{ 
		var re = /^[0-9\.]*$/; 
	} 
	if (! str.match(re)) 
	{ 
		/*if( digit == 0) 
		{	
			alert(lang[3]);
 		} 
		else 
		{ 
			alert(lang[4]); 
		}   */
		frmObject.focus();
		return false; 
	} 
	if (digit > 0 ) 
	{ 	
		var pos = frmObject.value.indexOf("."); 
		var len = frmObject.value.length; 
		var place = parseInt(len) - (parseInt(pos)+1); 
		if(place != digit) 
		{ 
			/*alert(digit +lang[5]);   */
			frmObject.focus();
			return false; 
		} 
	}	
	return true; 
} 
 
//validate the emailaddress.
function emailValidation(frmObject)
{ 
	//alert(frmObject.value);
	//frmObject.value = frmObject.value.trim(); 
	var str = frmObject.value.trim(); 
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; 
	if (!str.match(re)) 
	{ 
		/*alert(lang[6]);  	 */
		frmObject.focus();
		return false; 
	} 
	return true; 
} 
//Alphanumeric with special character values are allowed by this function.
function alphaNumericSpecial(frmObject)
{
	frmObject.value = frmObject.value.trim();
	var str= frmObject.value;
	var re = /^[A-Za-z0-9\!\@\#\$\%\^\&\*\(\)\_\+\-\~\?\>\<\,\.\`\s]*$/;
	if (! str.match(re)) 
	{ 
		/*alert(lang[7]);frmObject.focus();*/
		frmObject.select();
		return false;
	}
	return true;
}




//trim function truncat the leadin and trailing space of string.
String.prototype.trim = function() { a = this.replace(/^\s+/, ''); return a.replace(/\s+$/, ''); }; 

//Telehpone function allow numeric value from 0 to 9 and few character like -,+,(,) and blank space.
function telephone(frmObject) 
{ 
	frmObject.value = frmObject.value.trim(); 
	var str = frmObject.value; 
	var re = /^[0-9\-\+\(\)\s]*$/; 	
	if(! str.match(re)) 
	{ 
		/*alert(lang[8]);   */	
		frmObject.focus();
		return false;  
	}  
	return true; 
}

//checkCC function validate the 16 digit credit card number with format like XXXX XXXX XXXX XXXX
function checkCC(frmObject) 
{ 
	frmObject.value = frmObject.value.trim(); 
	var str = frmObject.value;  
	var re = /^\d{4} ?\d{4} ?\d{4} ?\d{4}$/; 
	if(!str.match(re)) 
	{  	
		/*alert(lang[9]);   */
		frmObject.focus();
		return false; 
	} 	
	return true; 
}

//checkCC4 function validate the 4 digit credit card number with format like XXXX
function checkCC4(frmObject) 
{ 
	frmObject.value = frmObject.value.trim(); 
	var str = frmObject.value;  
	var re = /^\d{4}$/; 
	if(!str.match(re)) 
	{  	
		/*alert(lang[10]);  */ 
		frmObject.focus();
		return false; 
	} 	
	return true; 
}

//This function validate the date value using MM/DD/YYYY  or MM-DD-YYYY format.
function checkDate(frmObject) 
{  
	frmObject.value = frmObject.value.trim(); 
	var str =frmObject.value;  
	var re = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;  
	if (! str.match(re))  
	{  
		/*alert(lang[11]);*/    
		frmObject.focus();
		return false;  
	}  	
	mm = parseInt(str.substring(0,1));
	dd = parseInt(str.substring(3,4)); 
	yy = parseInt(str.substring(6,9));  
	if(mm < 1 || mm > 12) 
	{  
		/*alert(lang[12]); */   	  
		frmObject.focus();
		return false;  
	}  	
	if((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12   ) && (dd < 1 && dd > 31))   
	{  
		/*alert(lang[13]);   */   	
		frmObject.focus(); 
		return false;  
	}   
	if((mm ==4 || mm == 6 || mm == 9 || mm == 11) && (dd < 1 && dd > 30 ))   
	{   
		/*alert(lang[14]);*/        
		frmObject.focus();
		return false;  
	}   
	if (mm == 2) 
	{  
		var isleap = (yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0));  
		if(isleap && (dd < 1 && dd > 29))   
		{   
			/*alert(lang[15]);*/        
			frmObject.focus();
			return false;	}  if(!isleap && (dd < 1 && dd > 28))  {   alert(lang[16]);   }   }   return true; }



function checkUrl(frmObject)
{
	frmObject.value = frmObject.value.trim(); 
	newarray = frmObject.value.split(".");
	//alert(newarray[0].trim())
	if(newarray[0].trim() != "www")
	{
		return false; 
	}
	
	var str = "http://" + frmObject.value;
	var v = new RegExp();
	v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
	if (!v.test(str)) 
	{
		alert("Please Enter valid URL format");
		//alert(lang[18]); 
		frmObject.focus(); 
		  
		return false; 
	}
	return true; 
}
function trimAll(sString) //trimall function
{
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function validateQuickQuote()
{
	
	
	var qName = document.getElementById('qName');
	var qEmail = document.getElementById('qEmail');
	var qPhone = document.getElementById('qPhone');
	var qComments = document.getElementById('qComments');
	var qCaptcha = document.getElementById('qCaptcha');
	
	if((qName.value.trim() == "Name") || !empty(qName) || !alpha(qName))
	{
		alert("Valid Name is required for Quick Quote");
		qName.focus();
		return false;
	}
	
	if((qEmail.value.trim() == "Email") || !empty(qEmail) || !emailValidation(qEmail))
	{
		alert("Valid Email is required for Quick Quote");
		qEmail.focus();
		return false;
	}
	if((qPhone.value.trim() == "Phone") || !empty(qPhone) || !telephone(qPhone))
	{
		alert("Valid Phone is required for Quick Quote");
		qPhone.focus();
		return false;
	}
	if((qComments.value.trim() == "Comments") || !empty(qComments))
	{
		alert("Comments are required for Quick Quote");
		qComments.focus();
		return false;
	}
	if(!empty(qCaptcha))
	{
		alert("Verification Code is required for Quick Quote");
		qCaptcha.focus();
		return false;
	}
	
}

function validateHireResource()
{
	
	var hName = document.getElementById('hName');
	var hOrg = document.getElementById('hOrg');
	var hCountry = document.getElementById('hCountry');
	var hEmail = document.getElementById('hEmail');
	var hPhone = document.getElementById('hPhone');
	var hWebsite = document.getElementById('hWebsite');
	var hDev = document.getElementById('hDev');
	var hResources = document.getElementById('hResources');
	var hDuration = document.getElementById('hDuration');
	var hYrs = document.getElementById('hYrs');
	var hComments = document.getElementById('hComments');
	var hCaptcha = document.getElementById('hCaptcha');
	
	if(!empty(hName) || !alpha(hName))
	{
		alert("Valid Name is required for Hire Professionals");
		hName.focus();
		return false;
	}
	
	if(!empty(hOrg))
	{
		alert("Valid Organization is required for Hire Professionals");
		hOrg.focus();
		return false;
	}
	
	if(!empty(hCountry))
	{
		alert("Valid Country is required for Hire Professionals");
		hCountry.focus();
		return false;
	}
	
	if(!empty(hEmail) || !emailValidation(hEmail))
	{
		alert("Valid Email is required for Hire Professionals");
		hEmail.focus();
		return false;
	}
	if(!empty(hPhone) || !telephone(hPhone))
	{
		alert("Valid Phone is required for Hire Professionals");
		hPhone.focus();
		return false;
	}
	
	/*if(!empty(hWebsite) || !checkUrl(hWebsite))
	{
		alert("Valid Website is required for Hire Professionals");
		hWebsite.focus();
		return false;
	}*/
	
	if(!empty(hDev))
	{
		alert("Select the developer type for Hire Professionals");
		hDev.focus();
		return false;
	}
	if(!empty(hResources))
	{
		alert("Select the resources for Hire Professionals");
		hResources.focus();
		return false;
	}
	/*if((hDuration.value.trim() == "Phone") || !empty(hDuration) || !telephone(hPhone))
	{
		alert("Valid Phone is required for Hire Professionals");
		hPhone.focus();
		return false;
	}
	if(!empty(hYrs))
	{
		alert("Duration is required for Hire Professionals");
		hYrs.focus();
		return false;
	}*/
	if(!empty(hComments))
	{
		alert("Comments are required for Hire Professionals");
		hComments.focus();
		return false;
	}
	if(!empty(hCaptcha))
	{
		alert("Verification Code is required for Hire Professionals");
		hCaptcha.focus();
		return false;
	}
	
}


function validateRequestQuote()
{
	
	var rContact = document.getElementById('rContact');
	var rCompanyname = document.getElementById('rCompanyname');
	var rCity = document.getElementById('rCity');
	var rCountry = document.getElementById('rCountry');
	var rPhone = document.getElementById('rPhone');
	var rEmail = document.getElementById('rEmail');
	var rPtype = document.getElementById('rPtype');
	var rPtech = document.getElementById('rPtech');
	var rPdesc = document.getElementById('rPdesc');
	var rCaptcha = document.getElementById('rCaptcha');
		
	if(!empty(rContact) || !alpha(rContact))
	{
		alert("Valid Contact Name is required for Quote");
		rContact.focus();
		return false;
	}
	
	/*if(!empty(rCompanyname) || !alpha(rCompanyname))
	{
		alert("Valid Company Name is required for Quote");
		rCompanyname.focus();
		return false;
	}*/
	
	if(!empty(rCity) || !alpha(rCity))
	{
		alert("Valid City is required for Quote");
		rCity.focus();
		return false;
	}
	
	if(!empty(rCountry))
	{
		alert("Valid Country is required for Quote");
		rCountry.focus();
		return false;
	}
	
	
	if(!empty(rPhone) || !telephone(rPhone))
	{
		alert("Valid Phone is required for Quote");
		rPhone.focus();
		return false;
	}
	
	if(!empty(rEmail) || !emailValidation(rEmail))
	{
		alert("Valid Email is required for Quote");
		rEmail.focus();
		return false;
	}
	
	
	if(!empty(rPtype))
	{
		alert("Select the Project Type for Quote");
		rPtype.focus();
		return false;
	}
	if(!empty(rPtech))
	{
		alert("Select Preferred Technology for Quote");
		rPtech.focus();
		return false;
	}
	/*if((hDuration.value.trim() == "Phone") || !empty(hDuration) || !telephone(hPhone))
	{
		alert("Valid Phone is required for Hire Professionals");
		hPhone.focus();
		return false;
	}
	if(!empty(hYrs))
	{
		alert("Duration is required for Hire Professionals");
		hYrs.focus();
		return false;
	}*/
	if(!empty(rPdesc))
	{
		alert("Project description is required for Quote");
		rPdesc.focus();
		return false;
	}
	if(!empty(hCaptcha))
	{
		alert("Verification Code is required for Quote");
		hCaptcha.focus();
		return false;
	}
	
}

function validateBeOurPartner()
{
	var pFname = document.getElementById('pFname');
	var pLname = document.getElementById('pLname');
	var pCountry = document.getElementById('pCountry');
	var pPhone = document.getElementById('pPhone');
	var pEmail = document.getElementById('pEmail');
	var pComment = document.getElementById('pComment');
	var pCaptcha = document.getElementById('pCaptcha');
		
	if(!empty(pFname) || !alpha(pFname))
	{
		alert("Valid First Name is required for Be Our Partner");
		pFname.focus();
		return false;
	}
	
	if(!empty(pLname) || !alpha(pLname))
	{
		alert("Valid Last Name is required for Be Our Partner");
		pLname.focus();
		return false;
	}
	
	if(!empty(pEmail) || !emailValidation(pEmail))
	{
		alert("Valid Email is required for Be Our Partner");
		pEmail.focus();
		return false;
	}
	if(!empty(pPhone) || !telephone(pPhone))
	{
		alert("Valid Phone is required for Be Our Partner");
		pPhone.focus();
		return false;
	}
	if(!empty(pCountry))
	{
		alert("Valid Country is required for Be Our Partner");
		pCountry.focus();
		return false;
	}
	if(!empty(pComment))
	{
		alert("Project description is required for Be Our Partner");
		pComment.focus();
		return false;
	}
	if(!empty(pCaptcha))
	{
		alert("Verification Code is required for Be Our Partner");
		pCaptcha.focus();
		return false;
	}
}

function validCommonForm()
{
	var cName = document.getElementById('cName');
	var cEmail = document.getElementById('cEmail');
	var cPhone = document.getElementById('cPhone');
	var cCountry = document.getElementById('cCountry');
	var cComments = document.getElementById('cComments');
	var cCaptcha = document.getElementById('cCaptcha');

	if(!empty(cName) || !alpha(cName))
	{
		alert("Valid Name is required");
		cName.focus();
		return false;
	}
	
	if(!empty(cEmail) || !emailValidation(cEmail))
	{
		alert("Valid Email is required");
		cEmail.focus();
		return false;
	}
	
	if(!empty(cPhone) || !telephone(cPhone))
	{
		alert("Valid Phone is required");
		cPhone.focus();
		return false;
	}
	if(!empty(cCountry))
	{
		alert("Please select Country");
		cCountry.focus();
		return false;
	}
	if(!empty(cComments))
	{
		alert("Valid Comments are required");
		cComments.focus();
		return false;
	}
	if(!empty(cCaptcha))
	{
		alert("Verification Code is required");
		cCaptcha.focus();
		return false;
	}
}