// JavaScript Document
// JavaScript Document
//----------phone number validation-------------
	
// 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 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 checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}

//----------end phone number validation-------------
//contact form validation
function vlidContactForm()
{
	var obj=document.contactForm;

	if(obj.name.value=="")					//if tile field is balank
	{
		alert("Please enter name!");
		obj.name.focus();
		return false;
	}
	if(obj.company.value=="")				//check weather company name is blank
	{
		alert("Please enter company name!");
		obj.company.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.email.value)))
	{
		alert("Invalid E-mail Address! Please re-enter!")
		obj.email.focus();
		obj.email.select();
		return false;
	}
	if ((obj.phone.value==null)||(obj.phone.value=="")){
		alert("Please Enter your Phone Number!")
		obj.phone.focus();
		return false;
	}
	if (checkInternationalPhone(obj.phone.value)==false){
		alert("Please Enter a Valid Phone Number!")
		obj.phone.value="";
		obj.phone.focus();
		return false;
	}
	if(obj.city.value=="")
	{
		alert("Please enter your city!");	
		obj.city.focus();
		return false;
	}
	if(obj.state_province.value=="")
	{
		alert("Please enter your state province!");
		obj.state_province.focus();
		return false;
	}
	if(obj.country.value=="")
	{
		alert("Please enter your country!");
		obj.country.focus();
		return false;
	}
	if(obj.message.value=="")
	{
		alert("Please enter your message!");
		obj.message.focus();
		return false;
	}
	else
	{
		var name=obj.name.value;
		var company=obj.company.value;
		var email=obj.email.value;
		var phone=obj.phone.value;
		var city=obj.city.value;
		var state_province=obj.state_province.value;
		var country=obj.country.value;
		var message=obj.message.value;
		if(obj.contact_method[1].checked)
		{
			contact_method=obj.contact_method[1].value;	
		}
		else
		{
			contact_method='phone';
		}

		var url="./ajaxcontactForm.php?action=sendmail&name="+name+"&company="+company+"&email="+email+"&phone="+phone+"&city="+city+"&state_province="+state_province+"&country="+country+"&contact_method="+contact_method+"&message="+message;
		ajaxFunction(url);	
	}

	
}
//end contact form validation
//pateners form validation
function validPatners()
{
	var obj=document.patnerform;
	var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/ //url validation
	if(obj.name.value=="")					//if tile field is balank
	{
		alert("Please enter name!");
		obj.name.focus();
		return false;
	}
	if(obj.company.value=="")				//check weather company name is blank
	{
		alert("Please enter company name!");
		obj.company.focus();
		return false;
	}
	if ( (obj.url.value!='') && (!tomatch.test(obj.url.value)) )   //client url validation
    {
         alert("Invalid url entered!");
		 obj.url.focus();
		 return false;
    }
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.office_email.value)))
	{
		alert("Invalid Office E-mail Address! Please re-enter!")
		obj.office_email.focus();
		obj.office_email.select();
		return false;
	}
	if ((obj.office_phone.value==null)||(obj.office_phone.value=="")){
		alert("Please Enter your Phone Number!")
		obj.office_phone.focus();
		return false;
	}
	if (checkInternationalPhone(obj.office_phone.value)==false){
		alert("Please Enter a Valid Phone Number!")
		obj.office_phone.value="";
		obj.office_phone.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.email.value)))
	{
		alert("Invalid E-mail Address! Please re-enter!")
		obj.email.focus();
		obj.email.select();
		return false;
	}
	if ((obj.mobile.value==null)||(obj.mobile.value=="")){
		alert("Please Enter your Phone Number!")
		obj.mobile.focus();
		return false;
	}
	if (checkInternationalPhone(obj.mobile.value)==false){
		alert("Please Enter a Valid Phone Number!")
		obj.mobile.value="";
		obj.mobile.focus();
		return false;
	}
	if(obj.howyou_know.value=="")
	{
		alert("How you know about us!");
		obj.howyou_know.focus();
		return false;
	}
	else
	{
		var name=obj.name.value;
		var company=obj.company.value;
		var url=obj.url.value;
		var office_email=obj.office_email.value;
		var office_phone=obj.office_phone.value;
		var email=obj.office_phone.value;
		var mobile=obj.mobile.value;
		var help=obj.help.value;
		var howyou_know=obj.howyou_know.value;
		var url="./partnerAjax.php?action=partner&name="+name+"&company="+company+"&url="+url+"&office_email="+office_email+"&office_phone="+office_phone+"&email="+email+"&mobile="+mobile+"&help="+help+"&howyou_know="+howyou_know;
		patnerajaxFunction(url);
		
	}
	
}
function validQuote()
{
	var obj=document.quoteForm;
	var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/ //url validation
	if(obj.name.value=="")
	{
		alert("Please enter your name!");
		obj.name.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.email.value)))
	{
		alert("Invalid E-mail Address! Please re-enter!")
		obj.email.focus();
		obj.email.select();
		return false;
	}
	if ((obj.phone.value==null)||(obj.phone.value=="")){
		alert("Please Enter your Phone Number!")
		obj.phone.focus();
		return false;
	}
	if (checkInternationalPhone(obj.phone.value)==false){
		alert("Please Enter a Valid Phone Number!")
		obj.phone.value="";
		obj.phone.focus();
		return false;
	}
	if(obj.city.value=="")
	{
		alert("Please enter your city!");
		obj.city.focus();
		return false;
	}	
	if(obj.state_province.value=="")
	{
		alert("Please enter your state province!");
		obj.state_province.focus();
		return false;
	}	
	if(obj.country.value=="")
	{
		alert("Please enter your country!");
		obj.country.focus();
		return false;
	}	
	if(obj.project_type.value=="")
	{
		alert("Please enter your project type!");
		obj.project_type.focus();
		return false;
	}	
	if(obj.audience.value=="")
	{
		alert("Please enter your target audience!");
		obj.audience.focus();
		return false;
	}	
	if(obj.budget.value=="")
	{
		alert("Please enter your budget range!");
		obj.budget.focus();
		return false;
	}	
	if(obj.time.value=="")
	{
		alert("Please enter time frame for the project!");
		obj.time.focus();
		return false;
	}
	if ( (obj.website.value!='') && (!tomatch.test(obj.website.value)) )   //client url validation
    {
         alert("Invalid url entered!");
		 obj.website.focus();
		 return false;
    }
	if(obj.brief.value=="")
	{
		alert("Please enter brief descripton about your project!");
		obj.brief.focus();
		return false;
	}
	else
	{
		var chks = document.getElementsByName('services[]');
		var hasChecked = false;
		var service='';
		for (var i = 0; i < chks.length; i++)
		{
			if (chks[i].checked)
			{
				
				service+=chks[i].value+",";
				
			}
			
		}
		/*if (!hasChecked)
		{
			alert("Please select one service type!");
			chks[0].focus();
			return false;
		}*/
		
		var name=obj.name.value;
		var company=obj.company.value;
		var email=obj.email.value;
		var phone=obj.phone.value;
		var city=obj.city.value;
		var state_province=obj.state_province.value;
		var country=obj.country.value;
		var contact_method=obj.contact_method.value;
		var project_type=obj.project_type.value;
		var audience=obj.audience.value;
		var budget=obj.budget.value;
		var time=obj.time.value;
		var website=obj.website.value;
		var brief=obj.brief.value;
		var similar_sites=obj.similar_sites.value;
		if(obj.send_copy.checked==true)
		{
			var send_copy='yes';
		}
		else
		{
			var send_copy='no';
		}
		var url="./quotesAjax.php?name="+name+"&company="+company+"&email="+email+"&phone="+phone+"&city="+city+"&state_province="+state_province+"&country="+country+"&contact_method="+contact_method+"&project_type="+project_type+"&audience="+audience+"&budget="+budget+"&time="+time+"&website="+website+"&brief="+brief+"&similar_sites="+similar_sites+"&send_copy="+send_copy+"&services="+service+"&action=add";
		quotesFunction(url);
			

	}
	
	
}
//javascript add special charcter in array
function implode(sep, arr) {
	return arr.join(sep);
}
	//end implode
//end 