
var f;
var e;

function checkreqs(){

	f = document.forms["registration"];
	e = f.elements;	
	
	var rad_val;
	var otherreq = document.getElementById("otherreq");
	var id054A014 = document.getElementById("054A014");	// BF

	if (id054A014  &&  otherreq) { // BF check for fields in form
		if(e["SRE054"][4].checked){ //Other Area
			otherreq.innerHTML = "*";
		}
		else{ 
			otherreq.innerHTML = "";
		}
	} // BF Check that fields exist

}

function checkother(){

	f = document.forms["registration"];
	e = f.elements;	

	var other = document.getElementById("other");
	var id054A014 = document.getElementById("054A014");	// BF

	if (id054A014  &&  other) { // BF check for fields in form
	
		if(!(e["other"].value == "")){ //Other Area
			eval('e["SRE054"][5].checked=true');
		}
	}
}

function valRegex(fn, r, err) {
	var s = '' + e[fn].value;
	var v = (s.search(r) == 0);
	return (v ? '' : err);
}
function valSelect(fn, err) {
	return (e[fn].selectedIndex == 0 ? err : '');
}
function valRadio(fn, err) {
	myOption = -1;
	for (i=0; i<e[fn].length; i++) {
		if (e[fn][i].checked) { myOption = i; }
	}
	return (myOption == -1 ? err : '');
}
function putinvisitorid() {
		e["visitorID"].value = visitorID;
}
function putincid() {
		e["campaignID"].value = cidCode;
}
function removeLineBreaks(fn) {
//		e[fn].value = e[fn].value.replace (/\r\n/gi, " ");
//		e[fn].value = e[fn].value.replace (/\|/gi, "_");
}


/* var SRE118 = "";
var SRE119 = "";
var HBX_OU = getQueryVariable("HBX_OU");
var HBX_PK = getQueryVariable("HBX_PK");
	

if (HBX_OU != "undefined" && HBX_PK != "undefined")
{
	SRE118 = HBX_PK;
}
else if ( readCookie('HBX_OU') && readCookie('HBX_PK')) { 
	
	HBX_OU = unescape(readCookie('HBX_OU'));
	HBX_PK = unescape(readCookie('HBX_PK'));
	
	//HBX_OU = "69"
	//HBX_PK = "CRM_SOFTWARE_INTEGRATION";
	
	if (HBX_OU != "" && HBX_PK != "")
	{
		SRE118 = HBX_PK;
		SRE119 = HBX_OU;
	}
	else{
		SRE118 = "";
		SRE119 = "";
	}
}
else
{
	SRE118 = "";
}
*/

function putinvalues(){
	
//	e["SRE118"].value = SRE118;
//	e["SRE119"].value = SRE119;
	
	var other = document.getElementById("other");
	
	if (other  && e["SRE102"] && e["comments"] ) {  // check that fields exist 
				
			if(!(e["other"].value == "") && !(e["comments"].value == ""))
			{
				SRE102 = e["other"].value + "," + e["comments"].value;
			}
			else if (!(e["other"].value == "") && (e["comments"].value == ""))
			{
				SRE102 = e["other"].value;
			}
			else if ((e["other"].value == "") && !(e["comments"].value == ""))
			{
				SRE102 = e["comments"].value;
			}
			
			e["SRE102"].value = SRE102;

	} // check that fields exist 	
	
}

/*function changeField(){
 f = document.forms[0];
  if(f.country.value=="USA"){
      //f.province.value ="";
      //f.province.disabled =true;
	  f.area.disabled =false;
	}
   else{
     f.area.selectedIndex =0;
     f.area.disabled =true;
	 //f.province.disabled =false;
	  }
}*/


function validate() {
	
	f = document.forms["registration"];
	e = f.elements;
	var allerrs = '';


	allerrs += valRegex("first_name", /.*[a-zA-Z].*/, "* first name\n");
	allerrs += valRegex("last_name", /.*[a-zA-Z].*[a-zA-Z].*/, "* last name\n");
	if (e["title"]) {allerrs += valRegex("title", /.*[a-zA-Z].*/, "* title\n"); }
	allerrs += valRegex("company", /.*[a-zA-Z].*/, "* company\n");
//	alert(f.country.value);
	if(f.country.value=="United States"  || f.country.value=="USA" || f.country.value=="Canada" ){
		allerrs += valRegex("phone", /^(\(?[0-9]{3}[\)-\.]?\ ?)?[0-9]{3}[-\.]?[0-9]{4}$/, "* phone\n");
	}
	else { //bf 10.06.09 allow other phone formats for other non NAR countries
		allerrs += valRegex("phone", /[0-9\s\.\-]{8,}/, "* phone\n");
		if (f.phone.value.indexOf('\+') > -1) { allerrs += '* Please remove the "\+" symbol from the phone number.\n';  } 
			
	}

	allerrs += valRegex("email", /[^\s@;!,]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9\-]{2,}/, "* email\n");
	allerrs += valRegex("address1", /.*[a-zA-Z0-9].*[a-zA-Z0-9].*/, "* address 1\n");
	allerrs += valRegex("city", /.*[a-zA-Z].*/, "* city\n");
	allerrs += valRegex("area", /.*[a-zA-Z].*/, "* state\n");
	allerrs += valRegex("zip", /.+/, "* postal code\n");
	allerrs += valSelect("country", "* select country\n");
	if (e["SRE030"]) {allerrs += valSelect("SRE030", "* select department\n"); }
	if (e["SRE032"]) {allerrs += valSelect("SRE032", "* select functional title\n"); }
	if (e["SRE014"]) {allerrs += valSelect("SRE014", "* select employees on site\n"); }
	if (e["SRE015"]) {allerrs += valSelect("SRE015", "* select employees with your company\n"); }
	//allerrs += va)lRadio("SRE010", "* current avaya customer\n");

	//'Select one of three' validation
	/*if (e["SRE054"].selectedIndex < 0 && e["SRE056"].selectedIndex < 0 && e["SRE054A"].selectedIndex < 0 )
		{ allerrs += "* select at least one solution, product or service\n"; }*/
	
	//Select at least on area of interest
	if (e["SRE054"]) {
		if(!e["SRE054"][0].checked && !e["SRE054"][1].checked && !e["SRE054"][2].checked && !e["SRE054"][3].checked && !e["SRE054"][4].checked) // && !e["SRE054"][5].checked) //&& !e["SRE054"][6].checked)
		{
			allerrs += "* Please select at least one area of interest.\n"; 
		}
	
		if (e["SRE054"][4].checked)
		{
			allerrs += valRegex("other", /.*[a-zA-Z].*/, "* Please specify your other area of interest\n");
		}
	}

	if (e["SRE001"] &&  e["SRE001"].type != "hidden") {allerrs += valRadio("SRE001", "* permission to email\n"); }
	if (e["SRE002"] &&  e["SRE002"].type != "hidden") {allerrs += valRadio("SRE002", "* permission to mail\n"); 	}
	if (e["SRE003"] &&  e["SRE003"].type != "hidden") {allerrs += valRadio("SRE003", "* permission to phone\n"); }

	if (!(allerrs == '')) 	{ 
	alert('Please check the following field(s): \n' + allerrs); }
	else  {  } 

	putinvisitorid();
	putincid();
	putinvalues();
	removeLineBreaks("SRE102");

	return ((allerrs == '') ? true : false); 
}

function getQueryVariable(variable) {
	if (!(unescape(location.href).indexOf("?") == -1)) { 
		var query = location.href.split("?");
		var vars = query[1].split("&");
		var ok = false;
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				ok = true; return pair[1];
			}
		}
		if (!(ok)) { return "undefined"; }
	}
	else { return "undefined"; }
}

function s_split(str,sep)
	{var si=0,sa=new Array(),i;while((str.length>0)&&(sep.length>0)){
	 i=str.indexOf(sep);if((!i)&&(sep!=str.substring(0,sep.length)))
	 break;if(i==-1){sa[si++] = str;break;}sa[si++]=str.substring(0,i);
	 str=str.substring(i+sep.length,str.length)}return sa}


function readVisitorCookie(name) {

var ReturnValue =""; 
var c_start;
var c_end;
 
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
 	   ReturnValue = unescape(document.cookie.substring(c_start,c_end));
    } 
  }
//BF 3.5.08 if (ReturnValue == "") { ReturnValue = false; }
	if (ReturnValue == false || ReturnValue == "false") { ReturnValue = ""; }

	return ReturnValue;
}



//bf var newCookie = s_split(document.cookie, "|");
//bf 3.19.09 var visitorID = newCookie[1];
var visitorID = readVisitorCookie("visitorID"); //bf 03.19.09
var cidCode = getQueryVariable("cid");
var SRE102 = "";

//}


