var rootdomain="http://"+window.location.hostname;
var sLocationURLDev = "/mufcweb/";
var sLocationURL = "/";
var bBaskEnable = true;

function makeRequest(url) {
    var http_request = false;
	
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }    // See note below about this line
    } else if (window.ActiveXObject) { // IE
        try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } 
        catch (e) {
            try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } 
            catch (e2) {}
        }
    }
	
    if (!http_request) { alert('Cannot create an XMLHTTP instance'); return false; }
    
    http_request.onreadystatechange = function() {
		if (http_request.readyState==4) {
			if (http_request.status==200) {
				writit(http_request.responseText, 'divBaskNew');
			} else { } //alert('There was a problem with the request. ' + http_request.status + ' ' + http_request.responseText);}
		} else { writit('<img src="' + sLocationURL + 'images/ajax-loader.gif" border="0" align="center" />', 'divBaskNew'); }
    };
    http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    http_request.send(url);
}

function refreshBask() { makeRequest(sLocationURL + 'basket/basket.aspx'); }
function refreshBask2() { makeRequest(sLocationURL + 'basket/basket.aspx?show=y'); }	
function writit(text, divid) { top.document.getElementById(divid).innerHTML = text; }
/************************************************/

function addtoBasket(title, type, pid, country, points) { //add to basket on left side
	if (bBaskEnable == true) {
		newtitle = escape(title);
		newtitle = newtitle.replace(/\//g,"%2F");
		newtitle = newtitle.replace(/\?/g,"%3F");
		newtitle = newtitle.replace(/=/g,"%3D");
		newtitle = newtitle.replace(/&/g,"%26");
		newtitle = newtitle.replace(/@/g,"%40");
		basketFrame.location = sLocationURL + "basket/update.aspx?task=add&title=" + newtitle + "&type=" + type + "&pid=" + pid + "&country=" + country + "&points=" + points;
	}
}

function addtoBasket2(title, type, pid, country, points, aval) { //add to basket on left side
	if (bBaskEnable == true) {
		newtitle = escape(title);
		newtitle = newtitle.replace(/\//g,"%2F");
		newtitle = newtitle.replace(/\?/g,"%3F");
		newtitle = newtitle.replace(/=/g,"%3D");
		newtitle = newtitle.replace(/&/g,"%26");
		newtitle = newtitle.replace(/@/g,"%40");
		basketFrame.location = sLocationURL + "basket/update.aspx?task=add&title=" + newtitle + "&type=" + type + "&pid=" + pid + "&country=" + country + "&points=" + points + "&aval=" + aval;
	}
}

function checkout(title, type, pid) { basketFrame.location = sLocationURL + "basket/update.aspx?task=checkout&title=" + title + "&type=" + type + "&pid=" + pid; }
function checkout1(title, type, pid, country) { basketFrame.location = sLocationURL + "basket/update.aspx?task=checkout&title=" + title + "&type=" + type + "&pid=" + pid + "&country=" + country; }
function deletefromBasket(type, pid) { parent.basketFrame.location = sLocationURL + "basket/update.aspx?task=delete&type=" + type + "&pid=" + pid; }
function deletefromBasketChOut(type, pid) { basketFrame.location = sLocationURL + "basket/update.aspx?task=deletech&type=" + type + "&pid=" + pid; }
function deleteallfromBasket() { basketFrame.location = sLocationURL + "basket/update.aspx?task=delall"; }
function updateShoppingBasket() { refreshBask(); }

function updateShoppingBasketCh() { //new code for redirect
	var parent_url = null;
	parent_url = new String(window.parent.location);
	parent.window.location = parent_url;
} 

function checkoutShoppingBasket() { parent.window.location = sLocationURL + "basket/checkout.aspx"; }
function dropMenuNavigation() { document.location = document.Form1.drpNavigate.value; }
function dropHandsNav() { document.location = document.Form1.model.value; }

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj_old(n, d) { //v3.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_findObj(n, d) {
	var p,i,x; if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
	x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
	x=MM_findObj(n,d.layers[i].document); if(!x&&!document.layers)
	x=document.getElementById(n); return x;
} 

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=document.getElementById(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v; obj.top=args[3]; obj.left=args[4]; }
}

function showSMSOrder(sTitle, sPid, sCost) {
	MM_showHideLayers('textlay','','hide',1,1);
	writtext(sTitle + ' ', 'MonoTitle');
	writtext(sPid + ' ', 'MonoPID');
	writtext(sCost, 'spnMonoCost');
	toppos = parent.document.documentElement.scrollTop + 100;
	MM_showHideLayers('textlay','','show',toppos+'px','400px');
}

function showSMSOrderImg(sTitle, sPid) {
	MM_showHideLayers('textlay','','hide',1,1);
	writtext(sTitle + ' ', 'divTitle');
	writtext(sPid + ' ', 'divPID');
	writtext('<img src="Media/Wall128px/' + sPid + '.jpg" border="0" />', 'divImgPrev');
	MM_showHideLayers('textlay','','show','500px','500px');
}

function writtext(stext, divid) { document.getElementById(divid).innerHTML = stext; }

/* AJAX NEW TEST */
function makePreviewRequest(url, divid) {
    var http_request = false;
	
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }    // See note below about this line
    } else if (window.ActiveXObject) { // IE
        try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } 
        catch (e) {
            try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } 
            catch (e2) {}
        }
    }
	
    if (!http_request) { alert('Cannot create an XMLHTTP instance'); return false; }
    
    http_request.onreadystatechange = function() {
		if (http_request.readyState==4) {
			if (http_request.status==200) {
				writit(http_request.responseText, divid);
			} else {
				alert('There was a problem with the request. ' + http_request.responseText); //\nStatus: ' + http_request.status + '\nResponse: ' + http_request.responseText);
			}
		}
    };
    http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    http_request.send(url);
}
/* End */


function setCardSession() {
	MM_showHideLayers('orderlay','','hide',1,1);
	bBaskEnable = true;
	basketFrame.location = sLocationURL + "basket/update.aspx?task=cardsess";
}

function showSMSbuy() { refreshBask(); }
function showSMSbuy2(sTitle, sCost, sImg, sType, sAva, sPIDLine, sAvaTxt) { 
	try {
		document.getElementById(divid).innerHTML = '';
		refreshBask();
	}
	catch (e) { }
	showFirstPayDiv(sTitle, sCost, sImg, sType, sAva, sPIDLine, sAvaTxt);
}

function showSMSBuyBask(sTitle, sCost, sImg, sType, sAva, sPIDLine, sAvaTxt) {
	var parent_url = null;
	var parent_qs = null;
	parent_url = new String(window.parent.location);
	parent_qs = new String(window.parent.location.search);
	
	if (parent_qs != '') { var new_qs = '&ib=y'; } else { var new_qs = '?ib=y'; }
	parent.window.location = parent_url + new_qs;
}

function showFirstPayDiv(sTitle, sCost, sImg, sType, sAva, sPIDLine, sAvaTxt) { 
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	parent.writit(sTitle, 'orderTitle');
	parent.writit(sCost, 'spnCost');
	parent.writit(sImg, 'spnGameImg');
	parent.writit(sType + ' ', 'prodType');
	parent.writit(sAva, 'spnGameAva');
	parent.writit(sPIDLine, 'spnGamePid');
	parent.writit(sAvaTxt, 'spnGameAvaTxt');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('smsbuylay','','show',toppos+'px',leftpos+'px');
}

function showFirstPayDiv2() { 
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	basketFrame.location = sLocationURL + "basket/update.aspx?task=smssel";
}

function showFirstPayDiv2a() { 
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('smsbuylay','','show',toppos+'px',leftpos+'px');
}

function showPaySelDiv(sTitle, sCost, sImg, sType) {
	parent.writit(sTitle, 'spnSelItem');
	parent.writit(sTitle, 'orderTitle');	
	parent.writit(sCost, 'spnCost');
	parent.writit(sImg, 'spnGameImg');	
	parent.writit(sType+' ', 'prodType');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 150; }
	else { leftpos = parent.window.innerWidth / 2 - 150; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('payOptlay','','show',toppos+'px',leftpos+'px');
}

function closeRespDiv() { MM_showHideLayers('smsresplay','','hide','1','1'); refreshBask(); }
function closeOptwin() { basketFrame.location = sLocationURL + "basket/update.aspx?task=payoptclose"; }
function closeOptDiv() { parent.MM_showHideLayers('payOptlay','','hide','1','1'); }

function showRespDiv(sRespTxt, sPidLine) {	
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	
	writit(sRespTxt, 'respMess');
	writit(sPidLine, 'spnResPid');
	writit('<img src=' + sLocationURL + 'images/animated-arrow.gif border=0 width=400 height=200>', 'respImg');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('smsresplay','','show',toppos+'px',leftpos+'px');
	parent.refreshBask();
}

function showRespDiv2(sRespTxt) {	
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	writit(sRespTxt, 'respMess');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('smsresplay','','show',toppos+'px',leftpos+'px');
}

function hideBuydiv() { 
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	parent.MM_showHideLayers('smsbuylay2','','hide','1','1');
	
	var parent_url = null;
	parent_url = new String(window.parent.location);
	if ( parent_url.indexOf("checkout") != -1 ) { parent.window.location = parent_url; }
}

function ToggleSMSDisp(oObjEnt, oObjSel) {
	if ( oObj.style.display == "none" ) { oObj.style.display = ""; } else { oObj.style.display = "none"; }
}

function noSMSOrder() { basketFrame.location = sLocationURL + "basket/update.aspx?task=smsrem"; }
function orderItem(msisdn) { top.basketFrame.location = sLocationURL + "basket/SMSorder.aspx?msisdn=" + msisdn; }

function changeCardPay() { 
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	basketFrame.location = sLocationURL + "basket/update.aspx?task=cardsess";
}
function changeCardPay2() { 
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	parent.MM_showHideLayers('smsbuylay2','','hide','1','1');
	basketFrame.location = sLocationURL + "basket/update.aspx?task=cardsess";
}

function changeCardPayTool() { basketFrame.location = sLocationURL + "basket/update.aspx?task=cardsess"; }
function changeSMSPay() { basketFrame.location = sLocationURL + "basket/update.aspx?task=smssess"; }
function changeSMSPayEmpty() { basketFrame.location = sLocationURL + "basket/update.aspx?task=smssessempty"; }
function getSMSPayItem() { basketFrame.location = sLocationURL + "basket/update.aspx?task=smssessitem"; }
function enterSMSOrderNo(msisdn) { basketFrame.location = sLocationURL + "basket/update.aspx?task=msisdncookie&msisdn=" + msisdn; }

function updateShoppingBasket2() {
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	parent.MM_showHideLayers('smsresplay','','hide','1','1');
	
	var parent_url = null;
	parent_url = new String(window.parent.location);
	parent.window.location = parent_url;
}

function updateShoppingBasket3() {
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	parent.MM_showHideLayers('smsresplay','','hide','1','1');
	refreshBask();
	
	var parent_url = null;
	parent_url = new String(window.parent.location);
	parent.window.location = parent_url;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	
	curleft = 200;
	
	return curleft;
}

function clearDivs() {
	parent.MM_showHideLayers('smsbuylay','','hide','1','1');
	parent.MM_showHideLayers('smsresplay','','hide','1','1');
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
}

function showFeeddiv_old(alertName, keyWord) {
	MM_showHideLayers('alerttextlay','','hide',1,1);
	writtext(alertName + ' ', 'alertTitle');
	writtext(alertName + ' ', 'alertTitle1');
	writtext(keyWord + ' ', 'alertkey');
	writtext(keyWord + ' ', 'alertkey1');
	
	toppos = parent.document.documentElement.scrollTop + 100;
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2; }
	else { leftpos = parent.window.innerWidth / 2; }
	
	MM_showHideLayers('alerttextlay','','show',toppos+'px',leftpos+'px');
}

function showFeeddiv(alertName, keyWord, sShort, sSuppNo) {
	MM_showHideLayers('alerttextlay','','hide',1,1);
	writtext(alertName + ' ', 'alertTitle');
	writtext(alertName + ' ', 'alertTitle1');
	writtext(keyWord + ' ', 'alertkey');
	writtext(keyWord + ' ', 'alertkey1');
	writtext(sShort, 'spnalertno');
	writtext(sShort, 'spnalertno1');	
	writtext(sSuppNo, 'spncustsuppno');
	
	toppos = parent.document.documentElement.scrollTop + 100;
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = document.body.clientWidth / 2 - 250; }
	else { leftpos = window.innerWidth / 2 - 250; }
	
	MM_showHideLayers('alerttextlay','','show',toppos+'px',leftpos+'px');
}

function updateCountry2(sUrl, sCoCode) { basketFrame.location = sLocationURL + "basket/update.aspx?task=setlocation&newloc=" + sCoCode + "&repage=" + sUrl; }

function updateCountry2a(sUrl) {
	basketFrame.location = sLocationURL + "basket/update.aspx?task=setlocation&newloc=" + document.Form1.countrycode.options[document.Form1.countrycode.selectedIndex].value + "&repage=" + sUrl;
	parent.writit('<img src="' + sLocationURL + 'images/ajax-loader.gif" border="0" align="center" />', 'divBaskNew');
}

function updateCheckoutNewLoc(sUrl) { 
	parent.writit('<img src="' + sLocationURL + 'images/ajax-loader.gif" border="0" align="center" />', 'divBaskNew');
	parent.window.location = sLocationURL + "redir.aspx?redirpg=" + sUrl; 
}

function showFirstPayDivOutUK(sTitle, sCost, sImg, sType, sShortCode, sForwardLine, sCSno, sAva, sPIDLine, sAvaTxt) { 
	writit('', 'divBaskNew');
	
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	parent.writit(sTitle, 'orderTitle2');
	parent.writit(sCost, 'spnCost2');
	parent.writit(sImg, 'spnGameImg2');
	parent.writit(sType + ' ', 'prodType2');	
	parent.writit(sShortCode, 'spnShort2');
	parent.writit(sForwardLine, 'spnProdID2');
	parent.writit(sAva, 'spnGameAva2');
	parent.writit(sPIDLine, 'spnGamePid2');
	parent.writit(sAvaTxt, 'spnGameAvaTxt2');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;	
	parent.MM_showHideLayers('smsbuylay2','','show',toppos+'px',leftpos+'px');
}

function showSMSbuyOutUK(sTitle, sCost, sImg, sType, sShortCode, sForwardLine, sCSno, sAva, sPIDLine, sAvaTxt) {
	refreshBask();
	showFirstPayDivOutUK(sTitle, sCost, sImg, sType, sShortCode, sForwardLine, sCSno, sAva, sPIDLine, sAvaTxt);
}

function insertflash(sFlash) {
	//document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="99" width="662" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>');
	//document.write('<param name="_cx" value="15875"><param name="_cy" value="2646"><param name="FlashVars" value=""><param name="Movie" value="' + sFlash + '.swf">');
	//document.write('<param name="Src" value="' + sFlash + '.swf"><param name="WMode" value="Transparent"><param name="Play" value="-1"><param name="Loop" value="-1">');
	//document.write('<param name="Quality" value="High"><param name="SAlign" value="LT"><param name="Menu" value="0"><param name="Base" value="">');
	//document.write('<param name="AllowScriptAccess" value="always"><param name="Scale" value="NoScale"><param name="DeviceFont" value="0"><param name="EmbedMovie" value="0">');
	//document.write('<param name="BGColor" value=""><param name="SWRemote" value=""><param name="MovieData" value=""><param name="SeamlessTabbing" value="1">');
	//document.write('<param name="Profile" value="0"><param name="ProfileAddress" value=""><param name="ProfilePort" value="0"><param name="AllowNetworking" value="all">');
	//document.write('<embed src="' + sFlash + '.swf" width="662" height="99" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" menu="false"></embed>');
	//document.write('</object>');
	
	//document.write('<img src="' + sLocationURL + 'images/MUMobile_Banner.gif" border="0">');
	//document.write('<img src="' + sLocationURL + 'images/662x99_Man_Mobile.jpg" border="0">');
	
	//document.write('<img src="' + sLocationURL + 'images/munich/Munich_SubHeader.jpg" border="0">');
	
	document.write('<iframe src="' + sLocationURL + 'layout/headerWidget.aspx" width="662" height="99" id="headwgt" name="headwgt" frameborder="0" scrolling="no"></iframe>');
}

function showCountryDDL(oRow) {
	var elem = document.getElementById(oRow);
	if (elem.className == 'showView') { elem.className = 'hideView'; } else { elem.className = 'showView'; }
	elem = null;
}

function showCountryDDL2(oRow1, oRow2) {
	var elem = document.getElementById(oRow1);
	var elem2 = document.getElementById(oRow2);
	if (elem.className == 'showView') { elem.className = 'hideView'; } else {elem.className = 'showView'; }
	if (elem2.className == 'showView') { elem2.className = 'hideView'; } else { elem2.className = 'showView'; }
	elem2 = null;
	elem = null;
}

function viewbask() {
	var elem = document.getElementById('baskrow');
	if (elem.className == 'showbask') { elem.className = 'hidebask'; } else { elem.className = 'showbask'; }
	elem = null;
}


function showFirstPayDivIR(sTitle, sCost, sImg, sType, sAva, sPIDLine, sAvaTxt, sPID) { 
	parent.MM_showHideLayers('payOptlay','','hide','1','1');
	parent.writit(sTitle, 'orderTitleIR');
	parent.writit(sCost, 'spnCostIR');
	parent.writit(sImg, 'spnGameImgIR');
	parent.writit(sType + ' ', 'prodTypeIR');
	parent.writit(sAva, 'spnGameAvaIR');
	parent.writit(sPIDLine, 'spnGamePidIR');
	parent.writit(sAvaTxt, 'spnGameAvaTxtIR');
	parent.writit(sPID + ' ', 'PIDIR');
	
	if (navigator.appName.indexOf("Microsoft")!=-1) { leftpos = parent.document.body.clientWidth / 2 - 250; }
	else { leftpos = parent.window.innerWidth / 2 - 250; }
	
	toppos = parent.document.documentElement.scrollTop + 100;
	parent.MM_showHideLayers('smsbuylayIR','','show',toppos+'px',leftpos+'px');
}
