// JavaScript Document


//Jump out from outer Frame
if (top.location != self.location) {
  top.location = self.location
}

var BASE_SIZE = 16;
var OVER_SIZE = 24;
var LAST_SIZE = 0;
var LAST_LEVEL = 0;
var START_FONT_CHECK_ID = false;

startList = function() {
	if (!START_FONT_CHECK_ID){startCheckFontSizeIE();START_FONT_CHECK_ID = true;}
	if (document.all && document.getElementById) {
		var navRoot = document.getElementById("nav");		
		var over;
		var j;
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			node.onmouseover=function() {
				for (j=0;j<this.childNodes.length;j++)
				{
					if (this.childNodes[j].nodeName=="UL"){
						this.childNodes[j].className+=" over";
						break;
					}
				}					
			}
			node.onmouseout=function() {
				for (j=0;j<this.childNodes.length;j++)
				{										
					if (this.childNodes[j].nodeName=="UL"){					
						this.childNodes[j].className=this.childNodes[j].className.replace(" over", "");					
						break;
					}
				}					
			}			
		}
	}
}

//Special Menu
startListSpecialMenu = function() {
	if (!START_FONT_CHECK_ID){startCheckFontSizeIE();START_FONT_CHECK_ID = true;}
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("nav");	
		var over;	
		var j;
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];

			node.onmouseover=function() {		
				for (j=0;j<this.childNodes.length;j++)
				{
					if (this.childNodes[j].nodeName=="UL"){
											
						this.childNodes[j].className+=" over";
						if (this.childNodes[j].childNodes[0].style.width=="0px" && this.childNodes[j].childNodes[0].style.height=="0px"){
							var menuWidth = this.childNodes[j].offsetWidth;
							var menuHeight = this.childNodes[j].offsetHeight;
							if (typeof(menuWidth)=="number" && typeof(menuHeight)=="number"){
								this.childNodes[j].childNodes[0].style.width = menuWidth;
								this.childNodes[j].childNodes[0].style.height = menuHeight;
							}
						}
					break;
					}
				}						
			}
			node.onmouseout=function() {
				for (j=0;j<this.childNodes.length;j++)
				{
					if (this.childNodes[j].nodeName=="UL"){			
						this.childNodes[j].className=this.childNodes[j].className.replace(" over", "");			
					break;
					}
				}				
			}

		}
	}
}


// if is mozilla browser check font-size
function startCheckFontSize(){
	var pID = window.setInterval("autoCheckFontSize()", 200);  
}

function startCheckFontSizeIE(){
	var pID = window.setInterval("autoCheckFontSizeIE()", 200);  	
}

function setCssStyle(id,css,type)
{
	if (!document.getElementById(id)){return;}
	switch (type){
		case 0:
			document.getElementById(id).className = css;			
			break;
			
		case 1:
			document.getElementById(id).className += " "+css;			
			break;
			
		default:
			break;
	}
	
}

function clearCssStyle(id,css,type)
{
	if (!document.getElementById(id)){return;}
	switch (type){
		case 0:
			document.getElementById(id).className = "";			
			break;
			
		case 1:
			document.getElementById(id).className = document.getElementById(id).className.replace(" "+css,"");
			break;
			
		default:
			break;
	}
	
}

function autoCheckFontSize(){
	var dBody = document.defaultView.getComputedStyle(document.body,null);
	var dSize = dBody.getPropertyValue("font-size");	
	dSize = parseInt(dSize.replace("/[^\d]/",""));
	if (dSize == LAST_SIZE){return;}
	if (dSize > BASE_SIZE){
		if (dSize < OVER_SIZE){
			setCssStyle("nav","HideSub1",0);
			setCssStyle("nav2","HideSub1",0);
			setCssStyle("nav3","HideSub1",0);
			setCssStyle("Search-6","HideSub1",0)
			
			setCssStyle("HomepagePrd","HideBulitDesc1",1);
			setCssStyle("neDVDPrd","HideBulitDesc1",1);
			setCssStyle("nsDVDPrd","HideBulitDesc1",1);
			setCssStyle("csDVDPrd","HideBulitDesc1",1);
			setCssStyle("prdTopNav","prdTopNavSize1",1);
			
			clearCssStyle("HomepagePrd","HideBulitDesc2",1);
			clearCssStyle("neDVDPrd","HideBulitDesc2",1);
			clearCssStyle("nsDVDPrd","HideBulitDesc2",1);
			clearCssStyle("csDVDPrd","HideBulitDesc2",1);
			clearCssStyle("prdTopNav","prdTopNavSize2",1);
			
		}else{
		
			setCssStyle("nav","HideSub2",0);
			setCssStyle("nav2","HideSub2",0);
			setCssStyle("nav3","HideSub2",0);
			setCssStyle("Search-6","HideSub2",0)
			
			setCssStyle("HomepagePrd","HideBulitDesc2",1);
			setCssStyle("neDVDPrd","HideBulitDesc2",1);
			setCssStyle("nsDVDPrd","HideBulitDesc2",1);
			setCssStyle("csDVDPrd","HideBulitDesc2",1);
			setCssStyle("prdTopNav","prdTopNavSize2",1);
			
			clearCssStyle("HomepagePrd","HideBulitDesc1",1);
			clearCssStyle("neDVDPrd","HideBulitDesc1",1);
			clearCssStyle("nsDVDPrd","HideBulitDesc1",1);
			clearCssStyle("csDVDPrd","HideBulitDesc1",1);
			clearCssStyle("prdTopNav","prdTopNavSize1",1);
								
		}
	}else{
	
		clearCssStyle("nav","",0);
		clearCssStyle("nav2","",0);
		clearCssStyle("nav3","",0);		
		clearCssStyle("Search-6","",0)	
		
		clearCssStyle("HomepagePrd","HideBulitDesc1",1);
		clearCssStyle("neDVDPrd","HideBulitDesc1",1);
		clearCssStyle("nsDVDPrd","HideBulitDesc1",1);
		clearCssStyle("csDVDPrd","HideBulitDesc1",1);
		clearCssStyle("prdTopNav","prdTopNavSize1",1);
		
		clearCssStyle("HomepagePrd","HideBulitDesc2",1);
		clearCssStyle("neDVDPrd","HideBulitDesc2",1);
		clearCssStyle("nsDVDPrd","HideBulitDesc2",1);
		clearCssStyle("csDVDPrd","HideBulitDesc2",1);
		clearCssStyle("prdTopNav","prdTopNavSize2",1);

	}
	
	if (document.getElementById("BigFontWarring")){
		if (dSize > OVER_SIZE){
			document.getElementById("BigFontWarring").style.display = "block";
		}else{
			document.getElementById("BigFontWarring").style.display = "none";
		}	
	}
		
	if (autoStoreDesc()){	
		LAST_SIZE = dSize;
	}
}

function autoCheckFontSizeIE(){		
	if (!window.readyState=="complete"){return;}	
	if (!document.getElementById("IEFontCheck")){return;}	
	var dSize = document.getElementById("IEFontCheck").offsetWidth;
	var action = 1;
	if (dSize == LAST_SIZE){return;}
		action = 1;
	if (dSize <= 8){
		action
	}else if(dSize <= 10){
		action = 2;
	}
	else{
		action = 3;
	}
	setActiveStyleSheet(action);
		
	if (autoStoreDesc()){	
		LAST_SIZE = dSize;		
	}	
}


// Commom popup window function
function PopupWin(vName,vLink,vWidth,vHeight,vLeft,vTop,vScrollbar,vResizable)
{
	var para = '';
	if(vWidth!=0)
	{para += ',width=' + vWidth;}
				
	if(vHeight!=0)
	{para += ',height=' + vHeight;}
				
	if(vLeft!=0)
	{para += ',left=' + vLeft;}
				
	if(vTop!=0)
	{para += ',top=' + vTop;}
				
	if(vScrollbar!=0)
	{para += ',scrollbars=' + vScrollbar;}
				
	if(vResizable!=0)
	{para += ',resizable=' + vResizable;}

	javascript:window.open(vLink ,vName,'toolbar=0,menubar=0,location=0,directories=0,status=0' + para)
}

/********************************************
Description:	check string is blank
Author:			Newegg.com
Date:			2004/04/14
Parameters:		s	(string)
Return:			boolean
********************************************/
function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ')&&(c != '\n')&&(c != '\t')) return false;
	}
	return true;
}

/********************************************
Description:	go search, submit form
Author:			Joshua Chen
Date:			2004/04/14
Parameters:		sFormName,iLenth
********************************************/
function goSearch(sFormName,iLength)
{
	var objForm;
	objForm = eval('document.' + sFormName);
	if (iLength >= 1)
	{	
		objForm.submit();
	}
}

/********************************************
Description:	Expand Menu, change element's style.
Parameters:		item	(item id)
Author:			Joshua Chen
Date:			2004/04/14		
********************************************/
function ExpandItem(item)
{
	obj = document.getElementById(item);
	visible = (obj.style.display != 'none');
	key = document.getElementById('x' + item);

	if (visible)
	{
		obj.style.display = 'none';
 		key.style.fontWeight = 'normal';
	}
	else
	{
		obj.style.display = 'block';
		key.style.fontWeight = 'bold';
	}
}

/********************************************
Description:	verify News letter sign up
Author:			Joshua Chen
Date:			2004/10/15
Parameters:		f	(form name)
return:			boolean
*******************************************/
function verifyNewsletterSingup(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var error_msg = "";
			
	f = eval('document.' + f);
			
	if ((f.LoginName.value == null) || (f.LoginName.value == "") || isblank(f.LoginName.value))
	{
		error_msg = "- Your email field is empty";
        empty_fields += "\n      " + error_msg;		                
    }
				    
				    
    if (f.LoginName.value.indexOf("@")==-1)
    {
		error_msg = "- Your email address is invalid";
        empty_fields += "\n      " + error_msg;		                
    }
				    
    if ((!f.Promotions.checked) && (!f.Newsletter.checked))    
    {
		error_msg = "- You didn't choose a kind of newsletters";
        empty_fields += "\n      " + error_msg;					
    }
				          
    if (!empty_fields && !errors) 
    {
		return true;
	}
    msg  = "______________________________________________________\n\n"
    msg += "Your request cannot be continue because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit again.\n";
    msg += "______________________________________________________\n"

    if (empty_fields) {
        msg += empty_fields + "\n";
    }
    alert(msg);
    return false;
}


/********************************************
Description:	autoWidth all store Products, except DVD Store
Author:			Joshua Chen
Date:			2005/03/10
Parameters:		
return:			
*******************************************/
autoWidth = function(){
	if (!document.getElementById("centerArea")){return;}
	if (!document.getElementById("HomepagePrd")){return;}
	var allW = document.getElementById("centerArea").offsetWidth;	
	var itemCount = document.getElementById("HomepagePrd").className;
	var itemEnd = itemCount.indexOf(" ");	
	if (itemEnd == -1){itemEnd = itemCount.length;}
	itemCount = parseInt(itemCount.substring(4,itemEnd));	
	allW = parseInt(allW);	
	if (allW < 464){allW = 464;}	
	var sCount = parseInt(allW / 232);	
	if (sCount > 4){sCount = 4;}	
	if (sCount > itemCount){sCount = itemCount;}
	var sPd = parseInt((allW - (232 * sCount)) / (sCount+sCount));
	var hps;
	sPd = sPd +"px";	
	for (var i=1;i<=itemCount;i++){
		if (document.getElementById("Section"+i)){
			hps = document.getElementById("Section"+i);
			hps.style.posTop = "0px";
			hps.style.paddingLeft = 0;
			hps.style.paddingRight = 0;
			hps.style.paddingLeft = sPd;			
			if ((i / sCount).toString().indexOf(".") == -1){
				hps.className = "SectionRt";
			}else{
				hps.className = "Section";
				hps.style.paddingRight = sPd;
			}
		}	
	}
}

/********************************************
Description:	autoWidth DVD Store Products
Author:			Joshua Chen
Date:			2005/03/10
Parameters:		
return:			
*******************************************/
autoWidthDVD = function(){	
	var itemCount = new Array(3);
	var itemName = new Array(3);
	itemName[0] = "ne";
	itemName[1] = "ns";
	itemName[2] = "cs";
	var bHaveDvd = false;
	var tmpItemCount;
	if (!document.getElementById("centerArea")){return;}
	if (document.getElementById("neDVDPrd")){
		tmpItemCount = document.getElementById("neDVDPrd").className;
		itemCount[0] = parseInt(tmpItemCount.substring(4,tmpItemCount.length));
		bHaveDvd = true;
	}
	if (document.getElementById("nsDVDPrd")){
		tmpItemCount = document.getElementById("nsDVDPrd").className;
		itemCount[1] = parseInt(tmpItemCount.substring(4,tmpItemCount.length));
		bHaveDvd = true;
	}
	if (document.getElementById("csDVDPrd")){
		tmpItemCount = document.getElementById("csDVDPrd").className;
		itemCount[2] = parseInt(tmpItemCount.substring(4,tmpItemCount.length));
		bHaveDvd = true;
	}
	if (!bHaveDvd){return;}
		
	var allW = document.getElementById("centerArea").offsetWidth;	
	allW = parseInt(allW);	
	
	if (allW < 464){allW = 464;}	
	var sCount = parseInt(allW / 232);
	if (sCount > 4){sCount = 4;}
	var tmpsCount;
	for (var i=0;i<itemCount.length;i++){
		if (tmpsCount < itemCount[i]){tmpsCount = itemCount[i];}
	}
	if (sCount > tmpsCount){sCount = tmpsCount;}	
	var sPd = parseInt((allW - (232 * sCount)) / (2*sCount));	
	var hps;
	sPd = sPd +"px";	
	for (var j=0;j<itemCount.length;j++){
		for (var i=1;i<=itemCount[j];i++){	
			if (document.getElementById("Section"+itemName[j]+i)){
				hps = document.getElementById("Section"+itemName[j]+i);
				hps.style.posTop = "0px";
				hps.style.paddingLeft = sPd;	
				hps.style.paddingRight = 0;					
				if ((i / sCount).toString().indexOf(".") == -1){
					hps.className = "SectionRt";
				}else{
					hps.className = "Section";
					hps.style.paddingRight = sPd;
				}
			}	
		}
	}
}

/********************************************
Description:	auto Expand online poll
Author:			Joshua Chen
Date:			2005/03/10
Parameters:		
return:			
*******************************************/
function ExpendOnlinePoll(uContent,uImage)
{	
	if (!document.getElementById(uContent)){return;}
	if (!document.getElementById(uImage)){return;}	
	if (document.getElementById(uContent).style.display == "block"){
		document.getElementById(uContent).style.display = "none";
		document.getElementById(uImage).src = "/Nest/Sort_DOWN.gif";
	}else{
		document.getElementById(uContent).style.display = "block";
		document.getElementById(uImage).src = "/Nest/Sort_UP.gif";
	}
}