<!--
var args = getArgs();
var allcookies = document.cookie;

// ##################### MOVE THIS CODE TO TEMPLATES SO THAT IT APPEARS ON EVERY PAGE ########################
// ############################ ALONG WITH THE LINK TO THE NEW JS FUNCTIONS FILE #############################
// check to see if a promo code was passed 
// and set cookie accordingly
//var locationOffer = document.location.href.indexOf("?Offer=");
//if (locationOffer != -1) {
//    var Offer = document.location.href.substring(locationOffer + 7, document.location.href.length);
//    setSessionCookie("Offer",Offer);
//}
// ###########################################################################################################

function validateForm(form) {
	var ttalert = '';
	ttalert += validateProfile(form);
	if (ttalert != '') ttalert = "The following Personal Profile fields are required:\n" + ttalert;
    ttalert += validateQuestions(form);
	if (ttalert != '') {
		alert(ttalert);
        return false;
	} else {
		return true;
	}
}

function checkEmail(emailStr, disp_name) {
    var reEmail = /_?([A-Za-z0-9\_-]+@.+\.[A-Za-z0-9-]{2,4})$/;;
    if (emailStr == "") {
        return "\t" + disp_name + "\n";
    }
    if (emailStr.match(reEmail) != null) {
        return "good";
    }
    else {
        return "\t" + disp_name + " address improperly formatted.\n";
    }
}

function validateTextField(value, disp_name) {
	var result = '';
	if (value == '') {
		result = "\t" + disp_name + "\n";
	}
	return result
}

function validateCheckBox(field) {
	// Check checkbox fields
	var checked = "false";
	var j;	
	
	for (j=0; j < field.length; j++) {
		if (field[j].checked == true) {
			checked = "true";
		}
	}
	return checked
}

function validateSingleCheckBox(field) {
	// Check checkbox fields
	var checked = "false";
	
	if (field.checked == true) {
		checked = "true";
	}
	return checked
}

function validateProfile(form) {
	var ttalert = '';
	if (form.first_name) { ttalert += validateTextField(form.first_name.value,"First Name"); }
	if (form.last_name) { ttalert += validateTextField(form.last_name.value,"Last Name"); }
	if (form.title) {
        if (form.title.type == "select-one") {
            if (form.title.selectedIndex == 0) {
                ttalert += "\tJob Title\n";
            }
        }
        if (form.title.type == "text") {
            ttalert += validateTextField(form.title.value,"Job Title");
        }
    }
	if (form.company) { ttalert += validateTextField(form.company.value,"Company"); }
	if (form.address1) { ttalert += validateTextField(form.address1.value,"Address 1"); }
	if (form.city) { ttalert += validateTextField(form.city.value,"City"); }
	if (form.state && form.province) {
        if (form.state.type == "select-one") {
            if ((form.state.selectedIndex == 0) && (form.province.value == '')) {
                ttalert += validateTextField(form.province.value,"State / Province");
            }
        }
        else if (form.state.type == "text") {
            if ((form.state.value == '') && (form.province.value == '')) {
                ttalert += validateTextField(form.province.value,"State / Province");
            }
        }
    }
	if (form.zip) { ttalert += validateTextField(form.zip.value,"Zip"); }
    if (form.country) {
        if (form.country.selectedIndex == 0) {
            ttalert += "\tCountry\n";
        }
    }
    if (form.phone) { ttalert += validateTextField(form.phone.value,"Telephone"); }
    if (form.fax) { ttalert += validateTextField(form.fax.value,"Fax"); }
    if (form.email) {
        var emailStatus = checkEmail(form.email.value, "Email");
        if (emailStatus != 'good') {
            ttalert += emailStatus;
        }
    }
	if (form.company_url) { ttalert += validateTextField(form.company_url.value,"Company URL"); }
	return ttalert;
}

function checkState(form) {
    if (form.state.selectedIndex != 0 && form.state.selectedIndex != (form.state.options.length - 1)) {
        form.country.selectedIndex = 224;
    }
    else if (form.state.selectedIndex == (form.state.options.length - 1)) {
        form.country.selectedIndex = 0;
    }
}

function checkCountry(form) {
    if (form.country.selectedIndex != 224) {
        form.state.selectedIndex = form.state.options.length - 1;
    }
    else if (form.country.selectedIndex == 224 && form.state.selectedIndex == (form.state.options.length - 1)) {
        form.state.selectedIndex = 0;
    }
        
}

function getArgs() {
	var args = new Object();
	var query = document.location.search.substring(1);
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var argvalue = pairs[i].substring(pos+1);
		args[argname] = unescape(argvalue);
	}
	return args;
}

function cookieExists(name) {
	var indexCookie = allcookies.indexOf(name + "=");
	
	return indexCookie;
}

function getCookieValue(name) {
	var pos = allcookies.indexOf(name + "=");
	if (pos != -1) {
		var start = pos + name.length + 1;
		var end = allcookies.indexOf(";",start);
		if (end == -1) end = allcookies.length;
		var value = allcookies.substring(start, end);
		
		return value;
	} else {
		return "";
	}
}

function getChipValue(cookiename,chipname) {
	var cookievalue = getCookieValue(cookiename);
	if (cookievalue != "") {
		if (cookievalue.indexOf(chipname) != -1) {
			var start = unescape(cookievalue.substring(cookievalue.indexOf(chipname) + chipname.length));
			var end = start.substring(0,start.indexOf(";"));
			var regexp = /(\\W)/g;;
			var value = end.replace(regexp," ");
			
			return value;
		} else {
			return "";
		}
	} else {
		return "";
	}
}

function initPage() {
    //pre populate fields if we're on page 1
    // of the registration page
    if (window.location.href.indexOf("registration.htm") != -1) {
        if (args.Offer) {
			// save the promo code in a session cookie so that
			// we don't lose it if they browse to another page
			setSessionCookie("Offer",args.Offer);
			
            // pre-populate the promo_code field
            if (document.form1.promo_code) {
				document.form1.promo_code.value = args.Offer;
			}
        }
        if (cookieExists("Datav1") != -1) {
            // pre-populate the first and last name fields
            var disp_name = getChipValue("Datav1", "DispName");
            var first_name = disp_name.substring(0, disp_name.indexOf("+"));
            var last_name = disp_name.substring(disp_name.indexOf("+") + 1);   
            
            if (document.form1.first_name) { document.form1.first_name.value = first_name; }
            if (document.form1.last_name) { document.form1.last_name.value = last_name; }
        }
    }
}

function setSessionCookie(name, value) {
	var domain = window.location.hostname;
	if (domain.indexOf('www') != -1) {
		domain = domain.substring(3);
	}
	else {
		domain = ".techtarget.com";
	}
	var the_cookie = name + "=" + value;
	var the_cookie = the_cookie + ";path=/";
	var the_cookie = the_cookie + ";domain=" + domain;
	document.cookie = the_cookie;

}

function openWin(url) {
	var domain = window.location.hostname;
	if (bolPopUp == true &&
		window.location.href.indexOf("registration.htm") != -1) {
		
        if (cookieExists("confSurvey") == -1) {
            // if the cookie does not exist, display survey
			// otherwise, they've already seen the survey
			strFeatures = "left=100,top=100,height=500,width=800,resizable,scrollbars";
			strWinName = "confSurvey";
			
			setSessionCookie("confSurvey", "true");
			
			objSurvey = window.open(url,strWinName,strFeatures);
			//objSurvey.moveTo((screen.availWidth/2),(screen.availHeight/2)); // fails in certain versions of IE (6.028)
			objSurvey.focus();
        }
	}
}
function getParameter ( queryString, parameterName ) {
  // Add "=" to the parameter name (i.e. parameterName=value)
  var parameterName = parameterName + "=";
  if ( queryString.length > 0 ) {
    // Find the beginning of the string
    begin = queryString.indexOf ( parameterName );
    // If the parameter name is not found, skip it, otherwise return the value
    if ( begin != -1 ) {
      // Add the length (integer) to the beginning
      begin += parameterName.length;
      // Multiple parameters are separated by the "&" sign
      end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
        end = queryString.length
      }
      // Return the string
      return unescape ( queryString.substring ( begin, end ) );
    }
    // Return empty string if no parameter has been found
    return "";
  }
}

// check to see if a promo code was passed
// and set cookie accordingly
var offer = getParameter(document.location.href,"Offer");
if (offer.length>0) {
  setSessionCookie("Offer",offer);
  
}
//-->
