// JavaScript Document
var login='<table width="100%" border="0" cellpadding="6" cellspacing="0"><form name="UserLogin" id="UserLogin"onSubmit="return false;" style="margin:0px"><tr><td colspan="2" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="20"><img src="http://www.jewelchina.com/MemberCenter/images/login.gif" width="15" height="16"/></td><td style="color:#000000">此产品已被加密，请输入密码，如没有密码，请联系该商家！</td></tr></table></td></tr><tr><td width="30%"><font style="color:#000000">查看密码：</font></td><td><input name="ProductPassword" type="password" id="ProductPassword" style="height:20px; width:120px" maxlength="16" /></td></tr><tr><td colspan="2" align="center"><input type="submit" name="Submit" id="LoginBtn" value="查看"  style="width:80px;height:25px;" onClick="LookU();"/><input type="hidden" value="" id="ProductId"></td></tr></form></table>';
	var bgDiv=null;
var alertFram=null;
var _width=0;
var _height=0;
function msgBox(title,msg,width,height,skin){
      //动态创建一个DIV
	  if(document.getElementById('alertFram')!=null){
	      document.body.removeChild(alertFram);
	  };
	  hidenAllSelect();
	  _width=width;
	  _height=height;
	  var scrollPos; 
      if (typeof window.pageYOffset != 'undefined') { 
       scrollPos = window.pageYOffset; 
      } 
     else if (typeof document.compatMode != 'undefined' && 
        document.compatMode != 'BackCompat') { 
        scrollPos = document.documentElement.scrollTop; 
     } 
    else if (typeof document.body != 'undefined') { 
       scrollPos = document.body.scrollTop; 
    }
      LeftPosition=(document.body.clientWidth / 2) - (width / 2)   
      TopPosition=(scrollPos+window.screen.availHeight/2 ) - (height / 2)-100;
	  //alert(window.screen.availHeight);
      alertFram = document.createElement("DIV");
	  var bdy=document.documentElement;
	  var h=bdy.scrollHeight>bdy.clientHeight?bdy.scrollHeight:bdy.clientHeight;
      var w=bdy.scrollWidth>bdy.clientWidth?bdy.scrollWidth:bdy.clientWidth;
	  alertFram.id="alertFram";
      alertFram.style.position = "absolute";
	  alertFram.style.background='#666666';
	  alertFram.style.zIndex = "10001";
	  alertFram.style.width = width+'px';
      alertFram.style.height = height+'px';
	  alertFram.style.paddingRight=3+'px';
	  alertFram.style.paddingBottom=2+'px';
	  //设置位置
	  alertFram.style.left=LeftPosition;
      alertFram.style.top=TopPosition;
	  var htmls=null;
	  if(typeof(skin)=="undefined"){
	  htmls='<div  style="background:#FFFFFF;width:'+width+'px;height:'+height+'px;border:#E4549D 1px solid;"><ul style="width:'+width+'px;height:26px;text-align:right;padding-top:2px;background-image:url(http://baby.jewelchina.com/images/bari.gif);margin:0px;color:#ffffff"><li style="float:left;width:70%;list-style-type:none;height:20px;text-align:left;line-height:20px;color:#FFFFFF;font-weight:bold;">'+title+'</li><li style="float:left;width:30%;list-style-type:none;height:20px;text-align:right"><img src="http://www.jewelchina.com/MemberCenter/images/B_close.gif"  alt="关闭" style="cursor:hand;" onclick="exit();" align="absmiddle"></li></ul><div>'+msg+' </div></div>';
	  }
	  else{
		  htmls=msg;
	  }
	  alertFram.innerHTML = htmls;
	  document.body.appendChild(alertFram);
	  if(!bgDiv ){
	  bgDiv = document.createElement("DIV");
	  bgDiv.id="BgDiv"
	  bgDiv.oncontextmenu='self.event.returnValue=false'
      bgDiv.style.backgroundColor="transparent";
      bgDiv.style.overflow="hidden";
	  bgDiv.style.position="absolute";
	  bgDiv.style.left="0";
	  bgDiv.style. top="0";
	  bgDiv.style. width="100%";
	  bgDiv.style. height=(scrollPos+h)+'px';
	  bgDiv.style. backgroundColor="#333333";
	  bgDiv.style. filter="blendTrans(duration=1) alpha(opacity=80)";
      document.body.appendChild(bgDiv);
      bgDiv.filters.blendTrans.apply();
      bgDiv.style.visibility="visible";
      bgDiv.filters.blendTrans.play();
	  }
	  
	  
}
//关闭窗口
function exit(){
       document.body.removeChild(alertFram);
	   document.body.removeChild(bgDiv);
	   bgDiv=null;
	   showAllSelect()
   }
function resize(){
	 
      if (typeof window.pageYOffset != 'undefined') { 
       scrollPos = window.pageYOffset; 
      } 
     else if (typeof document.compatMode != 'undefined' && 
        document.compatMode != 'BackCompat') { 
        scrollPos = document.documentElement.scrollTop; 
     } 
    else if (typeof document.body != 'undefined') { 
       scrollPos = document.body.scrollTop; 
    }
	 var bdy=document.documentElement;
	 var w=bdy.scrollWidth>bdy.clientWidth?bdy.scrollWidth:bdy.clientWidth;
	 var h=bdy.scrollHeight>bdy.clientHeight?bdy.scrollHeight:bdy.clientHeight;
	 LeftPosition=(w-_width)/2 ;
	 //alert(LeftPosition);
     TopPosition=(scrollPos+window.screen.availHeight/2 ) - (_height)-100;
	  
	  //设置位置
	  //alert(TopPosition);
       document.getElementById('alertFram').style.top=TopPosition;
	   document.getElementById('alertFram').style.left=LeftPosition;
	   document.getElementById('BgDiv').style.height=scrollPos+h;
}
function hidenAllSelect(){
	var selects=document.getElementsByTagName("select");
	//alert(selects);
	for(i=0;i<selects.length;i++){
		selects[i].style.display="none";
	}
}
function showAllSelect(){
	var selects=document.getElementsByTagName("select");
	//alert(selects);
	for(i=0;i<selects.length;i++){
		selects[i].style.display="";
	}
}
function getCookie(Name)
{
   var search = Name + "=";
   var returnvalue = "";
   if (document.cookie.length > 0) 
   {
      offset = document.cookie.indexOf(search);
   if (offset != -1)
   { 
   offset += search.length;
         end = document.cookie.indexOf(";", offset); 
   if (end == -1)
            end = document.cookie.length;
         returnvalue=unescape(document.cookie.substring(offset,end));
       }
    }
    return returnvalue;
}
//ajax
function AJAXCALL(url,handleResponse,param){
	var isXML=false;//false:html or true:xml
    var isCache=false;//false:no-cache or true:cache
    var method="POST";//GET or POST
	var attach="";
	if(param){
	   re = / /g; 
	   param=param.replace(re, "");
	   var tmp=param.split(",");//extends param array
	   for(var i=0;i<tmp.length;i++){
		      var pa=tmp[i].substr(0,3);
			  var ct=tmp[i].split("=")[1];
		      switch (pa){
				  case "isX":
				  if(ct=="true"){
					  isXML= true; 
				  }else{
					  isXML= false; 
				  }
				  break;
				  case "isC":
				  if(ct=="true"){
					  isCache= true; 
				  }else{
					  isCache= false; 
				  }
				  break;
				  case "met":
				  method=ct;
				  break;
				  case "att":
				  attach=ct;
				  break;
			  }
	   }	
	}
	if(!isCache){
		var t=new Date().getTime();
		if(url.indexOf("?")>0){
	        url+="&t="+t;
		}else{
			url+="?t="+t;
		}
	}	
	var postdata=null;
	if(method=="POST"){
		purl=url.split("?");
		url=purl[0];
		postdata=purl[1];//must urlencoded first
	}
	RequestHTTP(url,handleResponse,method,isXML,postdata,attach);
}

function AJAXFORM(formID,handleResponse,param){
var isXML=false;//false:html or true:xml
var attach="";
if(param){
	   re = / /g; 
	   param=param.replace(re, "");
	   var tmp=param.split(",");//extends param array
	   for(var i=0;i<tmp.length;i++){
		      var pa=tmp[i].substr(0,3);
			  var ct=tmp[i].split("=")[1];
		      switch (pa){
				  case "isX":
				  if(ct=="true"){
					  isXML= true; 
				  }else{
					  isXML= false; 
				  }
				  case "att":
				  attach=ct;
				  break;
			  }
	      }}

var url=$(formID).action;
var data=getForm(formID);
RequestHTTP(url,handleResponse,"POST",isXML,data,attach);
}

function getForm(theFormName){
   var form = document.forms[theFormName];
   if(typeof form.name == "undefined" || form.name=="")
	   form = $(theFormName);
   //form can not include "fieldset"
   var formData = "";
   var element;
  
   for (var i = 0; i < form.elements.length; i++) {
      element = form.elements[i];
      var type=element.type.toLowerCase();      
      if (type == "hidden" ||type == "text" || type == "password" || type == "textarea"){      	
       formData += element.name + "=" + $E(element.value) + "&";
	  }else if (element.type.indexOf("select") != -1) {
         for (var j = 0; j < element.options.length; j++) {
            if (element.options[j].selected == true) formData +=  element.name + "=" + $E(element.options[element.selectedIndex].value) + "&";
         }
      }
      else if (element.type == "checkbox") {
		 if (element.checked) formData += element.name + "=" + $E(element.value) + "&";
	  }
      else if (element.type == "radio") {
		  if (element.checked == true) formData += element.name + "=" + $E(element.value) + "&";
	  }
   }
   return formData.substring(0, formData.length - 1);
}

function RequestHTTP(burl,rdRandleResponse,bmethod,bXML,Formdata,attach){
var http_request = false;
function doHttpRequest()
{	
       if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

    http_request.onreadystatechange=handleStateChange;	
    http_request.open(bmethod,burl,true);
	if(Formdata){
	http_request.setRequestHeader("Content-Length",Formdata.length);   
    http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	http_request.send(Formdata);
	}else{
		if(bXML){

	        http_request.setRequestHeader("Content-Type","text/xml");
	        //charset "text/xml;charset=utf-8";
	    }else{
	        http_request.setRequestHeader("Content-Type","text/html");
	    }
    http_request.send(null);
	}
	
}

function handleStateChange()
{
    if(http_request.readyState==4 && http_request.status==200){
		var response_content;
		if(bXML){
		response_content=http_request.responseXML;
		}else{
        response_content=http_request.responseText;	
		}		
		if(typeof rdRandleResponse == "function"){
             rdRandleResponse(response_content, attach);
		}else{
		     eval(rdRandleResponse+"(response_content,attach)");
	    }
    }
}
doHttpRequest();
}

//tools
function getTagValue(doc, tag){
     var elems = doc.getElementsByTagName(tag)[0].firstChild.nodeValue;
     return elems; 
}

function $(obj){
  return document.getElementById(obj);	
}

function $F(obj){
  return document.getElementById(obj).value;
}

function $U(str){
  return encodeURIComponent(escape(str));	
}

function $E(str){
  return encodeURIComponent(str);	
}

function $css(id,rule){
  for(var i=0;i<document.styleSheets.length;i++){
		var tmp=browser.IE?document.styleSheets[i].rules:document.styleSheets[i].cssRules;
		for(var k=0;k<tmp.length;k++){
			if(tmp[k].selectorText==id){
				if(rule){
					return tmp[k].style[rule];
				}else{
					return tmp[k].style;
				}			
			}
		}
  }
}

var browser={};
browser.IE=browser.FF=browser.MF=browser.firefox=browser.OT=browser.other=false;
if (window.navigator.userAgent.indexOf("MSIE")>=1){
   browser.IE=true;
}else if (window.navigator.userAgent.indexOf("Firefox")>=1){
   browser.FF=true;
   browser.firefox=true;
   browser.MF=true;
}else{
   browser.OT=true;
   browser.other=true;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function LookU(type){
        var ProductPassword=$('ProductPassword').value;
		var ProductId=$('ProductId').value;
		if(ProductPassword==""){
			alert('请输入密码!');
			    $('ProductPassword').focus();
			return;
		}
		var herf="Encrypt.php?ProductPassword="+ProductPassword+"&ProductId="+ProductId;
		window.location.href=herf;
   }
function Look(ProductId){
		var ProductName=document.getElementById('ProductName'+ProductId);
		var ProductName=ProductName.innerHTML;
		/*var domain="Look_step"+"jewelchina86";
		var cookie=getCookie(domain);
		if(cookie!=""){
	        var ck=cookie.split('&');
			window.open("http://company.jewelchina.com/ProductShow.php?ProId="+ProductId+"&domain=jewelchina86");
		}
		else{*/
		     msgBox('输入查看密码：',login,250,180);
			 document.getElementById('ProductId').value=ProductId;
		     document.getElementById('ProductPassword').focus();
		//}
}