function fRenderProduct(oHttp){
	if (oHttp.readyState == 4) {	
		if (oHttp.status == 200) {	
			var rtn = oHttp.responseText;
			try{if(document.getElementById("frmPop") != null){document.getElementById("pDetail").removeChild(document.getElementById("frmPop"));}}catch(e){}			
			document.getElementById("oLoader").style.display = "none";
			document.getElementById("pDetail2").style.display = "";	
			
			if (navigator.appName.indexOf('Microsoft') != -1) {
    			document.getElementById("pDetail").insertAdjacentHTML("beforeEnd", rtn);					
			}else {
                var r = document.createRange();
                r.selectNode(document.body);
                var parsedHTML = r.createContextualFragment(rtn);
			    document.getElementById("pDetail").appendChild(parsedHTML);
			}
			
    		var bh = window.innerHeight ||document.documentElement.clientHeight || document.body.clientHeight;
			var bw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
			var l = parseInt(document.getElementById("pDetail2").style.left.toLowerCase().replace(/px/, ""));
			var t = parseInt(document.getElementById("pDetail2").style.top.toLowerCase().replace(/px/, ""));
    		if(l + 504 > bw){document.getElementById("pDetail2").style.left = (bw - 550) + "px"; }		
			if(t + 450 > bh){document.getElementById("pDetail2").style.top = (bh - 450) + "px"; }	
		}		
	}
}

function fPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);   
    }
    return cursor;
}

function fDetail(objid, p, t, url, left, top, evt, pagelink){
    var obj = document.getElementById(objid);
	var divobj = document.getElementById("div" + t);
	var burl = url;
	
	fCloseDetail();		
	var o = fPosition(evt);
	var o2 = document.getElementById("oLoader");
	var o3 = document.getElementById("pDetail2");
	
	o2.style.display = "";
	o2.style.top = o.y + "px";
    o2.style.left = o.x + "px";	
	o3.style.top = o.y + "px";
	o3.style.left = o.x + "px";
	
	var oHttp = false;
	if(window.XMLHttpRequest){
		oHttp = new XMLHttpRequest();
		if(oHttp.overrideMimeType){oHttp.overrideMimeType("text/xml");}
	}else if(window.ActiveXObject){
		try {oHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {try {oHttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {alert(e);}}
	}
	
	if (!oHttp) { //navigate to product detail anyway
	    location.href = burl + "?T=" + t + "&P=" + p;
	    return false;
	}	

    try{
	    oHttp.onreadystatechange = function() { fRenderProduct(oHttp); }
        rExp = new RegExp("//.+?/") //anything between // and / 
        url = url.replace(rExp, "//" + location.hostname + "/") + "?POP=t&T=" + t + "&P=" + p + "&PAGELINK=" + escape(pagelink);

	    oHttp.open("POST", url, true);    
        oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
        oHttp.setRequestHeader("Content-length", url.length);
        oHttp.setRequestHeader("Connection", "close");
	    oHttp.send("");
    }catch(e){
	    location.href = burl + "?T=" + t + "&P=" + p;
	    return false;
    }
}

function fCloseDetail() {
    try{
        var oChild = document.getElementById("frmPop");
        if(oChild != null){document.getElementById("pDetail").removeChild(document.getElementById("frmPop"));}
    }catch(e){}	
	try{ document.getElementById("pDetail2").style.display = "none"; } catch (e) {}
}


function fSelectColour(Colour){		
	var oColor = document.getElementById("clID");
	var oSize  = document.getElementById("szID");
	
	if(Colour == null || Colour == 0){return;}

	var oDiv = document.getElementById("swatch" + Colour);	
	var orgColour = parseInt(oColor.value);					
	var oDivOrg = document.getElementById("swatch" + orgColour);							
	var iSize;

	oColor.value = Colour;			
	if(oDivOrg != null){oDivOrg.className = "Swatches";}
	if(oDiv != null){oDiv.className = "SwatchOn";}
				
	try{
	  iSize  = parseInt(_oSize.options[oSize.selectedIndex].value);
	  if(iSize == 0){iSize = parseInt(oSize.options[1].value);}
	}catch(e){iSize  = parseInt(oSize.value);}
}	
				
function fPopupPost(){
	var c = "", s = "";	
	var q = document.getElementById("qty").value;
	
	try{
	    if(document.getElementById("clID").tagName == "INPUT"){
	        c = document.getElementById("clID").value;
	    }else{
	        c = document.getElementById("clID").options[document.getElementById("clID").selectedIndex].value;
	    }
	}catch(e){}
	
	try{
	    if(document.getElementById("szID").tagName == "INPUT"){
	        s = document.getElementById("szID").value;
	    }else{
	        s = document.getElementById("szID").options[document.getElementById("szID").selectedIndex].value;
	    }
	}catch(e){}
	
	if(c == "" || s == "" || c == "0" || s == "0"){
		if((c == "" || c == "0") && (s == "" || s == "0")){ alert("Please select the colour and size you require before adding this item to your shopping basket."); }
		else if(c == "" || c == "0"){ alert("Please select the colour you require before adding this item to your shopping basket."); }
		else if(s == "" || s == "0"){ alert("Please select the size you require before adding this item to your shopping basket."); }
		else{ alert("Please select the colour/size you require before adding this item to your shopping basket."); }
		return false;
	}
	if(q == "" || isNaN(q)){
		alert("Please select your quantity you require before adding this item to your Basket.");
		return false;
	}							
	return true;
}

function otherViews(page){
    window.open("/popup.aspx?I=" + page, "", "width=639,height=660,toolbar=no,header=no,location=no,resizable=1,scrollbars=0");
}

function generalPopup(page){
    window.open("/popup.aspx?I=" + page, "", "width=775,height=600,toolbar=no,header=no,location=no,resizable=1,scrollbars=1");
}
