//<!---- 					Developer 	: Lakshmi 					----->
//<!---- 					Verified  	: Bala    					----->
//<!---- 					Version   	: 1.0.0  					----->
//<!---- 					Company   	: VeeTechnologies Pvt. Ltd., Bangalore		----->
//<!---- 					Description     : Validates the Form fields values		----->
// Check Text or Not
function isText(str)
{
	var i=0;
	if(str.charAt(0)==' ')i++;
	while(i<str.length)
	{
		if (str.charAt(i)>='0' && str.charAt(i)<= '9' || str.charAt(i)=='+' || str.charAt(i)=='-' || str.charAt(i)=='*' || str.charAt(i)=='/' || str.charAt(i)=='\\' || str.charAt(i)=='\'' || str.charAt(i)=='@' || str.charAt(i)=='!' || str.charAt(i)=='~' || str.charAt(i)=='`' || str.charAt(i)=='#' || str.charAt(i)=='$' || str.charAt(i)=='%' || str.charAt(i)=='^' || str.charAt(i)=='&' || str.charAt(i)=='(' || str.charAt(i)==')' || str.charAt(i)=='_' || str.charAt(i)=='=' || str.charAt(i)=='?' || str.charAt(i)=='.' || str.charAt(i)==',' || str.charAt(i)==';' || str.charAt(i)==':' || str.charAt(i)=='"' || str.charAt(i)=='{' || str.charAt(i)=='}' || str.charAt(i)=='[' || str.charAt(i)==']' || str.charAt(i)=='<' || str.charAt(i)=='>' || str.charAt(i)=='|')
		return false;
		i++;
	}
	return true;
}

// Check Phone Number or not
function isTelephoneNumber(str)
{
	var i=0;
	if(str.charAt(0)=='+')i++;
	while(i<str.length)
	{
		if (!(str.charAt(i)>='0' && str.charAt(i)<= '9' || str.charAt(i)==' ' || str.charAt(i)=='-' || str.charAt(i)=='(' || str.charAt(i)==')') )
			return false;
		i++;
	}
	return true;
}

// Check Phone Number length
function isLength(str)
{
	var len=str.length;
		if(len<10)
		{
			return false;
		}
		return true;
}

// Check Number or Not
function isNumeric(str)
{
	var i=0;
	while(i<str.length)
	{
		if (!(str.charAt(i)>='0' && str.charAt(i)<= '9' || str.charAt(i)==' '))
		return false;
		i++;
	}
	return true;
}

// Remove the empty space
function trim(String)
{
   if (String == null)
   {   
   	return ("");
   }
   return String.replace(/(^\s+)|(\s+$)/g,"");
}

// Check the E-Mail Id
function isMailid(str) 
{
	var emailPat = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/;
	var matchArray = str.match(emailPat);
		if (matchArray == null)
		{
		alert("Invalid E-Mail Address");
		return false;
		}
}

function formContactus()
{
	document.contact.Name.value=trim(document.contact.Name.value);
	Name=document.contact.Name.value;
	if (document.contact.Name.value=="")
	{
		alert("Enter Your Name");		
		document.contact.Name.focus();		
		return false;
	}
	else
		if(!isText(Name))
		{
			alert("Check Your Name");
			document.contact.Name.focus();
			return false;
		}
		
	document.contact.email.value=trim(document.contact.email.value);
	email=trim(document.contact.email.value);
	if ((email==null)||(email==""))
	{
		alert("Enter E-Mail Address")
		document.contact.email.focus()
		return false
	}
	if (isMailid(email)==false)
	{
		document.contact.email.focus()
		return false
	}

	//document.down.submit();
	return true;
}

function formDownload()
{
	document.down.name.value=trim(document.down.name.value);
	name=document.down.name.value;
	if (document.down.name.value=="")
	{
		alert("Please Enter Your Name");		
		document.down.name.focus();		
		return false;
	}
	else if(!isText(name))
		{
			alert("Please Check Your Name (Must be in Text)");
			document.down.name.focus();
			return false;
		}
		
	document.down.email.value=trim(document.down.email.value);
	email=trim(document.down.email.value);
	if ((email==null)||(email==""))
	{
		alert("Please Enter Your E-Mail Address")
		document.down.email.focus()
		return false
	}
	if (isMailid(email)==false)
	{
		document.down.email.focus()
		return false
	}

	//document.down.submit();
	return true;
}

// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function doDateCheck(to) {
cd = new Date();
//alert(Date.parse(cd));
//alert(Date.parse(document.contact.startproject.value));
if (Date.parse(cd) < Date.parse(document.contact.startproject.value)) {
//alert("The dates are valid.");
return true;
}
else 
if (document.contact.startproject.value == "") {
alert("Both dates must be entered.");
return false; 
} else {
//alert("To date must occur after the from date.");
return false;
 }

   return true;
}


function formContact()
{
	document.contact.Name.value=trim(document.contact.Name.value);
	Name=document.contact.Name.value;
	if (document.contact.Name.value=="")
	{
		alert("Enter Your Name");		
		document.contact.Name.focus();		
		return false;
	}
	else
		if(!isText(Name))
		{
			alert("Check Your Name");
			document.contact.Name.focus();
			return false;
		}
		
	document.contact.email.value=trim(document.contact.email.value);
	email=trim(document.contact.email.value);
	if ((email==null)||(email==""))
	{
		alert("Enter E-Mail Address")
		document.contact.email.focus()
		return false
	}
	if (isMailid(email)==false)
	{
		document.contact.email.focus()
		return false
	}
	
	phone=trim(document.contact.phone.value);
	if ((phone==null)||(phone==""))
	{
		//document.contact.ph.value="?";
		alert("Enter Contact Phone No")
		document.contact.phone.focus()
		return false
	}
	if(!isTelephoneNumber(document.contact.phone.value))
		{
			alert("Check Contact Phone No");
			document.contact.phone.focus();
			return false;
		}

	document.contact.country.value=trim(document.contact.country.value);
	Name=document.contact.country.value;
	if (document.contact.country.value=="")
	{
		alert("Enter Your country");		
		document.contact.country.focus();		
		return false;
	}
	/*else
		if(!isText(Name))
		{
			alert("Check Your country");
			document.contact.country.focus();
			return false;
		}*/
		
	//document.contact.startproject.value=trim(document.contact.startproject.value);
	startproject=document.contact.startproject.value;
	if (document.contact.startproject.value=="")
	{
		alert("Enter When would you like to start this project?");		
		document.contact.startproject.focus();		
		return false;
	}
	
	//compare date
	
	if (doDateCheck(document.contact.startproject.value)==false){
		alert("Date must be later then current date.");
		document.contact.startproject.focus();
		return false;
	}
		
	if (document.contact.pgather.checked == false && document.contact.poutsource.checked == false && document.contact.pready.checked == false && document.contact.pothers.checked == false )
	{
		alert("Please Select at what stage are you in the outsourcing process ");		
			return false;
	}
	
	document.contact.description.value=trim(document.contact.description.value);
	description=document.contact.description.value;
	if (document.contact.description.value=="")
	{
		alert("Enter Your description");		
		document.contact.description.focus();		
		return false;
	}
	else
		if(!isText(description))
		{
			alert("Check Your description");
			document.contact.description.focus();
			return false;
		}

	//document.contact.submit();
	return true;
}