// JavaScript Document
function gup( name ){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if( results == null )    return "";  else    return results[1];}

function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false
}

if (str.indexOf(at,(lat+1))!=-1){
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false
}

if (str.indexOf(dot,(lat+2))==-1){
return false
}

}

function prepopulateCaseStudiesForm(){
	var casestudies = gup( 'cs' );
	var lastsfdccampaignid = gup( 'lscid' );
	var lastsfdccampaignname = gup( 'lscn' );
	var lastsfdccampaignstatus = gup( 'lscs' );
	var leadsourceoriginal = gup( 'lso' );
	var leadsourcemostrecent = gup( 'lsmr' );
	var webtoleadform = gup( 'wtlf' );
	var source = gup( 'source' );
	var wizardrole = gup( 'role' );
	var wizardindustry = gup( 'industry' );

	document.websiteform.CaseStudies.value = casestudies;
	document.websiteform.LastSFDCCampaignID.value = lastsfdccampaignid;
	document.websiteform.LastSFDCCampaignName.value = lastsfdccampaignname;
	document.websiteform.LastSFDCCampaignStatus.value = lastsfdccampaignstatus;
	document.websiteform.LeadSourceOriginal.value = leadsourceoriginal;
	document.websiteform.LeadSourceMostRecent.value = leadsourcemostrecent;
	document.websiteform.WebToLeadForm.value = webtoleadform;
	document.websiteform.Source.value = source;
	document.websiteform.WizardRole.value = wizardrole;
	document.websiteform.WizardIndustry.value = wizardindustry;
}

function validateCaseStudiesForm(){
	var strMissingInfo = ""
	
	var FirstNameValue=document.websiteform.FirstName
	var LastNameValue=document.websiteform.LastName
	var JobTitleValue=document.websiteform.JobTitle
	var CompanyValue=document.websiteform.Company
	var EmailAddressValue=document.websiteform.EmailAddress
	var PhoneValue=document.websiteform.Phone
	var CountryValue=document.websiteform.Country
	var StateorProvinceValue=document.websiteform.StateorProvince
	var IndustryValue=document.websiteform.Industry
	var PrimaryInterestValue=document.websiteform.PrimaryInterest
	var NoofEmployeesValue=document.websiteform.NoofEmployees
	var CRMSystemDetailsValue=document.websiteform.CRMSystemDetails


	if (FirstNameValue.value == ""){
	strMissingInfo += "First Name\n";
	}
	if (LastNameValue.value == ""){
	strMissingInfo += "Last Name\n";
	}
	if (JobTitleValue.value == ""){
	strMissingInfo += "JobTitle\n";
	}
	if (CompanyValue.value == ""){
	strMissingInfo += "Company\n";
	}
	if (EmailAddressValue.value == "" || echeck(EmailAddressValue.value)==false){
	strMissingInfo += "Email Address\n";
	}
	if (PhoneValue.value == ""){
	strMissingInfo += "Phone\n";
	}
	if (CountryValue.value == ""){
	strMissingInfo += "Country\n";
	}
	if (StateorProvinceValue.value == ""){
	strMissingInfo += "State or Province\n";
	}
	if (IndustryValue.value == ""){
	strMissingInfo += "Industry\n";
	}
	if (PrimaryInterestValue.value == ""){
	strMissingInfo += "Primary Interest\n";
	}
	if (NoofEmployeesValue.value == ""){
	strMissingInfo += "No of Employees\n";
	}
	if ( document.websiteform.DoyouhaveaCRMSystem[0].checked == false && document.websiteform.DoyouhaveaCRMSystem[1].checked == false ){
	strMissingInfo += "Do you have a CRM system?\n";
	}
	if ( document.websiteform.DoyouhaveaCRMSystem[0].checked == true){
		if (CRMSystemDetailsValue.value == ""){
			strMissingInfo += "Please specify your CRM system\n";
		}
	}
		
		  if (strMissingInfo != ""){
			strMissingInfo = "Please complete the following information :\n\n\n" + strMissingInfo + "\n\n\n";
			alert(strMissingInfo);
			return false;
		  }
		  else{
		  return true;
		  }
}

function validateContactUsForm(){
	var strMissingInfo = ""
	
	var FirstNameValue=document.websiteform.FirstName
	var LastNameValue=document.websiteform.LastName
	var JobTitleValue=document.websiteform.JobTitle
	var CompanyValue=document.websiteform.Company
	var EmailAddressValue=document.websiteform.EmailAddress
	var PhoneValue=document.websiteform.Phone
	var CountryValue=document.websiteform.Country
	var StateorProvinceValue=document.websiteform.StateorProvince
	var IndustryValue=document.websiteform.Industry
	var PrimaryInterestValue=document.websiteform.PrimaryInterest
	var NoofEmployeesValue=document.websiteform.NoofEmployees
	var CRMSystemDetailsValue=document.websiteform.CRMSystemDetails


	if (FirstNameValue.value == ""){
	strMissingInfo += "First Name\n";
	}
	if (LastNameValue.value == ""){
	strMissingInfo += "Last Name\n";
	}
	if (JobTitleValue.value == ""){
	strMissingInfo += "JobTitle\n";
	}
	if (CompanyValue.value == ""){
	strMissingInfo += "Company\n";
	}
	if (EmailAddressValue.value == ""){
	strMissingInfo += "Email Address\n";
	}
	if (PhoneValue.value == ""){
	strMissingInfo += "Phone\n";
	}
	if (CountryValue.value == ""){
	strMissingInfo += "Country\n";
	}
	if (StateorProvinceValue.value == ""){
	strMissingInfo += "State or Province\n";
	}
	if (IndustryValue.value == ""){
	strMissingInfo += "Industry\n";
	}
	if (PrimaryInterestValue.value == ""){
	strMissingInfo += "Primary Interest\n";
	}
	if (NoofEmployeesValue.value == ""){
	strMissingInfo += "No of Employees\n";
	}
	if ( document.websiteform.DoyouhaveaCRMSystem[0].checked == false && document.websiteform.DoyouhaveaCRMSystem[1].checked == false ){
	strMissingInfo += "Do you have a CRM system?\n";
	}
	if ( document.websiteform.DoyouhaveaCRMSystem[0].checked == true){
		if (CRMSystemDetailsValue.value == ""){
			strMissingInfo += "Please specify your CRM system\n";
		}
	}
		
	if ( document.websiteform.Comment.value == "" ){
	strMissingInfo += "Comment / Enquiries\n";
	}

		  if (strMissingInfo != ""){
			strMissingInfo = "Please complete the following information :\n\n\n" + strMissingInfo + "\n\n\n";
			alert(strMissingInfo);
			return false;
		  }
		  else{
		  return true;
		  }
}


