
var errorMes = "";

function doBuy()
{
	errorMes = "";
	form=document.compinfo;
	if(isNotEmpty(form.firstname,"First Name") && isNotEmpty(form.lastname,"Last Name") && isNotEmpty(form.email,"Email Address") && chkemail(form.email) && isNotEmpty(form.phone,"Primary Phone") && isNotEmpty(form.title,"Job Title") && isNotEmpty(form.cname,"Company Name")  && isFieldSelect(form.state,"State/Province") && isFieldSelect(form.country,"Country") && isNotEmpty(form.noe,"Number of internal employees") && isNotEmpty(form.tframe,"Purchase timeframe") && isFieldSelect(form.hear,"How did you hear about us?") && isNotEmpty(form.txtNumber,"Verification Code"))
	{
		if(errorMes == "")
		{
			form.buypage.value=form.firstname.value+"|"+form.lastname.value+"|"+form.email.value+"|"+form.phone.value+"|"+form.title.value+"|"+form.cname.value+"|"+form.state.value+"|"+form.country.value+"|"+form.noe.value+"|"+form.tframe.value+"|"+form.hear.value+"|"+form.ohear.value+"|"+form.orefer.value;
			pcou=form.buypage.value.split("|").length;
			if(pcou==13)
			{
				form.action="sbuy.php";
				form.submit();
			}
			else
			{
				alert("You have entered pipes (|) in some of the fields, We don't allow pipes in any fields.\n\nPlease remove all the pipes in all the fields");
			}
		}
		else
		{
			document.getElementById("ebox").style.display='';
			document.getElementById("ebox").innerHTML = "<div class='error-box'><a id='ealert' href=# onClick='return false;'><img src=/images/img-error.gif border=0></a> <h5>Please correct the errors below:</h5> <ui>"+ errorMes +"</ui></div><br>";
			document.getElementById("ealert").focus();
		}
	}
}

function doContact()
{
	errorMes = "";
	form=document.compinfo;
	if(isFieldSelect(form.department,"Which Department?") && isNotEmpty(form.firstname,"First Name") && isNotEmpty(form.lastname,"Last Name") && isNotEmpty(form.email,"Email Address") && chkemail(form.email) && isNotEmpty(form.phone,"Primary Phone") && isNotEmpty(form.cname,"Company Name")  && isFieldSelect(form.state,"State/Province") && isFieldSelect(form.country,"Country") && isFieldSelect(form.hear,"How did you hear about us?") && isNotEmpty(form.inquiry,"How can we help you?") && isNotEmpty(form.txtNumber,"Verification Code"))
	{
		if(errorMes == "")
		{
			form.conpage.value=form.department.value+"|"+form.firstname.value+"|"+form.lastname.value+"|"+form.email.value+"|"+form.phone.value+"|"+form.title.value+"|"+form.cname.value+"|"+form.state.value+"|"+form.country.value+"|"+form.hear.value+"|"+form.ohear.value+"|"+form.orefer.value+"|"+form.inquiry.value;
			pcou=form.conpage.value.split("|").length;
			if(pcou==13)
			{
				form.action="scontact.php";
				form.submit();
			}
			else
			{
				alert("You have entered pipes (|) in some of the fields, We don't allow pipes in any fields.\n\nPlease remove all the pipes in all the fields");
			}
		}
		else
		{
			document.getElementById("ebox").style.display='';
			document.getElementById("ebox").innerHTML = "<div class='error-box'><a id='ealert' href=# onClick='return false;'><img src=/images/img-error.gif border=0></a> <h5>Please correct the errors below:</h5> <ui>"+ errorMes +"</ui></div><br>";
			document.getElementById("ealert").focus();
		}
	}
}

function doRefer()
{
	errorMes = "";
	form=document.compinfo;
	if(isNotEmpty(form.rfirstname,"Referral First Name") && isNotEmpty(form.rlastname,"Referral Last Name") && isNotEmpty(form.rcname,"Referral Company Name")  && isNotEmpty(form.remail,"Referral Email Address") && chkemail(form.remail) && isNotEmpty(form.rphone,"Referral Primary Phone") && isFieldSelect(form.rstate,"Referral State/Province") && isFieldSelect(form.rcountry,"Referral Country") && isNotEmpty(form.noe,"Number of Internal Employees") && isNotEmpty(form.firstname,"First Name") && isNotEmpty(form.lastname,"Last Name") && isNotEmpty(form.cname,"Company Name")  && isNotEmpty(form.semail,"Email Address") && chkemail(form.semail) && isNotEmpty(form.sphone,"Primary Phone") && isNotEmpty(form.txtNumber,"Verification Code"))
	{
		if(errorMes == "")
		{
			form.refpage.value=form.firstname.value+"|"+form.lastname.value+"|"+form.semail.value+"|"+form.sphone.value+"|"+form.title.value+"|"+form.cname.value+"|||"+form.rfirstname.value+"|"+form.rlastname.value+"|"+form.remail.value+"|"+form.rphone.value+"|"+form.rcname.value+"|"+form.rstate.value+"|"+form.rcountry.value+"|"+form.noe.value;
			pcou=form.refpage.value.split("|").length;
			if(pcou==16)
			{
				form.action="sreferral.php";
				form.submit();
			}
			else
			{
				alert("You have entered pipes (|) in some of the fields, We don't allow pipes in any fields.\n\nPlease remove all the pipes in all the fields");
			}
		}
		else
		{
			document.getElementById("ebox").style.display='';
			document.getElementById("ebox").innerHTML = "<div class='error-box'><a id='ealert' href=# onClick='return false;'><img src=/images/img-error.gif border=0></a> <h5>Please correct the errors below:</h5> <ui>"+ errorMes +"</ui></div><br>";
			document.getElementById("ealert").focus();
		}
	}
}

function doDemo()
{
	errorMes = "";
	form=document.compinfo;
	if(isRadioSelect(form.R1,"Product Demonstration") && isNotEmpty(form.firstname,"First Name") && isNotEmpty(form.lastname,"Last Name") && isNotEmpty(form.email,"Email Address") && chkemail(form.email) && isNotEmpty(form.phone,"Primary Phone") && isNotEmpty(form.title,"Job Title") && isNotEmpty(form.cname,"Company Name")  && isFieldSelect(form.state,"State/Province") && isFieldSelect(form.country,"Country") && isNotEmpty(form.noe,"Number of internal employees") && isNotEmpty(form.tframe,"Purchase timeframe") && isFieldSelect(form.hear,"How did you hear about us?") && isNotEmpty(form.txtNumber,"Verification Code"))
	{
		if(errorMes == "")
		{
			var radiovalue = "";
			for(i=0;i<form.R1.length;i++)
			{
				if(form.R1[i].checked)
					radiovalue=form.R1[i].value;
			}

			form.demopage.value=form.firstname.value+"|"+form.lastname.value+"|"+form.email.value+"|"+form.phone.value+"|"+form.title.value+"|"+form.cname.value+"|"+form.state.value+"|"+form.country.value+"|"+form.noe.value+"|"+form.tframe.value+"|"+form.hear.value+"|"+form.ohear.value+"|"+form.orefer.value+"|"+radiovalue;
			pcou=form.demopage.value.split("|").length;
			if(pcou==14)
			{
				form.action="sdemo.php";
				form.submit();
			}
			else
			{
				alert("You have entered pipes (|) in some of the fields, We don't allow pipes in any fields.\n\nPlease remove all the pipes in all the fields");
			}
		}
		else
		{
			document.getElementById("ebox").style.display='';
			document.getElementById("ebox").innerHTML = "<div class='error-box'><a id='ealert' href=# onClick='return false;'><img src=/images/img-error.gif border=0></a> <h5>Please correct the errors below:</h5> <ui>"+ errorMes +"</ui></div><br>";
			document.getElementById("ealert").focus();
		}
	}
}

function doFreeTrial()
{
	errorMes = "";
	form=document.compinfo;
	if(isNotEmpty(form.firstname,"First Name") && isNotEmpty(form.lastname,"Last Name") && isNotEmpty(form.email,"Email Address") && chkemail(form.email) && isNotEmpty(form.phone,"Primary Phone") && isNotEmpty(form.title,"Job Title") && isNotEmpty(form.cname,"Company Name")  && isFieldSelect(form.state,"State/Province") && isFieldSelect(form.country,"Country") && isNotEmpty(form.noe,"Number of internal employees") && isNotEmpty(form.tframe,"Purchase timeframe") && isFieldSelect(form.hear,"How did you hear about us?") && isNotEmpty(form.txtNumber,"Verification Code"))
	{
		if(errorMes == "")
		{
			form.page1.value=form.firstname.value+"|"+form.lastname.value+"|"+form.email.value+"|"+form.phone.value+"|"+form.title.value+"|"+form.cname.value+"|"+form.state.value+"|"+form.country.value+"|"+form.noe.value+"|"+form.tframe.value+"|"+form.hear.value+"|"+form.ohear.value+"|"+form.orefer.value;
			pcou=form.page1.value.split("|").length;
			if(pcou==13)
			{
				form.action="proceed.php";
				form.submit();
			}
			else
			{
				alert("You have entered pipes (|) in some of the fields, We don't allow pipes in any fields.\n\nPlease remove all the pipes in all the fields");
			}
		}
		else
		{
			document.getElementById("ebox").style.display='';
			document.getElementById("ebox").innerHTML = "<div class='error-box'><a id='ealert' href=# onClick='return false;'><img src=/images/img-error.gif border=0></a> <h5>Please correct the errors below:</h5> <ui>"+ errorMes +"</ui></div><br>";
			document.getElementById("ealert").focus();
		}
	}
}

function isNotEmpty(field, name)
{
	if(field.value=="")
	{
		errorMes = errorMes + "<li>Please enter the <b>" + name + "</b>.</li>";
	}
	return true;
}

// Validate email id
function chkemail(email)
{
	var str=email.value;
	var filter=/^(([\w-])+(\.?)([\w-]*))*[a-zA-Z0-9]@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if(str != "")
	{
		if (filter.test(str))
		{
			return true;
		}
		else
		{
			errorMes = errorMes + "<li>Please enter a valid <b>Email Address</b>.</li>";
		}
	}
	return true;
}

function isFieldSelect(field,name)
{
	if(getSelVal(field)=="")
	{
		errorMes = errorMes + "<li>Please select a value for <b>"+ name +"</b>.</li>";
	}
	return true;
}

function isRadioSelect(field,name)
{
	var checked = false;
	for(i=0;i<field.length;i++)
	{
		if(field[i].checked)
			checked=true;
	}

	if(!checked)
	{
		errorMes = errorMes + "<li>Please select a value for <b>"+ name +"</b>.</li>";
	}
	return true;
}

function findCountry(val)
{
	form=document.compinfo;
	if(getSelVal(form.state)!="" && !formLoading)
	{
		var state = getSelVal(form.state).split("-");
		var country = state[0];

		if(country=="USA")
			selectMe('sel-country',1,val);
		else if(country=="CAN")
			selectMe('sel-country',43,val);
	}
}

function findState(val)
{
	form=document.compinfo;
	if(getSelVal(form.country)!="" && !formLoading)
	{
		var state = getSelVal(form.state).split("-");
		var country = getSelVal(form.country);

		if(country=="243")
		{
			if(state[0]!="USA")
				selectMe('sel-state',0,val);
		}
		else if(country=="42")
		{
			if(state[0]!="CAN")
				selectMe('sel-state',0,val);
		}
		else if(country=="")
		{
			if(state[0]=="")
				selectMe('sel-state',0,val);
		}
		else
		{
			selectMe('sel-state',68,val);
		}
	}
}

function rfindCountry(val)
{
	form=document.compinfo;
	if(getSelVal(form.rstate)!="" && !formLoading)
	{
		var state = getSelVal(form.rstate).split("-");
		var country = state[0];

		if(country=="USA")
			selectMe('sel-rcountry',1,val);
		else if(country=="CAN")
			selectMe('sel-rcountry',43,val);
	}
}

function rfindState(val)
{
	form=document.compinfo;
	if(getSelVal(form.rcountry)!="" && !formLoading)
	{
		var state = getSelVal(form.rstate).split("-");
		var country = getSelVal(form.rcountry);

		if(country=="243")
		{
			if(state[0]!="USA")
				selectMe('sel-rstate',0,val);
		}
		else if(country=="42")
		{
			if(state[0]!="CAN")
				selectMe('sel-rstate',0,val);
		}
		else if(country=="")
		{
			if(state[0]=="")
				selectMe('sel-rstate',0,val);
		}
		else
		{
			selectMe('sel-rstate',68,val);
		}
	}
}

function cHear()
{
	form=document.compinfo;
	if(form.hear.value=="Other")
	{
		document.getElementById("ohear").style.display='';
		document.getElementById("orefer").style.display='none';
	}
	else if(form.hear.value=="Referred")
	{
		document.getElementById("orefer").style.display='';
		document.getElementById("ohear").style.display='none';
	}
	else
	{
		document.getElementById("ohear").style.display='none';
		document.getElementById("orefer").style.display='none';
	}
}

function showOthers()
{
	cHear();
}

function getSelVal(field)
{
	var retval="";
	for(i=0;i<field.length;i++)
	{
		if(field[i].selected)
			retval=field[i].value;
	}
	return retval;
}
