function getkey(e) {
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function clearSelectList(list) {
	for(i=list.options.length-1; i>=0; --i) {
		list.options[i] = null;
	}
}

function addSelectListOption(list, value, name, flagSelected) {
	var option = document.createElement("option");
	option.text = name;
	option.value = value;
	option.selected = flagSelected;
	
	try {
		list.add(option, null);
	}
	catch (exception) {
		list.add(option);
	}
}

function getSelectListValue(object) {
	value = "";

	if (null != object) {
		value = object.options[object.selectedIndex].value;
	}
	
	return value;
}

function setSelectListValue(object, value) {
	for(i=0; i<object.options.length; ++i) {
		if (object.options[i].value == value) {
			object.selectedIndex = i;
			break;
		}
	}
}

/**
 * Handles the box toggling and associated AJAX calls.
 */
function toggle(ob, contextPath, stateKey) {
	if (ob.parentNode.getElementsByTagName('span')[1].style.display == 'none') {
		ob.getElementsByTagName('img')[0].src = contextPath + '/include/images/toggle_on.png';
		ob.parentNode.getElementsByTagName('span')[1].style.display = 'block';
	} else {
		ob.getElementsByTagName('img')[0].src = contextPath + '/include/images/toggle_off.png';
		//ob.style.backgroundImage = 'url(images/toggle_off.png)';
		ob.parentNode.getElementsByTagName('span')[1].style.display = 'none';
	}

	if (null != stateKey && '' != stateKey) {
		var ajaxRunner = new AjaxRunner(contextPath + '/ajax?action=setState&stateKey=' + stateKey + '&value=' + (ob.parentNode.getElementsByTagName('span')[1].style.display == 'block' ? 'true' : 'false'), null);
		ajaxRunner.doGet();
	}
}



/**
 * Encapsulates AJAX requests. Using this class allows the caller to invoke concurrent
 * AJAX requests while ensuring that the responses are mapped and handled correctly.
 */
function AjaxRunner(url, callback) {
	var request = initializeRequest();
	request.onreadystatechange = processResponse;

	function initializeRequest() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} 
		else if (window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
    
	function processResponse() {
		if (4 == request.readyState) {
			if (200 == request.status) {
				if (callback) {
					callback(request.responseXML);
				}
			}
			else {
				alert("Unable to retrieve data from server.");
			}
		}
	}

	this.doGet = function() {
		request.open("GET", url, true);
		request.send(null);
	}
    
	this.doPost = function(body) {
		request.open("POST", url, true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send(body);
	}
}




/* Legacy */

function showPopup(target_url, target_obj) {
	showPopupWithSize(target_url, target_obj, 700, 500);
}
function showPopupWithSize(target_url, target_obj, width, height) {
    this.target = target_obj;

    var obj_window = window.open(target_url, "Lookup", 'width='+width+',height='+height+',resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes,scrollbars=yes');
    obj_window.opener = window;
    obj_window.focus();
}

function closePopup(val) {
    window.opener.target.value = val;
    window.opener.focus();
    window.close();
}

function emailCustomerCare() {
	document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,99,117,115,116,111,109,101,114,99,97,114,101,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,34,62,99,117,115,116,111,109,101,114,99,97,114,101,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,60,47,97,62));
}

function emailInfo() {
	document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,105,110,102,111,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,34,62,105,110,102,111,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,60,47,97,62));
}

function emailMedia() {
	document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,100,105,97,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,34,62,109,101,100,105,97,64,101,120,112,101,114,116,102,108,121,101,114,46,99,111,109,60,47,97,62));
}

