// variables used for browser check in old menu
var MACIE = false;
var NOTNETSCAPE = false;

if(navigator.appName!='Netscape')
{
	NOTNETSCAPE = true;
}
//IE on Mac
if(browser.isIE && browser.isMac){
	MACIE = true;
}

//popup window
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

//search type
function advSearch(type) {
    document.searchForm.adv.value = type;
	if(document.searchForm.qt.value == 'Search csc.com') {
		document.searchForm.qt.value = '';
	}
}

//Run ga
function runGA() {
	_uacct = "UA-94743-1";
	_udn = "csc.com";
	urchinTracker();
}

//Get the value of a cookie
function getCPCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) {
		return null;
	}	
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) {
		end = document.cookie.length;
	}	
	return unescape( document.cookie.substring( len, end ) );
}

//Set a cookie
function setCPCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

//See if a campaign cookie has been set
function detectCampaign(){
	//If a campaign is deteced in url (via cp param) store in cookie
	var query = document.location.search.toQueryParams();
	if(query !== undefined && query.cp !== undefined) {
	  setCPCookie('campaign', query.cp, 7, '/');
	}
}

//If a campaign cookie is detected, and we're on a contact us form
//create hidden field with campaign value
function addCampaignToForm(){
	var campaign = getCPCookie('campaign');
	if(campaign !== undefined) {
		var f = document.getElementsByTagName('form');
		for(var i=0; i<f.length; i++){
		  if(f[i].name == "ContactUs" || f[i].name == "RegInfo") {
		   var el = document.createElement("input");
		   el.type = "hidden";
		   el.id = "campaign";
		   el.name = "campaign";
		   el.value = campaign;
		   f[i].appendChild(el);
		  }
		}
	}
}

//Run campaign
function runCampaign(){
	detectCampaign();
	addCampaignToForm();
}

