//Start of validation code
/*
function checkForMandatoryFields(inputString,InitialValue) {
	
	if ((inputString == InitialValue)) {
		
		return false;
	} else {
		return true;
	}
}
*/

function IsEmpty(inputString) {
	
	if ((inputString.length == 0) || (inputString == null) || (inputString == " ")) {
		return true;
	} else {
		return false;
	}
}

function isEmail(who) {
	function isEmpty(who) {
		var testArr=who.split("");
		var toggle=0;
		for(var i=0; i<testArr.length; i++) {
			if(testArr[i]==" ") {
				toggle=1;
				break;
			}
		}
		if(toggle)
			return true;
		return false;
	}

	function isValid(who) {
		var invalidChars=new Array("~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?");
		var testArr=who.split("");
		for(var i=0; i<testArr.length; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}

	function isfl(who) {
		var invalidChars=new Array("-","_",".");
		var testArr=who.split("");
		which=0;
		for(var i=0; i<2; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[which]==invalidChars[j]) {
					return false;
				}
			}
			which=testArr.length-1;
		}
		return true;
	}

	function isDomain(who) {
		var invalidChars=new Array("-","_",".");
		var testArr=who.split("");
		if(testArr.length<2||testArr.length>4) {
			return false;
		}
		for(var i=0; i<testArr.length; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}

	var testArr=who.split("@");
	if(testArr.length<=1||testArr.length>2) {
		return false;
	}
	else {
		if(isValid(testArr[0])&&isfl(testArr[0])&&isValid(testArr[1])) {
			if(!isEmpty(testArr[testArr.length-1])&&!isEmpty(testArr[0])) {
				var testArr2=testArr[testArr.length-1].split(".");
				if(testArr2.length>=2) {
					var toggle=1;
					for(var i=0; i<testArr2.length; i++) {
						if(isEmpty(testArr2[i])||!isfl(testArr2[i])) {
							toggle=0;
							break;
						}
					}
					if(toggle&&isDomain(testArr2[testArr2.length-1]))
						return true;
					return false;
				}
				return false;
			}
		}
	}
}

function popup(url) {
	
    width = 400;
    height = 200;
    y = (screen.availHeight - height)/2;
    x = (screen.availWidth - width)/2;
    window.open(url,'Silicus','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}

function popitup(url) {
	
    width = 350;
    height = 300;
    url= url +"?loc=" + location.href;
    y = (screen.availHeight - height)/2;
    x = (screen.availWidth - width)/2;
    window.open(url,'Silicus','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}

function formValidation() {
		
	var myform = document.getElementById('myform');
	var CaptchaCode = document.getElementById("CaptchaCode");
	
	if(IsEmpty(myform.first_name.value)) {
		alert('Please enter name');
		myform.first_name.focus();
		return false;
	}
	
	if(IsEmpty(myform.phone.value)) {
		alert('Please enter phone number');
		myform.phone.focus();
		return false;
	}
	
	if(IsEmpty(myform.email.value)) {
		alert('Please enter email address');
		myform.email.focus();
		return false;
	}
	
	if(!isEmail(myform.email.value,'E-Mail Address')) {
		
		alert('Please enter valid email address');
		myform.email.focus();
		return false;
	}
	
	if(IsEmpty(myform.CaptchaCode.value)) {
		alert('Please enter captcha code');
		myform.CaptchaCode.focus();
		return false;
	}
	
	/*
	if(CaptchaCode.value == 'Code') {
		alert('Please enter the verification code');
		return false;
	}
	*/
	
	try {
		
		var captchaImage = document.getElementById("captchaImage");
		var FullPath = captchaImage.src;
		var ToComapre = FullPath.substr(FullPath.lastIndexOf('/')+1,(FullPath.lastIndexOf('.')-1-FullPath.lastIndexOf('/')));
		
		if(ToComapre.toLowerCase() == CaptchaCode.value.toLowerCase()) {
			
			// return true;
		
		} else {
			
			GetNewCaptchaImage();
			alert('Please enter correct captcha code');
			return false;
		}
	
	} catch	(err) {
		
		alert(err);
	}
	
	myform.action = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
	myform.submit();
	
	createCookie('FIRSTNAMECR',myform.first_name.value,30)
	return true;
}
// Form common code Ends

//function Closeform
function CloseForm() {
	formValidation();
}
