﻿var borderStyle = "1px solid #999";

function move_box(an, box) 
{
 var cleft = 30;
 var ctop = 0;
 var obj = an;
 while (obj.offsetParent) {
   cleft += obj.offsetLeft;
   ctop += obj.offsetTop;
   obj = obj.offsetParent;
 }
 box.style.left = cleft + 'px';
 ctop += an.offsetHeight + 2;
 if (document.body.currentStyle &&
   document.body.currentStyle['marginTop']) {
   ctop += parseInt(
     document.body.currentStyle['marginTop']);
 } 
 box.style.top = ctop + 'px';
}

function move_box2(an, box) 
{
 var cleft = 30;
 var ctop = 0;
 var obj = an;
 while (obj.offsetParent) {
   cleft += obj.offsetLeft;
   ctop += obj.offsetTop;
   obj = obj.offsetParent;
 }
 cleft = cleft - 400;
 box.style.left = cleft + 'px';
 ctop += an.offsetHeight + 2;
 if (document.body.currentStyle &&
   document.body.currentStyle['marginTop']) {
   ctop += parseInt(
     document.body.currentStyle['marginTop']);
 } 
 box.style.top = ctop + 'px';
}

var boxdiv = null;

function show_hide_box2(an, width, height) {
 var href = an.href;

 if (boxdiv != null) {    
    move_box(an, boxdiv);
    boxdiv.contents.src = href;
    boxdiv.style.display='block';
    return;
 }

 boxdiv = document.createElement('div');
 boxdiv.setAttribute('id','divbox');
 boxdiv.style.display = 'block';
 boxdiv.style.visibility = 'visible'; 
 boxdiv.style.position = 'absolute';
 boxdiv.style.width = width + 'px';
 boxdiv.style.height = height + 'px';
 boxdiv.style.border = borderStyle;
 boxdiv.style.backgroundColor = '#fff';

 boxdiv.contents = document.createElement('iframe');
 boxdiv.contents.scrolling = 'no';
 boxdiv.contents.frameBorder = '0';
 boxdiv.contents.style.width = width + 'px';
 boxdiv.contents.style.height = height + 'px';
 boxdiv.contents.src = href;

 boxdiv.appendChild(boxdiv.contents);
 document.body.appendChild(boxdiv);
 move_box2(an, boxdiv);

 return;  
}

function show_hide_box(an, width, height) {
 var href = an.href;

 if (boxdiv != null) {    
    move_box(an, boxdiv);
    boxdiv.contents.src = href;
    boxdiv.style.display='block';
    return;
 }

 boxdiv = document.createElement('div');
 boxdiv.setAttribute('id','divbox');
 boxdiv.style.display = 'block';
 boxdiv.style.visibility = 'visible'; 
 boxdiv.style.position = 'absolute';
 boxdiv.style.width = width + 'px';
 boxdiv.style.height = height + 'px';
 boxdiv.style.border = borderStyle;
 boxdiv.style.backgroundColor = '#fff';

 boxdiv.contents = document.createElement('iframe');
 boxdiv.contents.scrolling = 'no';
 boxdiv.contents.frameBorder = '0';
 boxdiv.contents.style.width = width + 'px';
 boxdiv.contents.style.height = height + 'px';
 boxdiv.contents.src = href;

 boxdiv.appendChild(boxdiv.contents);
 document.body.appendChild(boxdiv);
 move_box(an, boxdiv);

 return;  
}
 
 function show_switch_box(an, width, height, borderStyle) {
 var href = an.href;
 if (boxdiv != null) {    
    move_box(an, boxdiv);
    boxdiv.contents.src = href;
    boxdiv.style.display='block';
    return;
 }

 boxdiv = document.createElement('div');
 boxdiv.setAttribute('id','divbox');
 boxdiv.style.display = 'block';
 boxdiv.style.visibility = 'visible'; 
 boxdiv.style.position = 'absolute';
 boxdiv.style.width = width + 'px';
 boxdiv.style.height = height + 'px';
 //boxdiv.style.border = borderStyle;
 //boxdiv.style.backgroundColor = '#fff';

 boxdiv.contents = document.createElement('iframe');
 boxdiv.contents.scrolling = 'no';
 boxdiv.contents.frameBorder = '0';
 boxdiv.contents.style.width = width + 'px';
 boxdiv.contents.style.height = height + 'px';
 boxdiv.contents.src = href;

 boxdiv.appendChild(boxdiv.contents);
 document.body.appendChild(boxdiv);
 move_box(an, boxdiv);

 return;  
}
 
 function HidePopup( )
{
    window.parent.boxdiv.style.display = "none";
}

function HidePopupToDetail(objcatID,objPID) 
{   
    window.parent.boxdiv.style.display = "none";
    window.parent.location = "product.aspx?id=" + objPID + "&catID=" + objcatID;
    return;
 }
 
 function HideRefeshPopup(objID) 
{   
    var browserName = whichBrs(); 
    if(browserName != "Internet Explorer")
    {
        window.parent.boxdiv.style.display = "none";
        window.parent.location = "productList.aspx?catID=" + objID;
      //  window.parent.location = window.parent.location;
    }
    else
    {
        window.parent.boxdiv.style.display = "none";
        window.parent.location.reload(true);
    }
     return;
 }
 function SwitchPopupClose(obj) 
{   
    window.parent.boxdiv.style.display = "none";
    window.parent.location = "/Commerce.Web/categoryList.aspx?transfer=" + obj;
    return;
 }

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

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 readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
