// JavaScript Document
_proLink = new Array("ProCartPrice.html","ProEvlope.html","ProNCRPrice.html","ProEvPrice.html","ProEPackage.html","ProCalCardPrice.html","ExpressPrice.html","ProTransportPrice.html");
_productCategory = [];
function ajxpro(){
	ajaxService.showProductCateogry(function(data){
		if(data){
			_for(data,function(i){
				_productCategory.push(data[i].alias);
				_productCategory.push('<div class=\"menuSubType\">'+data[i].categoryname+'</div>');
			});
			ajaxService.showProductWeb(function(data){handler(data);});
		}
	});
};
function handler(){
	_src = arguments[0];
	var para = "";
	var arr = new Array();
	var arrnameurl = new Array();
	var temp = 0;
	_str = "";
	_str2 = "";
	_for(_src,function(i){
		if(_src[i]!=temp){
			temp=_src[i].productid;
			para +=temp+",";
			arr.push(temp);
			arrnameurl.push(_src[i].productaliasofurl);
		}
		_str += "<div class=\"menuOver1\" id=\""+_src[i].productid+"\"> <a href=\"#\" onClick=\"setsessionandhref('/productIntroduction_"+_src[i].productaliasofurl+"_"+_src[i].productid+".html')\" >&nbsp;>&nbsp;"+_src[i].productname+"</a></div>";
		if(_src[i].productid==31)
		_str2 += "<div class=\"menuOver\" style='display:none;'> <a href=\"#\" onClick=\"setsessionandhref('/"+_proLink[i]+"')\" >&nbsp;>&nbsp;"+_src[i].productname+_price+"</a></div>";
		else _str2 += "<div class=\"menuOver\"> <a href=\"#\" onClick=\"setsessionandhref('/"+_proLink[i]+"')\" >&nbsp;>&nbsp;"+_src[i].productname+_price+"</a></div>";
	});
	if(!_empty(_str)){
		_addCss("menuItem2","menuStyle");
		_str += "<div class=\"menuOver\"></div>";
		_html("menuItem2",_str);
	}
	if(!_empty(_str2)){
		_addCss("menuItem3","menuStyle");
		_str2 += "<div class=\"menuOver\"> <a href=\"#\" onClick=\"setsessionandhref('/ExpressPrice.html')\">&nbsp;>&nbsp;"+_express+_price+"</a></div>";
		_str2 += "<div class=\"menuOver\"> <a href=\"#\" onClick=\"setsessionandhref('/ProTransportPrice.html')\">&nbsp;>&nbsp;"+_transport+_price+"</a></div>";
		_str2 += "<div class=\"menuOver\"></div>";
		_html("menuItem3",_str2);
	}
	initShield();
	inittop();
	ajaxService.showSelectProductWeb(para,function(data){
		if(data){
			_for(arr,function(i){
				if(arr[i]!=3){
					_add("item","<div id=\""+arr[i]+"_item\" class=\"menuSubFr itemStyle hidden\"></div>");
				}
			});
			var str1="";
			var str2="";
			var str4="";
			var str3="";
			_for(data,function(i){
				var temp = data[i];
				ss=temp.code==null?temp.stylename:temp.code+"&nbsp;&nbsp;-&nbsp;&nbsp;"+temp.stylename;
				var productaliasofurl="";
				_for(arr,function(j){
					if(arr[j]==temp.productid){
						productaliasofurl=arrnameurl[j];
					}
				});
				var designtypestr="";
				if(temp.hastransparencyareaflag==1){
				   designtypestr="simple";
				}
				if(temp.productid==3){
					switch(temp.categoryalias){///template_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+".html
						case 'category_homecard'://templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"__hor_9999_display_18_1.html
							if(str1 == "") str1 += parsePre(temp.categoryalias);
							str1+="<div class=\"menuSubTypeS\"><a href=\"javascript:setsessionandhref('/templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"_"+designtypestr+"_hor_9999_display_18_1.html')\">"+ss+"</a></div>";
							
							break;
						case 'category_multifunctioncard'://templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"__hor_9999_display_18_1.html
							if(str2 == "") str2 += parsePre(temp.categoryalias);
							str2+="<div class=\"menuSubTypeS\"><a href=\"javascript:setsessionandhref('/templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"_"+designtypestr+"_hor_9999_display_18_1.html')\">"+ss+"</a></div>";
							
							break;
						case 'category_festivalcard':
							if(str4 == "") str4 += parsePre(temp.categoryalias);
							str4+="<div class=\"menuSubTypeS\"><a href=\"javascript:setsessionandhref('/templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"_"+designtypestr+"_hor_9999_display_18_1.html')\">"+ss+"</a></div>";
							break;
						case 'category_businesscard':
							if(str3 == "") str3 += parsePre(temp.categoryalias);
							str3+="<div class=\"menuSubTypeS\"><a href=\"javascript:setsessionandhref('/templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"_"+designtypestr+"_hor_9999_display_18_1.html')\">"+ss+"</a></div>";
							break;
					}
				} else {
					_add(temp.productid+"_item","<div class=\"menuSubTypeS\"><a href=\"javascript:setsessionandhref('/templatelist_"+productaliasofurl+"_"+temp.productid+"_"+temp.styleid+"_"+designtypestr+"_hor_9999_display_18_1.html')\">"+ss+"</a></div>");
				}
			});
			if(_contain(3,arr)){
				_add("item","<div id=\"3_item\" class=\"menuSubFr itemStyle hidden\">"+str1+str2+str4+str3+"</div>");
			}
			_for(arr,function(i){
				_$(arr[i]+"_item").bind("mouseleave",function(event){
					if(event.pageX<=parseInt(_getCssVal(this,"left"))){
						if(event.pageY<=parseInt(_getCssVal("menuItem2","top"))+parseInt(_getCssVal(arr[0],"height"))*(arr.length+1)&&event.pageY>=parseInt(_getCssVal("menuItem2","top"))){
							_removeCss(arr[i],"menuitemshow");
							_addCss(this,"hidden");
							closeShield(false);
						} else {
							_$("menuItem2").hide();
							_removeCss("a.m2","menusshow");
							_removeCss(arr[i],"menuitemshow");
							_addCss(this,"hidden");
							closeShield(false);
						}
					} else {
						_$("menuItem2").hide();
						_removeCss("a.m2","menusshow");
						_removeCss(arr[i],"menuitemshow");
						_addCss(this,"hidden");
						closeShield(false);
					}
				});
				_$(arr[i]).bind({mouseenter:function(){
					_setCssVal(arr[i]+"_item","left",(_position(this).x+parseInt(_getCssVal(this,"width"))-4)+"px");
					_setCssVal(arr[i]+"_item","top",_position(this).y+"px");
					_removeCss(arr[i]+"_item","hidden");
					showShield(_$(arr[i]+"_item").css("width"),_$(arr[i]+"_item").height()+13,(_position(arr[i]+"_item").x),_position(this).y+"px",false);
				},mouseleave:function(event){
					if(event.pageX<=parseInt(_getCssVal("menuItem2","left"))){
						_removeCss(arr[i]+"_item","menuitemshow");
						_addCss(arr[i]+"_item","hidden");
						closeShield(false);
//						_removeCss("a.m2","menusshow");
//						_$("menuItem2").hide();
					} else if(event.pageX>=_position(this).x+parseInt(_getCssVal(this,"width"))-4) {
						_addCss(arr[i],"menuitemshow");
					} else {
						_removeCss(arr[i],"menuitemshow");
						_addCss(arr[i]+"_item","hidden");
						closeShield(false);
					}
				}});
			});
			_$("menuItem2").bind("mouseleave",function(event){
				if(event.pageY>parseInt(_getCssVal("menuItem2","top"))+parseInt(_getCssVal(arr[0],"height"))*(arr.length+1)) {
					_removeCss("a.m2","menusshow");_$(this).hide();
					closeShield(true);
				} else if(event.pageX<parseInt(_getCssVal("menuItem2","left"))){
					_removeCss("a.m2","menusshow");_$(this).hide();
					closeShield(true);
				} else if(event.pageY<=parseInt(_getCssVal("menuItem2","top"))){
					_removeCss("a.m2","menusshow");_$(this).hide();
					closeShield(true);
				}
			});
		}
	});
	_removeCss("item","hidden");
}

function parsePre(input){
	var temp = "";
	if(input != ""){
		_for(_productCategory,function(i){
			if(_productCategory[i] == input){
				temp = _productCategory[i+1];
				return;
			}
		});
	}
	return temp;
}

var _id=0;
function menuOver(id){
	if(parseInt(id)>0) {
		if(_id != id) {
			_$("menuItem"+_id).css("display","none");
			_$("menuItem"+id).css("display","none");
		}
		_id = id;
		var menuObj = _$("menuItem"+id);
		_loc = _position("div.m"+id).x-(parseInt(menuObj.css("width"))/5);
		menuObj.css("left",_loc);
		menuObj.show(700);
	}
}
function menuItemHiden(){
//	if(_id>0){
//		_$("menuItem"+_id).hide();
//	}
}

function imgEffect(id)
{
	/* var imgObj = $("#"+id);	 
	imgObj.fadeTo(200, 0.26);
	imgObj.fadeTo(200, 0.98);
	imgObj.css({"background":"red","opacity":"0.5","cursor":"pointer"})*/
}
function varEffect(){	
    jq(".NewPro").fadeTo(600,0.25);
	jq(".NewPro").fadeTo(600,0.95);
}
function helpWin(){
	var content=jq("div.showHelp");
	jq("#help2").click(function(){content.show(500); });
}
function closeWin(){
	var content=jq("div.showHelp");
    var closes=jq("#hide");
	closes.click(function(){content.hide(500); });
}
function inittop(){
	var arr = new Array();
	for(var i=1;i<6;i++){
		arr.push(_position("a.m"+i));
	}
	addEvent(arr);
}
function addEvent(){
	var arr = arguments[0]
	_for(arr,function(i){
		var menuSRC = _$("a.m"+(i+1));
		var menuItem = _$("menuItem"+(i+1));
		if(i!=1)
			menuItem.bind("mouseleave",function(){menuItem.hide();_removeCss(menuSRC,"menusshow");closeShield(true);});
		menuSRC.bind({mouseenter:function(){
			var left = arr[i].x-(parseInt(menuItem.css("width")))/3;
			menuItem.css("left",left+"px");
			menuItem.show();
			_addCss(menuSRC,"menusshow");
			showShield(menuItem.css("width"),menuItem.height()+2,left,menuItem.css("top"),true);
//			setTimeout("menuShow("+arr[i].x+","+i+","+current+")",10);
		},mouseleave:function(event){
//			setTimeout("menuHide("+event.pageY+","+i+")",10);
			if(event.pageY<parseInt(menuItem.css("top"))){
				menuItem.hide();
				closeShield(true);
				_removeCss(menuSRC,"menusshow");
			}
		}});
	});
}
function initShield(){
	var str = "<div id=\"shield\" class=\"itemShield\"><iframe src=\"common/null.jsp\" class=\"whiteIframe\" frameborder=\"0\" align=\"top\" scrolling=\"no\" id=\"wiframe\"></iframe></div>";
	var str2 = "<div id=\"shield2\" class=\"itemShield\"><iframe src=\"common/null.jsp\" class=\"whiteIframe\" frameborder=\"0\" align=\"top\" scrolling=\"no\" id=\"wiframe2\"></iframe></div>";
	_add("item",str);
	_add("item",str2);
}
function showShield(){
//	arguments:1.with 2.height 3.left 4.top 5.true:shield,false:shield2
	temp = (parseInt(arguments[0])+2)+"px";
	var obj = arguments[4]?"shield":"shield2";
	var obj2 = arguments[4]?"wiframe":"wiframe2";
	var SRC = _$(obj);
	var IFRAME = _$(obj2);
	IFRAME.css({"width":(temp),"height":(arguments[1])});
	SRC.css({"width":(temp),"height":(arguments[1])+"px","left":arguments[2]+"px","top":arguments[3]});
	SRC.show();
}
function closeShield(){
	var obj = arguments[0]?"shield":"shield2";
	_$(obj).hide();
}
function menuShow(){
	if(arguments[2]>0){
		_$("menuItem"+arguments[2]).hide();
	}
	arguments[2] = arguments[1]+1;
	var temp = _$("menuItem"+(arguments[1]+1))
	var left = arguments[0]-(parseInt(temp.css("width"))/5);
	temp.css("left",left+"px");
	temp.show(700);
}
function menuHide(){
	var temp = _$("menuItem"+(arguments[1]+1))
	if(arguments[0]<parseInt(temp.css("top"))){
		temp.hide();
	}
}
function scrollToLeft(){
  var iframewidth=document.getElementById("iframelasttemplate").width;
  if(iframelasttemplate.document.body.scrollWidth<=iframewidth){
     document.getElementById("scrollbuttonleft").style.cursor="default";
     document.getElementById("scrollbuttonright").style.cursor="default";
  }else{
	  if(iframelasttemplate.document.body.scrollLeft-137>0){
	     iframelasttemplate.document.body.scrollLeft=iframelasttemplate.document.body.scrollLeft-137;
	     document.getElementById("scrollbuttonleft").style.cursor="pointer";
     	 document.getElementById("scrollbuttonright").style.cursor="pointer";
	  }else{ 
	     iframelasttemplate.document.body.scrollLeft=0;
	     document.getElementById("scrollbuttonleft").style.cursor="default";
	     document.getElementById("scrollbuttonright").style.cursor="pointer";
	  }
  }
}
function scrollToRight(){
  var iframewidth=document.getElementById("iframelasttemplate").width;
  if(iframelasttemplate.document.body.scrollWidth<=iframewidth){
     document.getElementById("scrollbuttonleft").style.cursor="default";
     document.getElementById("scrollbuttonright").style.cursor="pointer";
  }else{
	  if(iframelasttemplate.document.body.scrollLeft+137<iframelasttemplate.document.body.scrollWidth){
	     iframelasttemplate.document.body.scrollLeft=iframelasttemplate.document.body.scrollLeft+137;
	     document.getElementById("scrollbuttonleft").style.cursor="pointer";
     	 document.getElementById("scrollbuttonright").style.cursor="pointer";
	  }else{ 
	     iframelasttemplate.document.body.scrollLeft=iframelasttemplate.document.body.scrollWidth;
	     document.getElementById("scrollbuttonleft").style.cursor="pointer";
     	 document.getElementById("scrollbuttonright").style.cursor="default";
	  }
  }
}

function gocharge(){
	_hiddenError();
	var amount = document.getElementById("amount");
	var paytypeid = document.getElementById("paytypeid");
	var cointypeid = document.getElementById("cointypeid");
	var mobile = document.getElementById("mobile");
	var cid = document.getElementById("cid");
	if(amount.value<38){
		_html("errorMSG",_amount);
		_showError(amount);
		return;
	} else{
		if(!_isMoney(amount.value)){
			_html("errorMSG",_amounterror);
			_showError(amount);
			return ;
		}
	}
	if(mobile.value){
		if(!_isMobile(mobile.value)){
			_html("errorMSG",_mobile+_syntax);
			_showError(mobile);
			return;
		}
	} else {
		_html("errorMSG",_plsEnter+_mobile);
		_showError(mobile);
		return;
	}
	if(paytypeid.value==0){
		_html("errorMSG",_plsSelect+_paytype);
		_showError(paytypeid);
		return;
	}
	if(cointypeid.value==0){
		_html("errorMSG",_plsSelect+_cointype);
		_showError(cointypeid);
		return;
	}
	if(cid){
		if(cid.value<1){
			_html("errorMSG",_unknowError);
			_showError(amount);
			return;
		}
	} else {
		_html("errorMSG",_unknowError);
		_showError(amount);
		return;
	}
	checksubmitdata();
}

function goPay(){
	var nowbalance = document.getElementById("nowbalance").value;
	var amount = document.getElementById("amount").value;
	var paymenttype = document.getElementById("paymenttype").value;
	var saveorderbutton = document.getElementById("resetButton");
	if(amount<=0){
		_html("errorMSG",_amountNotEnough);
		_showError(saveorderbutton);
		return ;
	}
	if(paymenttype<=0){
		_html("errorMSG",_unknowError);
		_showError(saveorderbutton);
		return ;
	}
	if(nowbalance<=0){
		_html("errorMSG",_amountNotEnough);
		_showError(saveorderbutton);
		return ;
	}
	if((nowbalance-amount)<0){
		_html("errorMSG",_amountNotEnough);
		_showError(saveorderbutton);
		return ;
	} else {
		document.prepayForm.submit();
	}
}

function getCoinName(val,val2){
	ajaxService.getCoinType(val,function(data){
		if(data){_html(val2+"_"+val,data.coinnameen);}
	});
}

function showlive800(){
	var timestamp=new Date().getTime()
	window.open("http://chat10.live800.com/live800/chatClient/chatbox.jsp?companyID=84466&configID=140811&jid=8926419243&enterurl=http%3A%2F%2Fwww%2Edesign%2Deasy%2Ecom%2Flive800%2Ejsp%3Ftype%3Dleft&timestamp="+timestamp,'','top=180,left=180,width=560,height=430,scrollbars=yes');
}

function replace(strSource,strFrom,strTo){
    var pattern,re;
	var s = strSource;
	pattern = new RegExp(strFrom,"ig");
	re = s.replace(pattern,strTo);
    return re;
}

function ChkStrreg(str)
{
	str=replace(str,"'","＇");
	str=replace(str,"\"","＂");
	str=replace(str,"#","＃");
	str=replace(str,"&", "＆");
	str=replace(str,"<","＜");
	str=replace(str,">","＞");
	str=replace(str,";","；");
	return str;
}

function isIE(){
  var systemtype=navigator.appName;
  if(systemtype.indexOf("Microsoft Internet Explorer")!=-1){
	  return true;
  }else return false;
}
function fncSubmitSearch(){
	var searchV = document.getElementById("pSearch").value;
	if(jQuery.trim(searchV)==""||jQuery.trim(searchV)=="您可輸入模板編號"){
		alert("请输入要搜索的模板编号！");
		return;
	}
	//window.location = "searchProduct_"+searchV+".html";
	window.location = "/searchTemplate_18_0_"+searchV+".html";
	//window.location = "/search_18_0_"+searchV+".html";
}
function hiddensdinfo(divid){
	var searchV = document.getElementById(divid);
	if(searchV.style.display!="none"){
		searchV.style.display="none";
		var table=document.getElementById("st");
		while(table.rows.length>0){
			table.removeChild(table.firstChild);
		}
	}
}
function showsdinfo(obj,divid){
	var keyword=obj.value;
	var searchV = document.getElementById(divid);
	if(searchV.style.display=="none"){
		var l=obj.offsetLeft;
		var t=obj.offsetTop;
		 while((obj=obj.offsetParent)){
			l+=obj.offsetLeft;
			t+=obj.offsetTop;
		  }
		  var systemtype=navigator.appName;
		  if(systemtype.indexOf("Microsoft Internet Explorer")!=-1){
			searchV.style.top=(t+22)+"px";
			searchV.style.left=(l)+"px";
		  }else{
			searchV.style.top=(t+22)+"px";
			searchV.style.left=(l)+"px";
		  }
		  searchV.style.display=""; 
	}
	ajaxService.getKeyword(keyword,divid,writesdinfo);
}
function writesdinfo(data){
	var searchV = document.getElementById(data.sddivid);
	var keylist=data.keylist;
	if(keylist.length>0){
		var table=document.getElementById("st");
		while(table.rows.length>0){
			table.removeChild(table.firstChild);
		}
		for(var i=0;i<keylist.length;i++){
			var content = eval("keylist["+i+"].content");
			var content_old = eval("keylist["+i+"].content_old");
			if(content.length<=0)content=content_old;
			var searchcount = eval("keylist["+i+"].searchcount");
			var trbutton=table.insertRow(table.rows.length);
			trbutton.className="keybg";
			trbutton.id="key"+i;
			trbutton.setAttribute("content_old",content_old);
			trbutton.onmouseover=function(){
				changeKeywordstyle(this);
			};
			trbutton.onmouseout=function(){
				changeKeywordstyleback(this);
			};
			trbutton.onclick=function(){
				document.getElementById("pSearch").value=this.getAttribute("content_old");
				hiddensdinfo(data.sddivid);
			};
			trbutton.insertCell(0);
			trbutton.insertCell(1);
			trbutton.cells[0].height="20";
			trbutton.cells[1].width="40";
			trbutton.align="left";
			trbutton.cells[0].innerHTML=content;
			trbutton.cells[0].align="left";
			trbutton.cells[1].innerHTML="&nbsp;&nbsp;"+searchcount+"";
			trbutton.cells[1].align="right";
			//alert(content+":"+searchcount);
		}
		var keywidth = document.getElementById("st").scrollWidth;
		if(keywidth<=166)keywidth=166;
		searchV.style.width=keywidth+"px";
	}else{
		hiddensdinfo(data.sddivid);
		
	}
}
//var trclass="";
function changeKeywordstyle(o){
	//trclass=o.className;
	o.className="keybgover";

	//o.bgColor="#A7DBEF";
}
function changeKeywordstyleback(o){
	  o.className="keybg";
}

function loadDesignerShowPic(src){
	var target = jQuery("#" + src);
 	if(target.find("img").length == 1){
 		target.find("img").remove();
 		target.removeClass("designerShow");
 		loadJsonASYN(
 			"designerAsyn.loadShowPic_r.shtml",
 			{maxSize : 3,orderBy:1},
 			function(data){
 				if(data && data.jsonData.length > 0){
 					var jsonData = data.jsonData;
 					var path = data.path;
 					var preFolder_1 = "/order/";
					var preFolder_2 = "/DESIGNER_PDF_minipic/";
					for(var i=0;i<jsonData.length;i++){
						var str = '<img onclick="goShowPic('+jsonData[i].tid+')" class="showImage" src="'+ path + preFolder_1 + jsonData[i].palais + preFolder_2 + jsonData[i].uid + "/" + jsonData[i].pre + '_1.jpg">';
						target.append(str);
					}
 				}
 			}
 		);
 	}
}

function goShowPic(postId){
	if(postId > 0){
		loadJsonASYN("designerAsyn.updateCount_r.shtml",{postId : postId,type : 1},function(data){
			self.location.href = "designer.loadTemplateDetail_" + postId + ".shtml";
		});
	}
}

function loadJsonASYN(url,data,result){
	if(url){
		if(data){
			data.random = Math.random();
		} else {
			data = {random:Math.random()};
		}
		jQuery.getJSON(
			url,
			data,
			function(data){
				result(data);
			}
		);
	}
}
