function gotoSwapProtocolDomain(protocolDomain){
        var resultURL = swapProtocolDomain(protocolDomain);
        if(window.location.href != resultURL){
                document.location=resultURL;
        }

}

/* 
pass in the protocol and domain and it will swap it into the _current_ location.
you can use this to swap the current protocol and domain with a secure version.
*/
function swapProtocolDomain(protocolDomain) {

/* no need to swap if they aren't different */
var matchingIndex = window.location.href.indexOf(protocolDomain);
if (matchingIndex > -1) {
	return window.location.href;
}

/* we'll search after the 7th char assuming "http://" */
var slashIndex = window.location.href.indexOf('/', 7);

/* if current protocol is "https://", we readjust to cater that instead */
if(window.location.href.indexOf('https') > -1){
	slashIndex = window.location.href.indexOf('/', 8);
}

if (slashIndex > -1) {
	var swapOut = window.location.href.substr(0, slashIndex);
	var keep = window.location.href.substr(slashIndex);
	return protocolDomain + keep;
} else {
	return protocolDomain;
}
}

function showAjaxLoader() {
	$('utilityWindow').update('<div align=center><img src="/images/gen/spinner_large.gif" hspace=50 vspace=50></div>');
}


/**
 * Updates the layer(popup) div contain the checkout page.
*/
function updatePopup(response, arg) {

	var pos = response.indexOf("SHIPPING_PAGE_UNIQUE_TEXT");
	var pos2 = response.indexOf("BILLING_PAGE_UNIQUE_TEXT");
	
	
	if(pos >=0 || pos2 >=0) {
		location.href = arg.success_url;
	} else {
		document.getElementById(arg.elementId).innerHTML= response;
		_resizeModal($('ModalContent').getWidth(),$('ModalContent').getHeight());
	}
}

function popUp(url, elementID, url_params) {

//	setHeight();
//	popUpRelocate(elementID);
	asyncGet(url, 'updateCOPage', {'elementId': elementID}, url_params);
	document.getElementById('co_top').style.display = "block";
	document.getElementById('pop_up_bg').style.display = "block";
//	document.body.onscroll = popUpRelocate;
//	window.onscroll = popUpRelocate;

}

function closePopUp() {
	document.getElementById("co").style.display="none"; 
	document.getElementById("co_top").style.display="none"; 
	document.getElementById("pop_up_bg").style.display = "none";
}

/*extends the grey bg for popup cart page */
function setHeight(){

        var container = document.getElementById('container');

        if (!container) { return; };

        var pixelHeight = container.offsetWidth;

        var co = document.getElementById('co_top');

        if (!co) { return; };

        co.style.height = pixelHeight + "px";

}

function scrolledX() {
	var scrolledX;
	if( self.pageYOffset ) {
	  scrolledX = self.pageXOffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	  scrolledX = document.documentElement.scrollLeft;
	} else if( document.body ) {
	  scrolledX = document.body.scrollLeft;
	}
	
	return scrolledX;
}

function scrolledY() {
	var scrolledY;
	if( self.pageYOffset ) {
	  scrolledY = self.pageYOffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	  scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
	  scrolledY = document.body.scrollTop;
	}	
	
	return scrolledY;
}

function popUpRelocate() {
	
	var leftOffset = scrolledX() + 50;
	var topOffset = scrolledY() + 50;
	
	document.getElementById('co').style.top = topOffset + "px";
	document.getElementById('co').style.left = leftOffset + "px";
	
}