function Searchit(args)
{
	var term = document.getElementById(args).value;
	var url = "http://" + window.location.host + "/search.html?"+term;
	window.location= url;
}
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 checkCookieEnable()
{
	if (navigator.cookieEnabled == 0)
	{
	  alert("You need to enable cookies for this site to load properly!");
	}
}	

function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}


function formValidation()
	{
	 var myform = document.getElementById('myform');
	 if(!checkForMandatoryFields(myform.first_name.value))
  	 {
  	  	alert('Please enter your First Name');
		myform.first_name.focus();
  	  	return false;
  	 }

  	 if(!checkForMandatoryFields(myform.last_name.value))
	 {
	 	   	alert('Please enter your Last Name');
	 		myform.last_name.focus();
	 	   	return false;
	 }
	  if(!checkForMandatoryFields(myform.email.value))
     {
	 	   	alert('Please enter your email Address');
	 		myform.email.focus();
	 	   	return false;
	 }
	 if (!isEmail(myform.email.value))
	 {
	 	alert('Please enter the valid Email Address');
		myform.email.focus();
	   	return false;
	 }
	 if(!checkForMandatoryFields(myform.phone.value))
	 {
	 	   	alert('Please enter your phone');
	 		myform.email.focus();
	 	   	return false;
	 }
	 
	myform.action = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
        myform.submit();
        createCookie('FIRSTNAMECR',myform.first_name.value,30)
        return true;
	}
	
     function loadpage()
     {
     	    checkCookieEnable();
	    var first_name= readCookie('FIRSTNAMECR');
	    if(first_name!=null)
	    {
	        var brow = navigator.appName;
	    	if(brow == "Microsoft Internet Explorer")
	         {
	    		document.getElementById('imsg').innerText = "Thank you. We will contact you shortly.";
	    	 }
	    	else
	    	 {
	    	   	alert("Thank you. We will contact you shortly.");
	    	 }
	    			
		eraseCookie('FIRSTNAMECR');
		
	    }
	 return true;
     }
    //CAPTCHA code
    function DrawCaptcha()
    {
        var a = Math.ceil(Math.random() * 10)+ '';
        var b = Math.ceil(Math.random() * 10)+ '';
        var c = Math.ceil(Math.random() * 10)+ '';
        var d = Math.ceil(Math.random() * 10)+ '';
        var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d;

        document.getElementById("txtCaptcha").value = code;
        return false;
    }
    function ValidCaptcha(){
        var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2) 
            return true;
        return false;
    }
    function removeSpaces(string)
    {
        return string.split(' ').join('');
    }
    //End of Captcha Code