function did(string) {
	return document.getElementById(string);
}

//this is the png fix
var fixlist = ['alertimg', 'alertimg2', 'nav_arrow', 'alert_arrow', 'news_arrow', 'feat_arrow', 'faq_arrow', 'hotitem_arrow', 'navmod_arrow', 'additems', 'additems2', 'arrow']; // add images here


function xhr() {
	if ( window.XMLHttpRequest ) {
		request = new XMLHttpRequest();
	} else if ( window.ActiveXObject ) {
		try {
			request = new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch ( error ) {
			try {
				request = new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( error2 ) {
				return alert("Fatal Error: No XMLHttp Interface Available");
			}
		}
	} else {
		return alert("Fatal Error: No XMLHttp Interface Available");
	}
	return request;
}


function rpc(path, input) {
	var requestType = "POST";
	
	if ( !input ) {
		requestType = "GET";
		input = null;
	}
	
	var request = xhr();
	
	
	request.open(requestType, 'rpc/'+path, false);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		
	request.send(input);
	eval("var res="+request.responseText);
	return res;
}

function async_rpc(path, callback, input) {
	this.requestType = "POST";
	this.myCallback = callback;
	
	this.callback = function () {
		if (4 == this.request.readyState && 200 == this.request.status) {
			eval("var res="+this.request.responseText);
			//res.callback(res.retval);
			this.myCallback(res);
		}
	}
	
	this.abort = function (){
		this.request.abort();
	}

	
	if ( !input ) {
		this.requestType = "GET";
		this.input = null;
	}
	
	var request = xhr();

	this.request.onreadystatechange = createDelegate(this, 'callback');

	this.request.open(this.requestType, 'rpc/'+path, true);
	this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.request.send(input);
	
}

function activaX(element, url, input) {
	this.element = domcheck(element);
	this.url = url;
	
	var request = xhr();
	this.request.onreadystatechange = createDelegate(this, 'callback');
	this.request.open("GET", this.url, true);
	this.request.send(null);
	
	this.callback = function() {
		this.element.innerHTML = this.request.responseText;
		this.element.innerHTML = this.element.innerHTML //ie fix
	}
	
}



function createDelegate(oObject, sMethodName) {
	return function () {
		return oObject[sMethodName].apply(oObject, arguments);
	};
}

function domcheck(elem) {
	if ( typeof(elem) == 'object' ) {
		return elem;
	}
	
	return did(elem);
}

function registerEvent(elem, event, callback, capture) {
	if ( typeof(capture) != 'undefined' ) {
		capture = true;
	}
	if ( event == 'allchange' ) {
		registerEvent(elem, 'change', callback, capture);
		registerEvent(elem, 'click', callback, capture);
		registerEvent(elem, 'keyup', callback, capture);
		return;
	}
	elem = domcheck(elem);
	
	if ( elem.addEventListener ) {
		elem.addEventListener(event, callback, capture);
	} else {
		elem.attachEvent('on'+event, callback, capture); 
	}
}

function unregisterEvent(elem, event, callback, capture) {
	if ( typeof(capture) != 'undefined' ) {
		capture = true;
	}
	if ( event == 'allchange' ) {
		unregisterEvent(elem, 'change', callback, capture);
		unregisterEvent(elem, 'click', callback, capture);
		unregisterEvent(elem, 'keyup', callback, capture);
		return;
	}
	elem = domcheck(elem);
	
	if ( elem.removeEventListener ) {
		elem.removeEventListener(event, callback, capture);
	} else {
		elem.detachEvent('on'+event, callback, capture); 
	}
}



function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
return win;
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s*/, '');
}

String.prototype.rtrim = function()
{
	return this.replace(/\s*$/, '');
}

String.prototype.trim = function()
{
	return this.rtrim().ltrim();
}

Array.prototype.find = function(targ)
{
	for(x in this) {
		if ( this[x] == targ ) {
			return x;
		}
	}
	return false;
}

Array.prototype.inArray = function(targ)
{
	if( this.find(targ) ) {
		return true;
	} else {
		return false;
	}
}

Array.prototype.remove = function(pos)
{
	if ( pos ) {
		this.splice(pos, 1);
	}
	
}

function getNextSibling(elem) {
	elem = domcheck(elem);
	if ( !elem.nextSibling ) {
		return false;
	}
	if ( elem.nextSibling.nodeName == '#text' ) {
		return getNextSibling(elem.nextSibling);
	}
	return elem.nextSibling;
}

function getPreviousSibling(elem) {
	elem = domcheck(elem);
	if ( !elem.previousSibling ) {
		return false;
	}
	if ( elem.previousSibling.nodeName == '#text' ) {
		return getPreviousSibling(elem.previousSibling);
	}
	return elem.previousSibling;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function did(name) {
	return document.getElementById(name);
}

function hideID(name) {
	if(did(name)) {
		did(name).style.display = 'none';
	}
}

function showID(name) {
	if(did(name)) {
		did(name).style.display = '';
	}
}

function toggleDisplayID(name,roll) {
	if(did(name)) {
		if(did(name).style.display == 'none') {
			//if(roll == 'updown') {
				//alert('blah');
			//	new Activa_FX('RollDown', name, 200);
			//} else {
				showID(name);
			//}
		} else {
			//if(roll == 'updown') {
				//alert('blah');
			//	new Activa_FX('RollUp', name, 200);
			//} else {
				hideID(name);
			//}
		}
	}
}

function vRoll(name, height, speed) {
	if(! speed) {
		speed = 250;
	}
	fxHeight = height;
	var targ = domcheck(name);
	if ( targ.style.display == 'none' ) {
		new Activa_FX('RollDown', targ, speed);
	} else {
		new Activa_FX('RollUp', targ, speed);
	}
}
function rollDisplayID(name, roll) {
	var targ = domcheck(name);
	if ( targ.style.display == 'none' ) {
		new Activa_FX('RollDown', targ, 250);
	} else {
		new Activa_FX('RollUp', targ, 250);
	}
}

function changeCreditCardCountry() {
	if(did('cc_country').value == '213' || did('cc_country').value == '38') { 
		showID('cc_state_dd_region'); hideID('cc_state_txt_region');
	} else {
		hideID('cc_state_dd_region'); showID('cc_state_txt_region');
	}
}


function step1updateOpCount() {
	if(did('opcount')) {
		var opcount = did('opcount').value;		
		
		var uri = "ActivaUpdater.php";
		var data = "";
	
		data += nh.compressData("action", "step1updateOpCount");
		data += nh.compressData("opcount", opcount);
	
		ActivaUpdater(uri, data);
	}
}

var editingOp = 0;
function modifyOp( opId ) {
	if(editingOp == 0 || editingOp == opId) {
		showID('editRow1op'+opId);
		showID('editRow2op'+opId);
		editingOp = opId;
	} else {
		alert("You may only edit one operator at a time.");
	}
	
	
}