function fullname(val) {
	val1=document.getElementById(val).value
	var u =/^[a-zA-Z.&]+$/;
	var c=u.test(val1);	
	if(c) {
	 Highlight(val,'#222222');
	return true; 
	} else {
		Highlight(val,'#BE6666');
	return false; }
}
function selectcon(obj) {
	if(document.getElementById(obj).value=='') {
		Highlight(obj,'#BE6666');
		return false;
	} else {
		Highlight(obj,'#222222');
		return true;
	} }
function IsEmail(val) {
	val1=document.getElementById(val).value
	//this is a regular expression
	var u = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var c=u.test(val1);	
	if(c) {
	 Highlight(val,'#222222');
	return true;
	} else {
		Highlight(val,'#BE6666');
	return false;
	}
}
function contact(val,minno,maxno) {
	val1=document.getElementById(val).value
	var u =/^[0-9]+$/;
	var c=u.test(val1);	
	if ((val1.length>=minno && val1.length<=maxno) && (c)) {
		Highlight(val,'#222222');
	return true;
	} else {
		Highlight(val,'#BE6666');
	return false;
	}
}
function Highlight(obj,col,objtd,img,objmsg) {
	document.getElementById(obj).style.border = col+' 1px solid';
}
function explode( delimiter, string, limit ) {  
    var emptyArray = { 0: '' };
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
function trim (str, charlist) {
   
    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}




var xmlHttp;
function checkstatus() { 
	var er=0;
	var foc ='';
	var serverurl=document.getElementById('serverurl').value
	var name=document.getElementById('name').value;
	var phone1=document.getElementById('phone1').value;
	var phone2=document.getElementById('phone2').value;
	var phone3=document.getElementById('phone3').value;
	var email=document.getElementById('email').value;
	var business=document.getElementById('business').value;
	var comments=document.getElementById('comments').value;
	var sc=document.getElementById('security_code').value;
		if (fullname('name')==false)
		{ 
			if(er==0)
			foc = 'name';
			er=1;
		}
		if (contact('phone1',3,4)==false)
		{ 
			if(er==0)
			foc = 'phone1';
			er=1;
		}
		if (contact('phone2',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone2';
			er=1;
		}
		if (contact('phone3',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone3';
			er=1;
		}
		if (IsEmail('email')==false)
		{ 
						
			if(er==0)
			foc = 'email';
			er=1;
		}
		if (selectcon('business')==false)
		{ 
			
			if(er==0)
			foc = 'business';
			er=1;
		}
		if (selectcon('comments')==false)
		{ 
			
			if(er==0)
			foc = 'comments';
			er=1;
		}
		
		if (selectcon('security_code')==false)
		{ 
			
			if(er==0)
			foc = 'security_code';
			er=1;
		}
	
	if(er==1)
		{
			
			document.getElementById(foc).focus();
			return false;
		}
		
		else
		{
	
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="ajaxphp/checkslideform.php"; 
	//url=url+"?q="+str
	url=url+"?sc="+sc+"&name="+name+"&phone1="+phone1+"&phone2="+phone2+"&phone3="+phone3+"&email="+email+"&business="+business+"&comments="+comments+"&serverurl="+serverurl; 
	xmlHttp.onreadystatechange=stateChangedaddtochainslide
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
}

function checkMainForm()
{ 
	var er=0;
	var foc ='';
	var serverurl=document.getElementById('serverurl').value
	var name=document.getElementById('name').value;
	var phone1=document.getElementById('phone1').value;
	var phone2=document.getElementById('phone2').value;
	var phone3=document.getElementById('phone3').value;
	var email=document.getElementById('email').value;
	var subject=document.getElementById('subject').value;
	var message=document.getElementById('message').value;
	var sc=document.getElementById('security_code').value;
	
		if (fullname('name')==false)
		{ 
			if(er==0)
			foc = 'name';
			er=1;
		}
		if (IsEmail('email')==false)
		{ 			
			if(er==0)
			foc = 'email';
			er=1;
		}
				
		if (contact('phone1',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone1';
			er=1;
		}
		if (contact('phone2',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone2';
			er=1;
		}
		if (contact('phone3',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone3';
			er=1;
		}
		
		if (selectcon('subject')==false)
		{ 
			
			if(er==0)
			foc = 'subject';
			er=1;
		}
		if (selectcon('message')==false)
		{ 
			
			if(er==0)
			foc = 'message';
			er=1;
		}
		
		if (selectcon('security_code')==false)
		{	
			if(er==0)
			foc = 'security_code';
			er=1;
		}
	
	if(er==1)
		{
			document.getElementById(foc).focus();
			return false;
		}		
		else
		{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="ajaxphp/checkcode.php"; 
	//url=url+"?q="+str
	url=url+"?sc="+sc+"&name="+name+"&phone1="+phone1+"&phone2="+phone2+"&phone3="+phone3+"&email="+email+"&subject="+subject+"&message="+message+"&serverurl="+serverurl;
	xmlHttp.onreadystatechange=stateChangedaddtochain
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
}

function stateChangedaddtochain() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 var result=parseInt(xmlHttp.responseText); 
// alert(xmlHttp.responseText); 
 if(result==1)
 {
	 alert('Security code is invalid');
 }
 else
 {
 window.location='http://www.webdesignoffice.us/thankyou';
 }
   } 
}
function stateChangedaddtochainslide() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 var result=parseInt(xmlHttp.responseText); 
 //alert(xmlHttp.responseText); 
 if(result==1)
 {
	 alert('Security code is invalid');
 }
 else
 {
	 window.location='http://www.webdesignoffice.us/thankyou';
 }
   } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
// this validation is for contact form
function checkcontactform() { 
var er=0;
	var foc ='';
	var serverurl=document.getElementById('serverurl').value
	var name=document.getElementById('name').value;
	var phone1=document.getElementById('phone1').value;
	var phone2=document.getElementById('phone2').value;
	var phone3=document.getElementById('phone3').value;
	var email=document.getElementById('email').value;
	var subject=document.getElementById('subject').value;
	var message=document.getElementById('message').value;
	var captcha=document.getElementById('captcha').value;
	
		if (selectcon('name')==false)
		{ 
			if(er==0)
			foc = 'name';
			er=1;
		}
		if (IsEmail('email')==false)
		{ 			
			if(er==0)
			foc = 'email';
			er=1;
		}
				
		if (contact('phone1',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone1';
			er=1;
		}
		if (contact('phone2',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone2';
			er=1;
		}
		if (contact('phone3',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone3';
			er=1;
		}
		
		if (selectcon('subject')==false)
		{ 
			
			if(er==0)
			foc = 'subject';
			er=1;
		}
		if (selectcon('message')==false)
		{ 
			
			if(er==0)
			foc = 'message';
			er=1;
		}
		if (selectcon('captcha')==false)
		{ 
			
			if(er==0)
			foc = 'captcha';
			er=1;
		}
		
	
	if(er==1)
		{
			document.getElementById(foc).focus();
			return false;
		}
		/*else
		{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="ajaxphp/contactform.php"; 
	//url=url+"?q="+str
	url=url+"?name="+name+"&phone1="+phone1+"&phone2="+phone2+"&phone3="+phone3+"&email="+email+"&subject="+subject+"&message="+message+"&serverurl="+serverurl;
	xmlHttp.onreadystatechange=stateChangedaddtocontact
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}*/
}

function stateChangedaddtocontact() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 var result=parseInt(xmlHttp.responseText); 
 //alert(xmlHttp.responseText); 
 if(result==1)
 {
	 alert('There is problem in the server.');
 }
 else
 {
	 window.location='http://www.webdesignoffice.us/thankyou';
 }
   } 
}

// this validation is for proposal form
function validate_form2(thisform) {	
	var er=0;
	var foc ='';
	with (thisform) {
		if (selectcon('company')==false) { 
			if(er==0)
			foc = 'company';
			er=1; }
		if (selectcon('firstname')==false) { 
			if(er==0)
			foc = 'firstname';
			er=1; }
		if (contact('phone1',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone1';
			er=1;
		}
		if (contact('phone2',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone2';
			er=1;
		}
		if (contact('phone3',3,4)==false)
		{ 
						
			if(er==0)
			foc = 'phone3';
			er=1;
		}
		if (selectcon('city')==false) { 
			if(er==0)
			foc = 'city';
			er=1; }
		if (IsEmail('email')==false) { 
			if(er==0)
			foc = 'email';
			er=1; }
		if (selectcon('services')==false) { 
			if(er==0)
			foc = 'services';
			er=1; }
		if (selectcon('completion_deadline')==false) { 
			if(er==0)
			foc = 'completion_deadline';
			er=1; }
		if (selectcon('project')==false) { 
			if(er==0)
			foc = 'project';
			er=1; }
		if(er==1) {
			document.getElementById(foc).focus();
			return false; }
		else {
				return true; }
	}
}

function validate_form1(thisform)
{	
	
	var er=0;
	var foc ='';
	with (thisform)
	{
		
		if (fullname('name1')==false)
		{ 
						
			if(er==0)
			foc = 'name1';
			er=1;
		}
		if (contact('age',1,3)==false)
		{ 
						
			if(er==0)
			foc = 'age';
			er=1;
		}
		if (contact('conn',6,13)==false)
		{ 
						
			if(er==0)
			foc = 'conn';
			er=1;
		}
		
		
		if (IsEmail('email1')==false)
		{ 
						
			if(er==0)
			foc = 'email1';
			er=1;
		}
		if (selectcon('add')==false)
		{ 
			
			if(er==0)
			foc = 'add';
			er=1;
		}
		if (selectcon('apfor')==false)
		{ 
			
			if(er==0)
			foc = 'apfor';
			er=1;
		}	
		if (selectcon('exp')==false)
		{ 
			
			if(er==0)
			foc = 'exp';
			er=1;
		}
		if (selectcon('captcha')==false)
		{ 
			
			if(er==0)
			foc = 'captcha';
			er=1;
		}
	
		if(er==1)
		{
			
			document.getElementById(foc).focus();
			return false;
		}
		
		else
		{
				
				return true;
		}
	}
}
