function openPop(winURL) {
//alert("In openPop function");
 closePop();
 var winOptions = 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=650,height=500';
 windowpop = window.open(winURL, 'windowpop', winOptions);
}
 function closePop() {
//alert("In closePop function");
}
 var errorstr = "";
function test(frm) {
// alert("in test function");	
//alert(frm);

	var theForm = document.forms[0];
	//alert("the form name is "+theForm);
	
	
	if(document.getElementById("emailid")!=null && document.getElementById("confemailid")!=null)
				{
	      var email=document.getElementById("emailid").value;
	       var confirmemail=document.getElementById("confemailid").value;
	            //alert(email);
				if(email!=confirmemail)
				{
				errorstr += "email and confirm mail doesnt match\n";
	
				}
	}


                //alert("before calling CheckBoxGroupCheck()");

	CheckBoxGroupCheck();
	//alert("after calling CheckBoxGroupCheck()");

	//alert("No of elements is "+theForm.elements.length);

	for (i = 0; i < theForm.elements.length; i++) {
		//alert("Element Type: " + theForm.elements[i].type);
		//alert("Element Name: " + theForm.elements[i].name);
		//alert("Id: " + theForm.elements[i].id);
		//alert("class name = "+theForm.elements[i].className);
		
				
		var misc = temp(theForm.elements[i].className,
				theForm.elements[i].name, theForm.elements[i].value,
				theForm.elements[i].id);
				//alert("value = "+theForm.elements[i].value);
				
				
		}
		
			
//alert("final error str is "+errorstr);
//alert(errorstr=="");

if(errorstr=="")
{
	var requestURL = location.href;
	 var parameterName = "resourceurl";
	 var pFileName = "ResourceFilename";
	 var pSolutionName = "SolutionName";

	 if ( requestURL.length > 0 ) {
	 //alert("requestURL.length=" + requestURL.length);
	 urlStart = requestURL.indexOf(parameterName);
	 actualURL = requestURL.substring(urlStart+ parameterName.length + 1);
	// alert("actualURL = " + actualURL);

	 solutionStart = requestURL.indexOf(pSolutionName);
	// alert("solutionStart = " + solutionStart);
	 solution = requestURL.substring(solutionStart + pSolutionName.length + 1);
	 solution = unescape(solution);
	// alert("Solution = " + solution);
	 frm.Solution.value = solution;

	 subject = solution + " Resource Requested";
	 frm._override_subject.value = subject;

	 filenameStart = requestURL.indexOf(pFileName);
	// alert("filenamestart = " + filenameStart);
	 filename = requestURL.substring(filenameStart + pFileName.length + 1, solutionStart - 1);
	 filename = unescape(filename);
	 frm.filename.value = filename;
	// alert("filename = " + filename);
	 }
	 opener.document.location.href=actualURL;
	
}
else
{
alert(errorstr);
errorstr = "";
return false;
}
	}

function temp(cname, iname, ival, id) {

var theForm = document.forms['leadGen'];

	//alert("in function temp");
	//alert("class name is "+cname+"element name is "+iname+" ival is "+ival);
	
	//alert("in temp b4 checking for CheckBoxSelect");
	
	var pos = cname.indexOf("CheckBoxSelect");
	var opt=0;
	
	//alert("pos is "+pos);
	
			if (pos != -1)
			{
				//alert("1111111111");
				//alert(theForm.elements[i].checked);
				//alert(opt);
				
				if(!theForm.elements[i].checked && !opt)
				{
					//alert("2222222");
					errorstr+=theForm.elements[i].id+" should be checked \n";
					opt=1;
	
				}
				//alert("33333333");
	
			}
	
	
	//alert(errorstr);
	//alert("@@@@@");
	var pos = cname.indexOf("NullCheck");
	//alert("pos for NullCheck is "+pos);

	if (pos != -1) {
		//alert("calling NullCheck function");
		//alert(document.getElementsByName(iname)[0].value);

		if (!document.getElementsByName(iname)[0].value) {
			errorstr += id + " cannot be null \n";
		}//end of inner-if
		else {
		
		var retstr = trim(document.getElementsByName(iname)[0].value);
						if (retstr.length == 0) {
							errorstr += id + " cannot have only spaces \n";
							}
			pos = cname.indexOf("checkForInvalidCharacters");
			//alert("pos for checkForInvalidCharacters is "+pos);

			if (pos != -1) {
				//alert("calling checkForInvalidCharacters function");
				var ret = checkForInvalidCharacters(ival);

				//alert(ret);

				if (!ret) {
					errorstr += id + " cannot have Invalid Characters \n";
					
				}
			
			}

			pos = cname.indexOf("checkForNumbers");
			//alert("pos for checkForNumbers is "+pos);

			if (pos != -1) {
				//alert("calling checkForNumbers function");

				var ret = checkForNumbers(ival);

				//alert(ret);

				if (!ret) {
					errorstr += id + " cannot have Numbers \n";
				}
			}

			pos = cname.indexOf("validateUSPhone");

			//alert("pos for validateUSPhone is "+pos);

			if (pos != -1) {
				//alert("calling validateUSPhone function");
				var ret = validateUSPhone(ival);
				//alert("FINAL RETURN VALUE is "+ret);

				if (!ret) {
					//errorstr+=id +" is not Valid \n";
				}

			}

			pos = cname.indexOf("ValidateEmail");

			//alert("pos for ValidateEmail is "+pos);

			if (pos != -1) {
				//alert("calling ValidateEmail function");
				var ret = ValidateEmail(ival);
				//alert("FINAL RETURN VALUE is "+ret);

				if (!ret) {
					//errorstr+=id +" is not Valid \n";
				}

			}

			pos = cname.indexOf("ValidateCardNumber");
			{
				if (pos != -1) {
					//alert("calling ValidateCardNumber function");
					var ret = ValidateCardNumber(ival);
					//alert("FINAL RETURN VALUE is "+ret);

					if (!ret) {
						//errorstr+=id +" is not Valid \n";
					}

				}

			}

			pos = cname.indexOf("ValidateSecuriyCode");

			//alert("pos for ValidateSecuriyCode is " + pos);

			if (pos != -1) {
				//alert("calling ValidateSecuriyCode function");
				var ret = ValidateSecuriyCode(ival);
				//alert("FINAL RETURN VALUE is "+ret);

				if (!ret) {
					//errorstr+=id +" is not Valid \n";
				}

			}
			
			pos = cname.indexOf("ValidateNumbers");
			
			//alert("pos for ValidateNumbers is " + pos);
			if (pos != -1) {
			//alert("calling ValidateNumbers function");
			var ret = ValidateNumbers(ival);
			//alert("FINAL RETURN VALUE is "+ret);
			if (!ret) {
			errorstr+="Please enter only Number for "+ id+ "\n";
				  }
			
			}

			pos = cname.indexOf("ValidateZipCode");

			//alert("pos for ValidateZipCode is " + pos);

			if (pos != -1) {
				//alert("calling ValidateSecuriyCode function");
				var ret = ValidateZipCode(ival);
				//alert("FINAL RETURN VALUE is "+ret);

				if (!ret) {
					//errorstr+=id +" is not Valid \n";

				}
			

			}
			
			
	}//end of else part

}//end of if loop

}//end of function temp

function checkForInvalidCharacters(strInput) {
	var invalidChars = "?&=";
	for ( var i = 0; i < invalidChars.length; i++) {
		strBadChar = invalidChars.charAt(i); //get next invalid character
		if (strInput.indexOf(strBadChar, 0) > -1)
			return 0; //if there is one in Email
	}
	return 1;
	//returns 0 if bad char is present
}

function checkForNumbers(strInput) {
	var invalidChars = "1234567890";
	for ( var i = 0; i < invalidChars.length; i++) {
		strBadChar = invalidChars.charAt(i);
		if (strInput.indexOf(strBadChar, 0) > -1)
			return 0;
	}
	return 1;

	// returns 0 if it has numbers
}

function validateUSPhone(theFieldValue) {

	//alert("in ValidateUSPhone function with value "+theFieldValue);

	var phoneNumberDelimiters = '()- ';

	var normalizedPhone = stripCharsInBag(theFieldValue,
			phoneNumberDelimiters);
	//alert("normalizedPhone is "+normalizedPhone);

	//alert("checking if the Phone-Number is normalised");
	if (!isUSPhoneNumber(normalizedPhone)) {
		//alert("Not normalised and hence returning 0");
		return 0;
	} else {
		//alert("Normalised and hence returning 1");
		return 1;
	}
}

function isUSPhoneNumber(s) {
	//alert("in isUSPhoneNumber function with "+s);

	//alert("returning "+ (isInteger(s) && s.length == digitsInUSPhoneNumber)+" from isUSPhoneNumber function");

	var digitsInUSPhoneNumber = 10;

	return (isInteger(s) && s.length == digitsInUSPhoneNumber);
}

//removes all characters which appear in string bag from string s
function stripCharsInBag(s, bag) {
	//alert("in stripCharsInBag function with "+s+" and "+bag);
	var i;
	var returnString = '';
	//search through strings characters one by one
	//if character is not in bag, append to return string
	for (i = 0; i < s.length; i++) {
		//check that current character isnt whitespace
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1)
			returnString += c;
	}
	//alert("returning "+returnString+" from stripCharsInBag function");
	return returnString;
}

function isInteger(s) {
	//alert("in isInteger function with "+s);
	var i;
	for (i = 0; i < s.length; i++) {
		//check that current character is number.
		var c = s.charAt(i);
		if (!isDigit(c)) {
			//alert("returning false1 in isInteger");
			errorstr += "Phone Number must contain only digits . \n";
			return false;
		}
	}
	var digitsInUSPhoneNumber = 10;

	if (s.length != digitsInUSPhoneNumber) {
		//alert("returning false2 in isInteger");
		errorstr += "Phone Number should be of 10 digits. \n";
		return false;
	}

	//all characters are numbers
	//alert("returning true in isInteger");
	return true;
}

//check for empty string
function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

//returns true if character c is a digit
//(0 .. 9)
function isDigit(c) {
	return ((c >= '0') && (c <= '9'))
}
function ValidateEmail(strInput) {
	if (strInput.indexOf("@") == -1 && strInput != "") {
		errorstr += "Email should contain @ sign. \n";
		return 0;
	}

	if (strInput.indexOf("@") == 0) {
		errorstr += "Please verify that your email address is valid.\n";
		return 0;
	}

	if (strInput.indexOf(" ") >= 0 && strInput.value != "") {
		errorstr += "Please verify that your email address does not contain any spaces.\n";
		return 0;

	}
	var apos=strInput.indexOf("@");
	 var dotpos=strInput.lastIndexOf(".");
	 if (dotpos-apos<2)
	  	 {
	   	 errorstr += "Please verify that your email address is valid.\n";
	   	 return 0;
	  					
			}
	
	
	if ((strInput.indexOf('@', 0) == -1 || strInput.indexOf('.', 0) == -1)
			&& strInput != "") {
		errorstr += "Please verify that your email address is valid.\n";
		return 0;

	}

	return 1;
}
var validNum = "1234567890";
var vmax = 16;

function ValidateCardNumber(number) {
	for ( var i = 0; i <= number.length; i++) {
		if (validNum.indexOf(number.charAt(i)) == -1) {

			errorstr += "Use Only Numbers for your credit card number. \n";
			return 0;

		}
	}

	if ((number.length != vmax) && (number.length > 0)) {
		errorstr += "Credit Card Number must be 16 characters.\n";
		return 0;

	}
	return 1;

}
function ValidateSecuriyCode(number) {
 	if (number.length < 3) {
	 //alert("here");
	  //alert(number.length);
		errorstr += "Card Security Code must be at least 3 characters.\n";
		return 0;
	}

	for ( var i = 0; i <= number.length; i++) {
		if (validNum.indexOf(number.charAt(i)) == -1) {
			errorstr += "Please use only numbers for your Card Security Code.\n";
			return 0;

		}

	}

	return 1;

}

function ValidateZipCode(code)
{

	if (code.length < 5) {
		errorstr += "Your Zip Code must be five digits long.\n";
		}

	for ( var i = 0; i <= code.length; i++) {
		if (validNum.indexOf(code.charAt(i)) == -1) {
			errorstr += "Please use only numbers for Zip Code.\n";
			return 0;
		}
	}

	return 1;
}


function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ValidateNumbers(input)
{
var validNum = "1234567890";
for ( var i = 0; i <= input.length; i++) {
if(validNum.indexOf(input.charAt(i)) == -1) {
return 0;

		}
	}
	return 1;
	
}



function CheckBoxGroupCheck()
{

var theForm = document.forms[0];
var opt=0;

for (i = 0; i < theForm.elements.length; i++) {
//alert(i+" "+theForm.elements[i].type+" "+theForm.elements[i].id);

//alert((theForm.elements[i].type=="checkbox") + " and " + (theForm.elements[i].id!="") + " and "+ (theForm.elements[i].className!="CheckBoxSelect") );
		
if( (theForm.elements[i].type=="checkbox")  && (theForm.elements[i].id!="") && (theForm.elements[i].className!="CheckBoxSelect"))
{
	//alert("found checkbox");
	var checkboxid=theForm.elements[i].id;
	var reqdid=checkboxid;
	//alert("checkbox id is "+checkboxid);

	var isChecked=0;

	for (j = 0; j < theForm.elements.length; j++) {

		if(theForm.elements[j].type=="checkbox" && theForm.elements[j].id==checkboxid)
		{
			//alert(theForm.elements[j].checked);

			if(theForm.elements[j].checked)
			{
				//alert("HURRAY");
				isChecked=1;
			}
		}

	}

	//alert("isChecked is "+isChecked);
	if(!isChecked && !opt)
	{
		opt=reqdid;
		errorstr+="Please select atleast one CheckBox \n"
	}

}
}

}
 

 
 
 