//var isIE = false;  // global flag
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isPC = (navigator.userAgent.indexOf("Windows") != -1);
var isFirefox = (navigator.userAgent.indexOf("Firefox") != -1);

var dontHilite = false;

//window.name = 'opener';
//var waitWindow;

// all the special stuff needed for CW home page

var lastZip = '';
var zipInt;
var stateName, stateErr;

var selTable = 'auto_model';
var selects = ['year', 'make', 'modelgroup', 'model', 'drivetrain', 'engine', 'modelid'];


var echoResponse = false;
var politeResponse = "Please try your selection again, or refresh the page.  If this problem persists, contact the webmaster.";

var leadID = xGetCookie('lead_id');


// - - - -



function pageSetup() {
	window.focus();
	var f, e;
	/*
	if (f = document.forms[0]) {
		// hilight first empty text field
		for (var i = 0;  (e = f.elements[i]);  i++) {
			if ((e.type == 'text' || e.type == 'password' || e.type == 'textarea') && e.value == '') {
				e.focus();
				break;
			}
		}
	}
	*/
	soopaSetup();
	popSetup();

	if (!document.getElementsByTagName) return;
	
	// alternative to 'target="_blank"' for external links,
	//  because "target" has been removed from strict doctype spec
	var a, anchors = document.getElementsByTagName('a');
	for (var i = 0;  i < anchors.length;  i++) {
		a = anchors[i];
		if (a.getAttribute('href') && a.getAttribute('rel') == 'ext') 
			a.target = '_blank';
	}
}

function hiFirst(formName) {
	if (!formName || formName == '')
		formName = 'mainForm';
	var f = eval('document.'+ formName);
	for (var i = 0;  (e = f.elements[i]);  i++) {
		if ((e.type == 'text' || e.type == 'password' || e.type == 'textarea') && e.value == '') {
			e.focus();
			break;
		}
	}
}


function formSubmit(formName) {
	if (formName == '')
		formName = 'mainForm';
	var f = eval('document.'+ formName);
	f.submit();
}
function formSubmitVal(step) {
	if (validateExtra(step)) {
		formSubmit('mainForm');
	}
	else return false;
}
function formSubmitVal1p(step) {
	if (validateExtra(step)) {
		if (step == 1 || step == 3) 
			openWait();
		formSubmit('mainForm');
	}
	else return false;
}

function val(selName) {
	var sel = document.mainForm[selName];
	if (sel.options) {
		return sel.options[sel.selectedIndex].value;
	} else return '';
}



var popupTypes = [
	'width=540,height=540,resizable=yes,scrollbars=yes,location=no,toolbar=no,top=20',
	'width=620,height=540,resizable=no,scrollbars=no,location=no,toolbar=no,top=0',
	'width=420,height=300,resizable=no,scrollbars=no,location=no,toolbar=no'
	];

function popSetup() {
	var a;
	for (var i = 0;  a = document.links[i];  i++) {
		if (a.target && a.target.indexOf("popup:") == 0) {
			a.onclick = axPop;
		}
	}
}
function axPop() {
	var a = this.target.split(":");
	var specs = popupTypes[a[1]];
	var tmp, ref;
	if (specs.indexOf("left=") == -1) {
		tmp = specs.match(/width=(\d+)/);
		if (tmp[1] > 0) {
			var l = Math.floor((screen.availWidth - tmp[1])/2);
			specs += ',left='+ l;
		}
	}
	if (specs.indexOf("top=") == -1) {
		tmp = specs.match(/height=(\d+)/);
		if (tmp[1] > 0) {
			var t = Math.floor((screen.availHeight - tmp[1])/6);
			specs += ',top='+ t;
		}
	}
	//alert('name: '+a[2]+'\nspecs: '+specs);
	ref = window.open(this.href, a[2], specs);
	ref.focus();
	return false;
}




function submitPopup(valStep) {
	var f = document.mainForm;

	if (validateExtra(valStep)) {
		f.submit();
		window.close();
	}
}



function openWizard() {
	// grab fields from other form
	var f  = document.mainForm;
	var fw = document.wizardForm;
	var errors = [];

	if (!isValid('zip', fw.zip.value, '')) 
		errors.push('Your Zip Code:');
	if (!isValid('email', fw.email.value, '')) 
		errors.push('Your Email Address:');
	
	if (errors.length > 0) {
		alert("Please check the following fields before submitting:\n\n" + errors.join("\n"));
		return false;
	}

	if (f.state.value == '') {
		// retry getting state
		loadState(fw.zip);
		if (f.state.value == '') 
			//errors.push('We are experiencing technical difficulties looking up your state from your zip code.  Please try resubmitting the form.  If the problem persists, please contact the webmaster.');
			errors.push("We're sorry, but we don't currently offer any warranty products in your state.  But we're expanding fast, so please check back soon.");
	}
	if (errors.length > 0) {
		alert(errors.join("\n\n"));
		return false;
	}
	
	var url = '_wizard.html?';
	url += getqs('state', 'mainForm');
	url += '&'+ getqs('zip,email,optin[]', 'wizardForm');
	
	ref = window.open(url, 'wizard', popupTypes[1]);
	if (ref.opener == null) ref.opener = window;
	ref.opener.name = 'opener';
	ref.focus();
}




function openWait() {
	ref = window.open('_wait.html?lead_id='+leadID, 'wait', popupTypes[2]);
	if (ref.opener == null) ref.opener = window;
	ref.opener.name = "opener";
	ref.focus();
	//waitWindow = ref;
	//document.onunload = waitWindow.close();
}







// assemble query string
// either specify form variables and optionally specify form name
// or pass '*' for all varNames and specify form name (will take 1st form if empty)
// (could expand this to any/all forms... I'll do that if I ever need it)

function getqs(varNames, formName) {
	var v, vn, e, vars = [], out = [];
	if (varNames == '*') {
		var f = (formName) ? eval('document.'+ formName) : document.forms[0];
		for (var i = 0;  (e = f.elements[i]);  i++) 
			if (!vars.contains(e.name)) 
				vars.push(e.name);
	} else vars = varNames.split(',');
	
	for (var i = 0;  (v = vars[i]);  i++) {
		vn = v.replace(/[\[\]]+/, '');  // '[]' part is just for php
		out.push(vn +'='+ vals(v, formName));
	}
	return out.join('&');
}


function vals(varName, formName) {
	var e, val, opt, opts, out = [];
	var els = document.getElementsByName(varName);
	
	for (var i = 0;  (e = els[i]);  i++) {
		opts = [];
		if (formName && e.form.name != formName) continue;
		
		switch (e.type) {
			case 'checkbox':  case 'radio':
				if (e.checked) 
					val = e.value;
				else continue;
				break;

			case 'select-one':
				if (e.options.length > 0) 
					val = e.options[e.selectedIndex].value;
				else continue;
				if (val == 'Please Select...') val = '';
				break;
			
			case 'select-multiple':
				if (e.options.length > 0) {
					for (var j = 0;  (opt = e.options[j]);  j++) 
						if (opt.selected) 
							opts.push(escape(opt.value));
					val = opts.join('|');
				} else continue;
				break;
			
			//case 'text':  case 'textarea':
			//case 'hidden':  case 'password':  case 'button':
			default:
				val = e.value;
				break;
		}
		out.push((opts.length > 0) ? val : escape(val));
	}
	return out.join('|');
}








// - - - -
// Simplest possible ajax functions, made general-purpose

var reqFunc, req, response;

// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url, func) {
	reqFunc = func;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

// handle onreadystatechange event of req object
function processReqChange() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			//enterState();
			eval(reqFunc);
		} else {
		 	return req.statusText;
		}
	}
}








// invoked by all kinds of events, so make it general purpose

function ldInsert(varStr, step, flag) {
	// lead_id should be handled by cookie
	// step is overridden by wstep if it exists

	var url = '_ld.php?'+ varStr;
	
	try { loadXMLDoc(url, 'ldConfirm()'); }
	catch(e) {
		var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
		alert("Unable to get data:\n"+ msg + politeResponse);
		return;
	}
}
function ldConfirm() {
	response = req.responseText;
	var tmp = response.split('|');
	var msg;

	if (echoResponse)
		document.mainForm['response'].value = response +"\n\n"+ req.getAllResponseHeaders();
	
	if (tmp[0] == 'error') {
		msg = "Error - "+ tmp[1];
		alert(msg);
	
	} else {
		//document.mainForm['confnum'].value = tmp[1];
		var success = 1;
		//alert('inserted '+ tmp[1] +' values');
	}
}


function jsTrack(event, msg) {
}



// invoked by zip text element keyup, and possibly form onsubmit in case of error
function loadState(el) {
	var zip = el.value = el.value.replace(/\D/g, "");
	
	if (!zip.match(/^\d{5}$/)) return;
	
	if (zip != lastZip || document.mainForm['state'].value == '') {
		lastZip = zip;
		var url = '_zip.php?z='+ zip;
		//alert("url:\n" + url);
		try { loadXMLDoc(url, 'enterState()'); }
		catch(e) {
			var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
			alert("Unable to get data:\n"+ msg + politeResponse);
			return;
		}
	}
}

function enterState() {
	response = req.responseText;
	var tmp = response.split('|');
	var msg;

	if (echoResponse)
		document.mainForm['response'].value = response +"\n\n"+ req.getAllResponseHeaders();
	
	if (tmp[0] == 'error') {
		stateName = "";
		stateErr = tmp[1];
		msg = "Error - "+ tmp[1];
		alert(msg);
	
	} else {
		stateName = tmp[1];
		
		var found = tmp[2].split(',').intersect(partners.split(',')).length;

		if (!found) {
			msg = "We're sorry, but we don't currently offer any warranty products in ";
			msg += tmp[1] +". But we're expanding fast, so please check back soon.";
			document.mainForm['state'].value = '';
			stateErr = 'unsupported';
			alert(msg);
		
		} else {
			document.mainForm['state'].value = tmp[0];
			stateErr = '';
		}
	}
}



// invoked by select element change;
function loadSelect(selName, prev) {
	var v = val(prev);
	if (v == '' || v == 'Please Select...') 
		return;
	
	var url = '_sel.php?t='+ selTable +'&s='+ selName +'&v='+ selQS(prev);
	//alert("url:\n" + url);
	try { loadXMLDoc(url, 'buildSelects()'); }
	catch(e) {
		var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
		alert("Unable to get data:\n" + msg + politeResponse);
		return;
	}
}


function buildSelects() {
	response = req.responseText;
	
	if (echoResponse)
		document.mainForm['response'].value = req.responseText + "\n\n" + req.getAllResponseHeaders();
	
	var tmp = response.split('|');
	var selName = tmp[0];
	
	if (selName == 'modelid') {
		document.mainForm['modelid'].value = tmp[1];
		return;
	}
	var sel = document.mainForm[selName];
	var pairs = tmp[1].split(',');
	var val, opts, i, nextone;
	
	sel.disabled = true;
	
	clearSel(selName);
	for (i = 0;  i < pairs.length;  i++) {
		val = pairs[i];
		if (val.indexOf('=') == -1) {
			key = val;
		} else {
			opts = val.split('=');
			key = opts[0];
			val = opts[1];
		}
		sel.options[i] = new Option(key, val);
	}
	sel.disabled = false;
	
	// if only one answer, get the next one too
	//  (this is recursive, so make sure we can break out)
	if (pairs.length == 1) {
		if (nextone = nextSel(selName)) 
			loadSelect(nextone, selName);
	} else {
		// clear the boxes below
		while (nextone = nextSel(selName)) {
			if (nextone != 'modelid')
				clearSel(nextone);
			selName = nextone;
		}
	}
}


function selQS(last) {
	var out = [];
	var selName, str;
	for (var i = 0;  i < selects.length;  i++) {
	//for (var i = 0;  i < 4;  i++) {
		selName = selects[i];
		str = selName + '~' + val(selName);
		out[out.length] = str;
		if (selName == last) {
			break;
		}
	}
	str = out.join('|')
	str = str.replace(/\s/g, '+');
	return str;
}

function nextSel(name) {
	for (var i = 0;  i < selects.length;  i++) {
		if (name == selects[i])
			return selects[i + 1];
	}
	return false;
}
function clearSel(name) {
	var sel = document.mainForm[name];
	if (sel.options)
	//	sel.options = [];
		sel.options.length = 0;
	//sel.onchange = null;
	sel.disabled = true;
}






// - - - -





// soopa-rollovers
// 7/28/2001
// www.youngpup.net

function soopaSetup() {
	var img, sh, sn, sd;
	for (var i = 0; (img = document.images[i]); i++) {
		if (img.getAttribute) {

			sn = img.getAttribute("src");
			sh = img.getAttribute("hsrc");
			sd = img.getAttribute("dsrc");

			if (sn != "" && sn != null) {
				img.n = new Image();
				img.n.src = img.src;
			
				if (sh != "" && sh != null) {
					img.h = new Image();
					img.h.src = sh;
					img.onmouseover = soopaSwapOn;
					img.onmouseout  = soopaSwapOff;
				}

				if (sd != "" && sd != null) {
					img.d = new Image();
					img.d.src = sd;
					img.onmousedown = soopaSwapDown;
				}
			}
		}
	}
}
function soopaSwapOn() {
	this.src = this.h.src;
}
function soopaSwapOff() {
	this.src  = this.n.src;
}
function soopaSwapDown() {
	this.src  = this.d.src;
	this.temp = typeof(document.onmouseup) != 'undefined' && typeof(document.onmouseup) != 'unknown' ? document.onmouseup : "";
	soopaSwapUp.img = this;
	document.onmouseup = soopaSwapUp;
}
function soopaSwapUp() {
	var ths = soopaSwapUp.img;
	ths.src = ths.n.src;
	if (ths.temp) document.onmouseup = ths.temp;
}





// Extensions to the String class:
// var myStr = "  yomomma.mpg "
// myStr.trim() -> myStr now contains "hotdogs!"
// myStr.hasFileExtension(".mpg") -> true


// like Trim( ) in vbscript. removes trailing and 
// leading whitespace from a string
String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, "");
}

// determines whether or not a filename has one of the specified extensions
String.prototype.endsWith = function() {
	var bOk = false;
	for (var i = 0;  i < arguments.length;  i++) {
		if (this.indexOf(arguments[i]) == this.length - arguments[i].length) {
			bOk = true;
			break;
		}
	}
	return bOk;
}

// quick shortcut to grab parenthetical match
String.prototype.grab = function(reg) {
	//eval(reg);
	var tmp = this.match(reg);
	return (tmp[1]) ? tmp[1] : false;
}



// push is a quite useful method of arrays in newer 
// javascript implementations, but not in ie5-
Array.prototype.push = function(val) {
	this[this.length] = val;
	return val;
}
Array.prototype.contains = function(val) {
	for (i = 0;  i < this.length;  i++) 
		if (this[i] == val) 
			return true;
}
Array.prototype.without = function(val) {
	var out = [];
	for (i = 0;  i < this.length;  i++) 
		if (this[i] != val) 
			out.push(this[i]);
	return out;
}
Array.prototype.unset = function(k) {
	var out = [];
	for (i = 0;  i < this.length;  i++) 
		if (i != k) 
			out.push(this[i]);
	return out;
}

Array.prototype.intersect = function(arr) {
	var el, out = [];
	for (var i = 0;  (el = this[i]);  i++) 
		if (arr.contains(el)) 
			out.push(el);
	return out;
}





function isValid(type, str, reg) {
	var temp = str.trim();
	
	if (type == 'text') {
		if (reg != '') {
			return isValidReg(temp, reg);
		} else {
			return temp.length > 0;
		}
		
	} else if (type == 'num') {
		if (reg != '') {
			var bounds = reg.split(',');
			return isValidBoundedNumber(temp, bounds[0], bounds[1]);
		} else {
			return isValidNumber(temp);
		}
	
	} else if (type == 'phone') {
		return isValidPhoneNumber(temp);
	
	} else if (type == 'email') {
		return isValidEmailAddress(temp);
	
	} else if (type == 'zip') {
		return isValidZipCode(temp);
	
	} else if (type == 'cc') {
		return isValidCCNumber(temp);
	
	} else if (type == 'usd') {
		return isValidUSDAmount(temp);
	}
	return false;
}


function isValidReg(s, reg) {
	var regEx = eval("/" + reg + "/g");
	return s.match(reg);
}

function isValidNumber(s) {
	var temp = s.replace(/\D/g, "") + "";
	//return temp.length > 0;
	return !isNaN(temp);
}
function isValidBoundedNumber(s, min, max) {
	var temp = s.replace(/\D/g, "");
	return (!isNaN(temp) && temp >= min && temp <= max);
}

function isValidPhoneNumber(s) {
	var temp = s.replace(/\D/g, "") + "";
	return (temp.length == 10 && (s.substring(0,1)-0) > 1);
}

function isValidZipCode(s) {
	var temp = s.replace(/\D/g, "");
	//return temp.match(/^\d{5}$|^\d{9}$/) != null;
	return (temp.length == 5 || temp.length == 9);
}

function isValidSelectBox(o) {
	if (o.options.length == 0) 
		return false;
	var v = o.options[o.selectedIndex].value;
	
	return (v != "_none_" && v.trim() != "" && v != "Please Select...");
}

function isValidEmailAddress(s) {
	var temp = s.replace(/\s/g, "");
	return (temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{2,4}$/)) && 
			temp.charAt(0) != "." && !(temp.match(/\.\./));
}

function isValidCCNumber(s) {
	var temp = s.replace(/\D/g, "");
	
	// implement full mod-10 check?
	
	// simple check for plausible Visa or Mastercard
	return temp.match(/^(4|5)\d{15}$/) != null;
}

function isValidUSDAmount(s) {
	var temp = s.replace(/[^\d.-]/g, "");
	return temp.match(/^\d+\.\d\d$/) != null;
}





// masking functions - attempt to parse and reformat 
// element's values as a specific datatype
// to use, tack them to the form field's onblur handler.
// document.myForm.phone_number.onblur = phoneFieldBlurHandler	
//   -> this field will now mask for phone numbers onblur

function textFieldBlurHandler() {
	this.value = this.value.trim();
}

function numFieldBlurHandler() {
	this.value = this.value.replace(/\D/g, "");
	if (isNaN(this.value)) 
		this.value = "";
}

function dateFieldBlurHandler() {
	var d = new Date(this.value);
	if (!isNaN(d)) {
		// if the user didn't specify the century/millenium,
		// then assume the present.
		if (this.value.search(/\d{3}/) == -1) 
			d.setYear(Math.floor((new Date()).getFullYear() / 100) * 100 + d.getFullYear() % 100);

		this.value = d.getHumanDateString();
	}
}

function timeFieldBlurHandler() {
	var t = new Time(this.value);
	if (!isNaN(t)) 
		this.value = t.getHumanTimeString();
}

function emailFieldBlurHandler() {
	this.value = this.value.replace(/\s/g, "");
}

function phoneFieldBlurHandler() {
	var temp = this.value.replace(/\D/g, "");
	temp = temp.replace(/^[01]+/, "");

	if (temp.length >= 10) {
		//this.value = "(" + temp.substring(0,3) + ") ";
		this.value  = temp.substring(0,3) + "-";
		this.value += temp.substring(3,6) + "-" + temp.substring(6,10);
	} else {
		this.value = temp;
	}
}

function zipFieldBlurHandler() {
	var temp = this.value.replace(/\D/g, "");

	if (temp.length >= 5 && temp.length < 9) {
		temp = temp.substring(0,5);
	
	} else if (temp.length >= 9) {
		temp = temp.substring(0,5) + "-" + temp.substring(5,9);
	}
	this.value = temp;
}

function ccFieldBlurHandler() {
	var temp = this.value.replace(/\D/g, "");

	if (temp.length >= 16) {
		this.value = temp.substring(0,4) + "-" + temp.substring(4,8);
		this.value += "-" + temp.substring(8,12) + "-" + temp.substring(12,16);
	} else {
		this.value = temp;
	}
}

function usdFieldBlurHandler() {
	var temp = this.value.replace(/[^\d.]/g, "");
	
	if (temp.match(/^\d+$/)) 
		temp += '.00';
	if (temp.match(/^\./)) 
		temp = '0' + temp;
	if (temp.match(/\.$/)) 
		temp += '00';
	else if (temp.match(/\.\d$/)) 
		temp += '0';
	this.value = temp;
}



// convenience function.
// attaches textFieldBlurHandler to the onblur event 
// of every text or textarea element in f
// var myForm = document.myForm
// attachAllTextHandlers(myForm) 
//		-> every text element in myForm now will call 
//		   textFieldBlurHandler (above) onblur
function attachAllTextHandlers(f) {
	var el;
	for (var i = 0; (el = f.elements[i]); i++) {
		if (el.type == "text" || el.type == "textarea") 
			el.onblur = textFieldBlurHandler;
	}
}


// not currently used, but could be handy as keyup handler
function numOnly(el) {
	el.value = el.value.replace(/\D/g, "");
}




// Extensions to the Date class:
// var myDate = new Date();
// myDate.getMonthName(); -> "February"
// myDate.getHumanDateString(); -> "29 February 2000"
// myDate.getHumanTimeString(); -> "4:00 pm"


// returns the name of the month
Date.prototype.getMonthName = function() {
	return ["January","February","March","April","May","June","July","August",
			"September","October","November","December"][this.getMonth()];
}

// returns a nicely formatted date string
Date.prototype.getHumanDateString = function() {
	return this.getDate() + " " + this.getMonthName() + " " + this.getFullYear();
}

// returns a nicely formatted time string
Date.prototype.getHumanTimeString = function() {
	var h = this.getHours();
	var m = this.getMinutes();
	var t = h >= 12 ? "pm" : "am";

	if (h == 0) h = 24;
	if (h > 12) h -= 12;
	h = String(h);
	m = String(m);
	if (m.length == 1) m = "0" + m;

	return h + ":" + m + " " + t;
}




// Time is a wrapper class for the Date object
// it accepts a wide variety of strings representing the time
// and returns a date object representing the current date with the
// specified time.
//
// var myTime = new Time('4p');
// myTime now contains a date object representing today at 4PM.
//
// accepted formats include 4p, 4:p, 4:1p, 4:10p, 4:10pm, 16:00, 
// and a bunch more...

function Time(sTimeStr) {
	if (sTimeStr.trim() != "") {
		var a = sTimeStr.match(/\d{1,2}/g);
		var t = sTimeStr.match(/(am|pm|a|p)/ig);
		if (a) {
			var d = new Date();
			var h = a[0];
			var m = a[1] ? a[1] : 0;
			if (t) t = String(t[0]);
			if (t && t.charAt(0).toLowerCase() == "p") h = h % 12 + 12;
			d.setHours(h);
			d.setMinutes(m);
			return d;
		}
		return null;
	}
}


// ugly way of simulating sleep() - just eat CPU

function pause(ms) {
	var now = new Date();
	var fin = now.getTime() + ms;
	while (true) {
		now = new Date();
		if (now.getTime() > fin)
			return;
	}
}


var sleeping = false;

function sleep(ms) {
	sleeping = true;
	setTimeout('stopSleeping', 500);
	while (sleeping) {
		noop();
	}
}
function stopSleeping() {
	sleeping = false;
}
function noop() {
	return;
}


/* x_cook.js compiled from X 4.0 with XC 0.27b. Distributed by GNU LGPL. For copyrights, license, documentation and more visit Cross-Browser.com */
function xDeleteCookie(name, path){if (xGetCookie(name)) {document.cookie = name + "=" +"; path=" + ((!path) ? "/" : path) +"; expires=" + new Date(0).toGMTString();}}function xGetCookie(name){var value=null, search=name+"=";if (document.cookie.length > 0) {var offset = document.cookie.indexOf(search);if (offset != -1) {offset += search.length;var end = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;value = unescape(document.cookie.substring(offset, end));}}return value;}function xSetCookie(name, value, expire, path){document.cookie = name + "=" + escape(value) +((!expire) ? "" : ("; expires=" + expire.toGMTString())) +"; path=" + ((!path) ? "/" : path);}

