// JScript File
function showSubMenu(menuString,obj,obj1){
	menu = document.getElementById(menuString);
	ShowSelectMenu(menu,obj,obj1);
	/*****hidden  select********/
	var argArr=showSubMenu.arguments;
	if(argArr.length>3&&argArr[3]=="hidden")
	{
		HideElement("select");
	}
	/*****hidden  select********/
}

function browserIsIE()
{  
	if (navigator.appName == "Microsoft Internet Explorer")
		return true;
	else return false;
}

var isIE = browserIsIE();

function $get(id)
{
	return document.getElementById(id);
}
function hideElement(e)
{
	e.style.display = "none";
}
function displayElement(e)
{
	e.style.display = "";
}
function setHtml(e, html)
{
	e.innerHTML = html;
}


function ShowSelectMenu(menu, div ,value)
{
	if (open_menu != null)
		open_menu.style.display = "none";
    if(value==0){
       positionMenu(menu, div, -234, 28);     //分站点首页
    }else if(value==1){
       positionMenu(menu, div, 0, 20);     //招聘会
    }   
   // positionMenu(menu, div, 0, 17);
    
    // hide all SELECT objects
    //sels = document.getElementsByTagName("select");
    //for (i=0; i<sels.length; i++)
	//	sels[i].style.visibility = "hidden";
		
   // if (menu.filters)
  //  {
  //      menu.filters[0].Apply();
   //     menu.style.display = "";
   //     menu.filters[0].Play();
  //  }
 //   else
        menu.style.display = "";
    
    open_menu = menu;
    menu_to_hide = null;
}

function getWebURL(webURL, storeID, deptID, productID)
{
	if (productID > 0)
		return webURL + "Product.aspx?storeID=" + storeID + "&categoryID=" + deptID + "&productID=" + productID;
	else if (deptID > 0)
		return webURL + "Category.aspx?storeID=" + storeID + "&categoryID=" + deptID;
	else if (storeID > 0)
		return webURL + "Store.aspx?storeID=" + storeID;
	else
		return webURL + "Default.aspx";
}

function timer_hide_menu()
{
	if (menu_to_hide != null) 
	{
		menu_to_hide.style.display = 'none';
		menu_to_hide = null;
		
		// hide all SELECT objects
		sels = document.getElementsByTagName("select");
		for (i=0; i<sels.length; i++)
			sels[i].style.visibility = "visible";
			
		
	}
}

open_menu = null;
menu_to_hide = null;

function menu_over(td)
{
	td.style.backgroundColor = '#DDDDDD';
}
function menu_out(td)
{
	td.style.backgroundColor = '';
}

function keep_menu(menu)
{
	/*****hidden  select********/
	var argArr=keep_menu.arguments;
	if(argArr.length>1&&argArr[1]=="hidden")
	{
		HideElement("select");
	}
	/*****hidden  select********/
	menu_to_hide = null;
	open_menu = menu;
}
function keep_menu_out()
{
	/******************/
	ShowElement("select");
	/******************/
	menu_to_hide = open_menu;
	setTimeout(timer_hide_menu, 500);
}

function findPosX(obj)
{
	var curLeft = 0;
	if (obj.offsetParent)
	{
		do 
		{
			curLeft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
	else if (obj.x)
		curLeft += obj.x;
	
	return curLeft;	
}
function findPosY(obj)
{
	var curTop = 0;
	if (obj.offsetParent)
	{
		do 
		{
			curTop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	else if (obj.y)
		curTop += obj.y;
	
	return curTop;	
}
function positionMenu(menu, div, offX, offY)
{
	posY = findPosY(div);
	posX = findPosX(div);

	posY += offY+2;
	posX += offX;

    menu.style.top = posY + "px";
    menu.style.left = posX + "px";
	//alert(menu.style.top);    
}

function changePage(page)
{
	window.open(page, "_self");
}

function showImageList(listid, productid, persid, width, height)
{
    var params = "scrollbars=yes,width=" + width + ",height=" + height;
    window.open("ImageList.aspx?imagelistid=" + listid + "&productid=" + productid + "&persid=" + persid, "_blank", params);
}

function displayProductMedia(filename, w, h)
{
	if (w > 0 && h > 0)
		window.open("media/" + filename, "_blank", "width=" + w + ",height=" + h);
	else
		window.open("media/" + filename, "_blank");

}

function fillText(sel, arrName)
{
    if (sel.selectedIndex == 0)
        return;
        
    arr = eval(arrName);
    text = arr[sel.selectedIndex-1];
        
    var e = document.getElementById("aspnetForm").elements;
    var found = false;
    for (i=0; i<e.length; i++)
        if (e[i] == sel)
                found = true;
        else if (e[i].type == "textarea" && found)
		{
             e[i].value = text;
             return;
        }
            
}

function ControlValue(field)
{
	if (!field)
		// no pers
		return null;

	/*
	else if ((field.length && !field.type) || field.type == "radio") // radio button
	{
		for (j=0; j<field.length; j++)
		{
			if (field[j].checked)
			{
				ret = field[j].value;

				return ret;
			}
		}
	}
	*/
	else if (field.type == 'radio')
	    return field.checked ? field.value : null;

	else if (field.type == 'select-one') {

		var opt = field.options[field.selectedIndex];
	
		return opt.value;
		
	}
	else if (field.type == 'text') {
		return field.value;
	}
	else if (field.type == 'textarea')
	{
		// need to wrap at maximum size
		var output = "";
		var lines = field.value.split("\n");
		var mx = field.cols;
		
		for (var lineno=0;lineno<lines.length; lineno++)
		{
			var line = lines[lineno];
			if (line.length > mx)
			{
				var words = line.split(" ");
				var count = 0;
				for (var j=0; j<words.length; j++)
				{

					var word = words[j];
					if (count + word.length + 1 <= mx)	// word will fit on line
					{
						output = output + " " + word;
						count += word.length + 1;
					}
					else if (word.length > mx) // word byitself is too big
					{
						output += "\n" + word + "\n";
						count = 0;
					}
					else // word does not fit on this line
					{
						output += "\n" + word;
						count = word.length;
					}
				}
				output += "\n";
			}
			else
				output += line + "\n";
		}		
		return output;
	}
	else
	    return "";
}

function ShowPreview()
{
    if (Page_ClientValidate("") == false)
        return;

    var form = document.getElementById("aspnetForm");
    var e = form.elements;
    var q = "ProductPreview.aspx?productID=" + previewProductID + "&itemID=" + previewItemID;
    for (i=0; i<e.length; i++)
    {
        var n = e[i].name;
        var ix = n.indexOf("pers");
        if (ix >= 0)
        {
            var vname = n.substr(ix+5);//+5 because control name is $pers$pers3343
            var vvalue = ControlValue(e[i]);
            if (vvalue != null)
                q += "&" + vname + "=" + escape(vvalue);
        }
    }
    var params = "width=" + (previewWidth+20) + ",height=" + (previewHeight+100);
    window.open(q, "_blank", params);
    //alert(q);
}

function ShowPhotoCardPreview(orientation)
{
    var q = "PhotoCardPreview.aspx?o=" + orientation;
    var f = document.getElementById(persMappings["FONT"]);
    var c = document.getElementById(persMappings["COLOR"]);
    var v = document.getElementById(persMappings["GREETING"]);
    var b = document.getElementById(persMappings["CLOSING"]);
    
    f = ControlValue(f);
    c = ControlValue(c);
    v = ControlValue(v);
    b = ControlValue(b);

    q += "&f=" + escape(f);
    q += "&c=" + escape(c);
    q += "&v=" + escape(v);
    q += "&b=" + escape(b);
    
    q += "&r=" + Math.random();
    
    document.images["imgCardInside"].src = q;
    document.images["imgCardFront"].scrollIntoView(true);
    
}

function ShowProductImage(src)
{
	if (document.images)
	{
		var theImg = document.images["productImage"];
		if (theImg.filters)
		{
			theImg.filters[0].Apply();
			theImg.src = src;		
			theImg.filters[0].Play();			
		}
		else
			theImg.src = src;		
	}
}

function BoxDefault(box)
{
	if (box.value==box.defaultValue)
		box.value = "";
}

function CheckSearchBox(form)
{
	
	if (form.searchString.value.length == 0 || form.searchString.value == form.searchString.defaultValue)
	{
		alert("Please specify your search keywords.");
		return false;
	}
	else
		return true; 
}

divMore = null;
divExpand = null;
divExpandDivs = null;
divExpandIndex = 0;

function ShowMore(index)
{
	/*
	if (divMore != null)
	{
		divMore.style.display = '';
		divExpand.style.display = 'none';
	}
	*/

	divMore = document.getElementById("navMore" + index);
	divExpand = document.getElementById("navMoreExpanded" + index);
	
	divMore.style.display = 'none';
	divExpand.style.display = '';
	
	divExpandDivs = divExpand.children;
	divExpandIndex = 0;

	for (i=0; i<divExpandDivs.length; i++)
		divExpandDivs[i].style.display = "none";
	
	window.setTimeout(expandNavbar, 30);
}

function expandNavbar()
{
	divExpandDivs[divExpandIndex].style.display = "";
	divExpandIndex++;	
	
	if (divExpandIndex < divExpandDivs.length)
	{
		window.setTimeout(expandNavbar, 30);
	}
}


function PreviewAlsoAvailable(img)
{
	var dest = $get("imgAlsoAvailable");
	
	if (dest)
	{
		if (img.length == 0)
			img = "images/blank.gif";

		if (dest.filters)
		{
			dest.filters[0].Apply();
			dest.src = img;
			dest.filters[0].Play();
		}
		else
		{
			dest.src = img;
		}
	}
}

function openLargeImage(productID, width, height)
{
	window.open('ExtraLargeImage.aspx?productID=' + productID, '_blank', 'width='+width+',height='+height);
}

function ValidateImageUpload(source, args)
{

	var mailOption = source.optionMail ? document.getElementById(source.optionMail) : null;
	var uploadOption = source.optionUpload ? document.getElementById(source.optionUpload) : null;
	var keepOption = source.optionKeep ? document.getElementById(source.optionKeep) : null;
	var libraryOption = source.optionLibrary ? document.getElementById(source.optionLibrary) : null;
	var file = document.getElementById(source.fileUpload);
	
	if (mailOption && mailOption.checked)
		args.IsValid = true;
	else if (keepOption && keepOption.checked)
		args.IsValid = true;
	else if (libraryOption && libraryOption.checked)
		args.IsValid = true;
	else if (uploadOption.checked)
	{
		args.IsValid = file.value.length > 0;
	}
	else
		args.IsValid = false;
	
}


function ValidateCheckbox(source, args)
{
    var box = document.getElementById(source.checkboxID); 
    args.IsValid = box.checked;
}


function ValidateDate(source, args)
{
	//alert(source.required);
	var id = source.controlToValidate;
	var m = ValidatorGetValue(id + "_Month");
	var d = ValidatorGetValue(id + "_Day");
	var y = ValidatorGetValue(id + "_Year");
	
	//alert(m + " " + d + " " + y);
	if (m.length == 0 && d.length == 0 && y.length == 0)
	{
		if (source.required == "t")
		{
			source.errormessage = source.orgErrorMessage;
			args.IsValid = false;
		}
		else
			args.IsValid = true;
		return;
	}
	
	m = ValidatorConvert(m, "Integer", null);
	d = ValidatorConvert(d, "Integer", null);
	y = ValidatorConvert(y, "Integer", null);
	
	if (m == null || d == null || y == null)
	{
		args.IsValid = false;
		return;
	}
	
	date = new Date(y, m-1, d);
	if (isNaN(date))
	{
		args.IsValid = false;
		source.errormessage = "Invalid Date";
		return;
	}
	
	earliestDate = new Date(ValidatorConvert(source.earliestDate, "Date", {dateorder:"ymd"}));
	if (date < earliestDate)
	{
		source.errormessage = "Selected date is before earliest allowed date";
		args.IsValid = false;
		return;
	}
	
	var wd = date.getDay();
	
	if (wd == 0 && source.noallow0 == "t")
	{
		source.errormessage = "Sunday is not allowed";
		args.IsValid = false;
		return;
	}
	else if (wd == 1 && source.noallow1 == "t")
	{
		source.errormessage = "Monday is not allowed";
		args.IsValid = false;
		return;		
	}
	else if (wd == 2 && source.noallow2 == "t")
	{
		source.errormessage = "Tuesday is not allowed";
		args.IsValid = false;
		return;		
	}
	else if (wd == 3 && source.noallow3 == "t")
	{
		source.errormessage = "Wednesday is not allowed";
		args.IsValid = false;
		return;		
	}
	else if (wd == 4 && source.noallow4 == "t")
	{
		source.errormessage = "Thursday is not allowed";
		args.IsValid = false;
		return;		
	}
	else if (wd == 5 && source.noallow5 == "t")
	{
		source.errormessage = "Friday is not allowed";
		args.IsValid = false;
		return;		
	}
	else if (wd == 6 && source.noallow6 == "t")
	{
		source.errormessage = "Saturday is not allowed";
		args.IsValid = false;
		return;		
	}
	
	/*
	if (source.allowWeekends == "f")
	{
		var wd = date.getDay();
		
		if (wd == 0 || wd == 6)
		{
			source.errormessage = "Weekends are not allowed";
			args.IsValid = false;
		}
	}
	*/
	
	args.IsValid = true;
	
}

function ShowExpressShippingInfo()
{
	window.open("ExpressShipping.aspx", "_blank", "width=550,height=500,scrollbars=yes");
}

function noIntShip()
{
	window.open("InternationalItem.aspx", "_blank", "width=550,height=500,scrollbars=yes");
}

function staticPageWindow(pageID)
{
	window.open("StaticPageWindow.aspx?pageid=" + pageID, "_blank", "width=550,height=500,scrollbars=yes");
}

function writeUploadMessage()
{
	document.writeln("<div style='position:absolute;display:none;width:400px;height:180px;border:1px solid black;padding:2px;background-color:#FFFFCC;font-size:13px;color:green;font-weight:bold;' id='divUploadImage'>");
	document.writeln("<div style='text-align:center'>Image Upload in Progress:<hr noshade size=1 width=90%></div>");
	document.writeln("<div style='margin:10px'>Please wait while your image is uploaded.<br>Depending on your internet connection and image size, this might take couple minutes.<br>This message will go away once your image is uploaded.</div>");
	//document.writeln("<div style='text-align:center'><img src='images/progress.gif' border=0></div>");	
	document.writeln("</div>");
}

function showProgressMessage(btn, divID, ox, oy)
{
	var div = document.getElementById(divID);

	if (!div)
		return;
		
	div.style.left = findPosX(btn) + ox;
	div.style.top = findPosY(btn) + oy;
	div.style.display = "";	
}

function writePlaceOrderMessage()
{
	document.writeln("<div style='position:absolute;display:none;width:400px;height:180px;border:1px solid black;padding:2px;background-color:#FFFFCC;font-size:13px;color:green;font-weight:bold;' id='divPlaceOrderMessage'>");
	document.writeln("<div style='text-align:center'>Your Order is being completed:<hr noshade size=1 width=90%></div>");
	document.writeln("<div style='margin:10px'>Please wait while your order is being placed.<br>If you're using credit card, this operation might take a minute or two. DO NOT press Place Order button again and do not navigate away from this page.<br>This message will disappear once your order is completed.<br>Thank You.</div>");
	//document.writeln("<div style='text-align:center'><img src='images/progress.gif' border=0></div>");
	document.writeln("</div>");
}

function showInfoInNavbar(info)
{
	var nav = document.getElementById("navbarInfoRight");
	if (nav)
		nav.innerHTML = info;
}
function hideInfoInNavbar()
{
	var nav = document.getElementById("navbarInfoRight");
	if (nav)
		nav.innerHTML = "";
}

function dontLeave()
{
	if (event && event.clientY && event.clientY < -10000) 
		window.open("DontLeave.aspx", "_blank", "width=600,height=460,scrollbars=yes");
}

function ShowVerisignInfo()
{
	window.open("https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=WWW.PERSONALIZATIONMALL.COM&lang=en", "_blank", "width=550,height=470");
}

// navbar specials
navbarSpecials = new Array();
navbarSpecialIndex = 0;
navbarSpecialTimeout = 5000;
function addNavbarSpecial(productName,  altTag, productURL, imageURL)
{
    var s = {
        productName: productName,
        productURL: productURL,
        altTag: altTag,
        imageURL: imageURL
       };
    navbarSpecials[navbarSpecials.length] = s;
    return s;
}
function initNavbarSpecial(index)
{
    navbarSpecialIndex = index;
    showNavbarSpecial();
    
    window.setTimeout(rotateNavbarSpecial, navbarSpecialTimeout);
    
}
function rotateNavbarSpecial()
{
    navbarSpecialIndex++;
    if (navbarSpecialIndex >= navbarSpecials.length)
        navbarSpecialIndex = 0;
        
    showNavbarSpecial();
    window.setTimeout(rotateNavbarSpecial, navbarSpecialTimeout);
}
function showNavbarSpecial()
{
    var s = navbarSpecials[navbarSpecialIndex];
    var sContainer = document.getElementById("divSpecials");
    if (sContainer.filters && navbarSpecialIndex > 0)
        sContainer.filters[0].Apply();
    
    document.getElementById("hrefSpecialImage").href = s.productURL;
    document.getElementById("imgSpecialImage").src = s.imageURL;
    document.getElementById("imgSpecialImage").alt = s.altTag;
    document.getElementById("hrefSpecialName").innerHTML = s.productName;
    document.getElementById("hrefSpecialName").href = s.productURL;
    
    if (sContainer.filters && navbarSpecialIndex > 0)    
        sContainer.filters[0].Play();
}

// home alt. image script
homeImages = new Array();
homeImageIndex = 0;
homeImageTimeout = 5000;
homeImageRound = 0;
homeImageID = null
function addHomeImage(src)
{
    homeImages[homeImages.length] = src;
    return src;
}
function initHomeImages(imgID)
{
    homeImageID = imgID;
    homeImageIndex = 0;
    showHomeImage();
    homeImageRound = 1;
    
    window.setTimeout(rotateHomeImages, homeImageTimeout);
    
}
function rotateHomeImages()
{
    homeImageIndex++;
    if (homeImageIndex >= homeImages.length)
    {
        homeImageIndex = 0;
        homeImageRound++;
    }
        
    showHomeImage();
    window.setTimeout(rotateHomeImages, homeImageTimeout);
}
function showHomeImage()
{
    var s = homeImages[homeImageIndex];
    var sContainer = document.getElementById(homeImageID);
    if (sContainer.filters && homeImageRound > 0)
        sContainer.filters[0].Apply();
    
    sContainer.src = "images/" + s;
    
    if (sContainer.filters && homeImageRound > 0)    
        sContainer.filters[0].Play();
}

function isDigitOrLetter(ch)
{
	return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z');
}

function checkGiftCardNumber(box)
{
	var r = "";
	var g = box.value.toUpperCase();
	var digits = 0;
	
	for (i=0; i<g.length; i++)
	{
		var ch = g.charAt(i);
		
		if (isDigitOrLetter(ch))
		{
			r += ch;
			digits++;
			if (digits >= 12)
				break;
			
			if (digits % 4 == 0)
				r+='-';
		}
	}
	
	box.value = r;
}

function textboxRemainingChars_Display(textbox, divID)
{
	var div = $get(divID);
	if (div)
	{
		if (div.style.display == "none")
			div.style.display = "";
			
		var r = textbox.maxLength - textbox.value.length;
		div.innerHTML = r + " characters left";
		
	}

}

function SetControlValue(field, value)
{
	if (!field)
		// no pers
		return null;
	/*
	else if (field.type == 'radio')
	    return field.checked ? field.value : null;
	*/
	else if (field.type == 'select-one') 
	{
		for (i=0; i<field.options.length; i++)
			if (field.options[i].value == value)
			{
				field.selectedIndex = i;
				return;
			}	
	}
	else if (field.type == 'text' || field.type == 'textarea') 
		field.value = value;

}



function dumpObject(obj)
{
	var str = "";
	for (var f in obj)
	{
		var v = obj[f];
		str += f + ": " + v + "\n";
	}
	alert(str);
}


//*********************
//隐藏元素
function HideElement(strElementTagName){
	if(isIE){
		try{
			for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
				var objTemp = window.document.all.tags(strElementTagName)[i];
				objTemp.style.visibility = "hidden";
			}
		}catch(e){
			alert(e.message);
		}
	}
}

//显示元素
function ShowElement(strElementTagName){
	if(isIE){
		try{
			for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
				var objTemp = window.document.all.tags(strElementTagName)[i];
				objTemp.style.visibility = "visible";
			}
		}catch(e){
			alert(e.message);
		}
	}
}

/****
* 分站点记忆功能
*/
function memoryCity(){
	var city = "";
	if(window.document.all.isMemoryCity.checked){
		city = window.document.all.isMemoryCity.value;
	}
	var url="/process/website/include/memoryCity.jsp?city="+city+"&math="+Math.random();
	if (window.XMLHttpRequest) {
	   reqMemoryCity = new XMLHttpRequest();
	   reqMemoryCity.open("GET", url, true);
	   reqMemoryCity.onreadystatechange = memoryCityCallback;
	   reqMemoryCity.send(null);
	} else if (window.ActiveXObject) {
	   reqMemoryCity = new ActiveXObject("Microsoft.XMLHTTP");
	   reqMemoryCity.open("GET", url, true);
	   reqMemoryCity.onreadystatechange = memoryCityCallback;
	   reqMemoryCity.send();
	}
}

function memoryCityCallback(){
    if (reqMemoryCity.readyState == 4) {
	}
}