function display(url) 
{
    var sAttr;
    var sWidth;
    var sHeight;
    var sWindowName;
    var IE=(document.all) ? 1 : 0;
    var left;
    var top;
    sAttr="width=360,height=350,top=150,left=250,location=0,menubar=0,scrollbars=1,resizable=1";
    sWindowName = "PopUp";
    popupwindow = window.open(url, sWindowName, sAttr);
}

function shownews(url)
{
	width=300;	
	height=290;	
	win_top=290;	
	win_left=660;	
	locationStr="directories=no,scrollbars=1,width="+width+",height="+height+",top="+win_top+",left="+win_left;     
	window.open(url,"nidaye",locationStr);
}

function shownewsb(_url,_width,_height)
{
	width=520;	
	height=305;	
	win_top=290;	
	win_left=480;	
	locationStr="directories=no,scrollbars=1,width="+_width+",height="+_height+",top="+win_top+",left="+win_left;     
	window.open(_url,"nidaye",locationStr);
}

function openpopup( sURL, sType ) {
    var sAttr;
    var sWidth;
    var sHeight;
    var sWindowName;
    var IE = (document.all) ? 1 : 0;
    var left;
    var top;

    switch (sType)
    {
    	  case "Middle": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "620";
                sHeight = "460";
            }
            else
            {
                // other (Netscape)
                sWidth = "700";
                sHeight = "500";
            }

            sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Lookup";
            break;
        case "Lookup": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "700";
                sHeight = "600";
            }
            else
            {
                // other (Netscape)
                sWidth = "700";
                sHeight = "500";
            }

            sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Lookup";
            break;
        case "Small": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "450";
                sHeight = "220";
            }
            else
            {
                // other (Netscape)
                sWidth = "450";
                sHeight = "220";
            }

            sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Small";
            break;
        default:

            sAttr = "width=700,height=500,top=150,left=150,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "PopUp";
    }

    popupwindow = window.open(sURL, sWindowName, sAttr);
}

function openpic( sURL, sType ) {
    var sAttr;
    var locationStr;
    var sWidth;
    var sHeight;
    var sWindowName;
    var IE = (document.all) ? 1 : 0;
    var left;
    var top;

    switch (sType)
    {
        case "Lookup": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "596";
                sHeight = "642";
            }
            else
            {
                // other (Netscape)
                sWidth = "700";
                sHeight = "500";
            }
            win_top=(window.screen.availHeight-sHeight)/2;	
	        win_left=(window.screen.availWidth-sWidth)/2;	
	        locationStr="directories=no,scrollbars=1,width="+sWidth+",height="+sHeight+",top="+win_top+",left="+win_left;
           // sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Lookup";
            break;
        case "Looking": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "596";
                sHeight = "700";
            }
            else
            {
                // other (Netscape)
                sWidth = "700";
                sHeight = "500";
            }
            win_top=0;	
	        win_left=(window.screen.availWidth-sWidth)/2;	
	        locationStr="directories=no,scrollbars=1,width="+sWidth+",height="+sHeight+",top="+win_top+",left="+win_left;
           // sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Lookup";
            break;
        case "Small": // lookup popup.

            if (IE)
            {
                // IE
                sWidth = "450";
                sHeight = "220";
            }
            else
            {
                // other (Netscape)
                sWidth = "450";
                sHeight = "220";
            }

            sAttr = "width=" + sWidth + ",height=" + sHeight + ",top=150,left=150,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "Small";
            break;
        default:

            sAttr = "width=700,height=500,top=150,left=150,location=0,menubar=0,scrollbars=1,resizable=1";
            sWindowName = "PopUp";
    }

    popupwindow = window.open(sURL, sWindowName, locationStr);
}

var lookupFld;
var lookupPrefix;
var lookupOthers;
function lookup(elementName, action, prefix, otherFields){
	lookupFld = elementName;
	lookupPrefix = prefix;
	lookupOthers = otherFields;
    openpopup(action,'Lookup');
}

function looking(elementName, action, prefix, otherFields){
	lookupFld = elementName;
	lookupPrefix = prefix;
	lookupOthers = otherFields;
    openpopup(action,'Looking');
}

/*
 * add by qingyuan 2007-9-4*/
 
function lookconsumer(array)
{
	var action="/user.do?method=list&_isLookup=true";
	
    for(i=0;i<array.length;i++)
	{		
		var fieldName=new String();
		
		fieldName=array[i];
		
		if(fieldName&&fieldName.length>0)
		{
			var emone=document.getElementsByName(fieldName);
			
			if(emone&&emone.length>0)
			{
				var param=emone[0].value;
				
				if(param&&param.length>0)
				{
					action+="&"+fieldName+"="+param;
				}
			}
		}
	}
	
	openpopup(action,"Lookup");
}

function bringbackConsumer(consumer)
{
	if(window.opener!=null)
	{
		var record=new Object();
		
		if(consumer)record.consumer=consumer;
		
		window.opener.bringBackConsumer(record,window);
	}
}
function bringbackSelect(id,name,valueArray){
	if (window.opener != null){
	   var rec=new Object();
       rec.id=id;
       rec.name=name;
       if(valueArray)
       	 rec.valueArray = valueArray;
       window.opener.bringback(rec, window);       
    }
}

function bringbackSelectVendor(id,name,valueArray){
	if (window.opener != null){
	   var rec=new Object();
       rec.id=id;
       rec.name=name;
       if(valueArray)
       	 rec.valueArray = valueArray;
       window.opener.bringbackVendor(rec, window);       
    }
}


function bringBackConsumer(record,subwindow)
{
	if(record.consumer)
	{
		var userForm=document.getElementsByName("userForm");
		
		if(userForm&&userForm.length>0)
		{
			elements=document.getElementsByName("consumer");
			
			if(elements&&elements.length>0)elements[0].value=record.consumer[0];
			
			userForm[0].submit();
		}
	}
	
	subwindow.close();
}
function bringbackSelectcon(id,name,cellPhone,homePhone,email,province,workAddress,valueArray){
	if (window.opener != null){
	   var rec=new Object();
       rec.id=id;
       rec.name=name;
       rec.cellPhone=cellPhone;
       rec.homePhone=homePhone;
       rec.email=email;
       rec.province=province;
       rec.workAddress=workAddress;
       if(valueArray)
       	 rec.valueArray = valueArray;
       window.opener.bringbackcon(rec, window);       
    }
}
function bringback(rec, subwindow){
	var idFld = lookupPrefix ? (lookupPrefix + lookupFld) : lookupFld;
	var elements = document.getElementsByName(idFld);
	if(elements && elements.length > 0)
		elements[0].value = rec.id;
	var nameFld = lookupPrefix ? (lookupPrefix + 'name_' + lookupFld) : 'name_' + lookupFld;
	elements = document.getElementsByName(nameFld);
	if(elements && elements.length > 0)
		elements[0].value = rec.name;
	if(lookupOthers){
		for(var i = 0; i < lookupOthers.length; i++){
			var fieldName = lookupPrefix ? (lookupPrefix + lookupOthers[i]) : lookupOthers[i];
			elements = document.getElementsByName(fieldName);
			if(elements && elements.length > 0)
			{
				if(elements[0].src)
				{
					elements[0].src = rec.valueArray[i];
				}else{
					elements[0].value = rec.valueArray[i];
				}
			}
		}
	}
	subwindow.close();
}

function bringbackVendor(rec, subwindow){
	var idFld = lookupPrefix ? (lookupPrefix + lookupFld) : lookupFld;
	var elements = document.getElementsByName(idFld);
	if(elements && elements.length > 0)
		elements[0].value = rec.id;
	var nameFld = lookupPrefix ? (lookupPrefix + 'name_' + lookupFld) : 'name_' + lookupFld;
	elements = document.getElementsByName(nameFld);
	if(elements && elements.length > 0)
		elements[0].value = rec.name;
	if(lookupOthers){
		for(var i = 0; i < lookupOthers.length; i++){
			var fieldName = lookupPrefix ? (lookupPrefix + lookupOthers[i]) : lookupOthers[i];
			elements = document.getElementsByName(fieldName);
			if(elements && elements.length > 0)
				elements[0].value = rec.valueArray[i];
		}

		if(document.getElementById("bankId")&&document.getElementById("getBankId"))
		{
			var bankIds=document.getElementById("getBankId").value
			var ops=document.getElementById("bankId").options;
	    	for(var i=0;i<ops.length;i++)
	    	{

	    		if(ops[i].value==bankIds)
	    			document.getElementById("bankId").selectedIndex=i;
	    	}
		}
	}
	subwindow.close();
}
function bringbackcon(rec, subwindow){
	
	var elements = document.getElementsByName("consumer");
	if(elements && elements.length > 0){
		elements[0].value = rec.id;}
		
	elements=document.getElementsByName("issuerParty");
	if(elements&&elements.length>0)elements[0].value=rec.id;
	elements=document.getElementsByName("name_issuerParty");
	if(elements&&elements.length>0)elements[0].value=rec.name;
	
	elements = document.getElementsByName("consumerName");
	if(elements && elements.length > 0)
		elements[0].value = rec.name;
	elements = document.getElementsByName("confirmCellPhone");
	if(elements && elements.length > 0)
		elements[0].value = rec.cellPhone;
	elements = document.getElementsByName("confirmPhone");
	if(elements && elements.length > 0)
		elements[0].value = rec.homePhone;
	elements = document.getElementsByName("confirmMail");
	if(elements && elements.length > 0)
		elements[0].value = rec.email;
	elements = document.getElementsByName("confirmProvince");
	if(elements && elements.length > 0){
		elements[0].value = rec.province;}
	elements = document.getElementsByName("confirmAddr");
	if(elements && elements.length > 0)
		elements[0].value = rec.workAddress;
		
	if(lookupOthers){
		for(var i = 0; i < lookupOthers.length; i++){
			var fieldName = lookupPrefix ? (lookupPrefix + lookupOthers[i]) : lookupOthers[i];
			elements = document.getElementsByName(fieldName);
			if(elements && elements.length > 0)
				elements[0].value = rec.valueArray[i];
		}
	}
	subwindow.close();
}
function isDecimalDigits(argvalue) {
	  if(!argvalue)
	  	return false;
      argvalue = argvalue.toString();
      var validChars = "0123456789";

      var startFrom = 0;
      if (argvalue.charAt(0) == "-") {
          startFrom = 1;
      }

      for (var n = startFrom; n < argvalue.length; n++) {
          if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
      }
      return true;
 }
 
 
flushCity = function(provinceId, formName, cityField){
	var callback = {
		success: flushSuccess, 
		failure: flushFailure,
		timeout: 8000,
		argument: [formName, cityField]
	}
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/province.do', callback, 'province=' + provinceId); 
}

function flushSuccess(o){
	var selEl = eval('document.' + o.argument[0] +'.' + o.argument[1]);
	var length=selEl.options.length;
	while(length !=0 ){
       var length=selEl.options.length;
       for(var i=0;i<length;i++){
           selEl.options.remove(i);
       }
       length=length/2;
    }
    var responseObj = eval('('+ o.responseText +')');
	if(responseObj.citylist){
		for(var i = 0; i < responseObj.citylist.length; i++){
		    var el = document.createElement('OPTION');
		    var value = eval('responseObj.citylist[' + i  +'].name');
		    el.value = value;
		    el.text = value;
			selEl.add(el);
		}
	}
	
}
function subProdReview(){
	if(document.AddProdReview.review.value.length==0){
		alert("评论内容不能为空！");
		return false;
	}else return true;
}
function flushFailure(argument)
{
	alert("没有省份的城市信息!");
}

  function showImage()
  {
     var url=document.getElementById("image_source").value;
     openpic(url,'Lookup');
  }
  function show_image(source)
  {
    var prefix=source.substring(0,source.lastIndexOf("/")+1);
    var path=source.substring(source.lastIndexOf("/")+1,source.length);
    b_path="b"+path.substring(path.indexOf("_"),path.length);
    big_path=path.substring(path.indexOf("_")+1,path.length);
    var bel = document.getElementById("b_image");
    bel.src=prefix+b_path;
    bel.parentNode.href = prefix+big_path;
    document.getElementById("image_source").value=prefix+big_path;
  }  
  function addP(id,custom)
  {
    if(custom==4)
    {
      adding(id);
    }else if(custom==3)
    {
    	add_mitamin(id);
    }else{
      location.href='/shoppingcart.do?_methodName=add&_product_id='+id;
    }
  }
  function add_mitamin(id)
  {
  	var callback={success: mitaminSuccess, failure: mitaminFailure};	
	  var cObj=YAHOO.util.Connect.asyncRequest('POST', '/shoppingcart.do?_methodName=exist_mitamin&_product_id='+id, callback,''); 
  }
  function mitaminSuccess(argument)
  {
  	var responseObj=eval('('+ argument.responseText +')');
	  if(responseObj)
	  {
	  	if(responseObj.result=="1")
	  	{
	  		alert("购买的礼品不存在！");
	  	}else if(responseObj.result=="2")
	  	{
	  		alert("当前礼品未上架,暂时不能购买！");
		  }else if(responseObj.result=="3")
		  {
		  	alert('请选择美太美素产品！');
		  }else if(responseObj.result=="4")
		  {
		  	document.location.replace('/shoppingcart.do?_methodName=add&_product_id='+responseObj.id);
		  }else if(responseObj.result=="5")
		  {
		  	alert('每次购物只能选择一款美态美素产品！');
		  }	
	  }
 }
 function mitaminFailure(argument)
 {
 }
  function adding(id)
  {
    var msgw,msgh,bordercolor;
    msgw=300;//提示窗口的宽度
    msgh=150;//提示窗口的高度
    titleheight=25 //提示窗口标题高度
    bordercolor="#336699";//提示窗口的边框颜色
    titlecolor="#99CCFF";//提示窗口的标题颜色
    var sWidth,sHeight;
    sWidth=document.body.clientWidth;//浏览器工作区域内页面宽度
    sHeight=screen.height;//屏幕高度（垂直分辨率）
  //背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）
  var bgObj=document.createElement("div");//创建一个div对象（背景层）
  //定义div属性，即相当于
  //<div id="bgDiv" style="position:absolute; top:0; background-color:#777; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.6; left:0; width:918px; height:768px; z-index:10000;"></div>
  bgObj.setAttribute('id','bgDiv');
  bgObj.style.position="absolute";
  bgObj.style.top="0";
  bgObj.style.background="#FFF";
  bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  bgObj.style.opacity="0.6";
  bgObj.style.left="0";
  bgObj.style.width=sWidth + "px";
  bgObj.style.height=sHeight + "px";
  bgObj.style.zIndex = "10000";
  //document.body.style.overflow="hidden"
 // document.body.appendChild(bgObj);//在body内添加该div对象
  var msgObj=document.createElement("div")//创建一个div对象（提示框层）
  //定义div属性，即相当于
  //<div id="msgDiv" align="center" style="background-color:white; border:1px solid #336699; position:absolute; left:50%; top:50%; font:12px/1.6em Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left:-225px; margin-top:npx; width:400px; height:100px; text-align:center; line-height:25px; z-index:100001;"></div>
  msgObj.setAttribute("id","msgDiv");
  msgObj.setAttribute("align","center");
  msgObj.style.backgroundImage="url('/images/common/body.jpg')";
  msgObj.style.position = "absolute";
  msgObj.style.left = "50%";
  msgObj.style.top = "50%";
  msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  msgObj.style.marginLeft = "-150px" ;
  msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
  msgObj.style.width = msgw + "px";
  msgObj.style.height =msgh + "px";
  msgObj.style.textAlign = "left";
  msgObj.style.lineHeight ="25px";
  msgObj.style.zIndex = "10001";
  var title=document.createElement("h4");//创建一个h4对象（提示框标题栏）
title.setAttribute("id","msgTitle");
  title.setAttribute("align","right");
  title.style.margin="0";
  title.style.padding="3px";
  title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
  title.style.opacity="0.75";
  title.style.height="18px";
  title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
  title.style.color="white";
  title.style.cursor="pointer";
  title.innerHTML="<img src='/images/common/close.jpg'>";
  title.onclick=removeObj;
  var button=document.createElement("img");//创建一个input对象（提示框按钮）
  button.setAttribute("src",'/images/common/cancel.jpg');
  button.onclick=removeObj;
  function removeObj()
  {//点击标题栏触发的事件
   // document.body.removeChild(bgObj);//删除背景层Div
    document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏
    document.body.removeChild(msgObj);
//	document.body.style.overflow=""//删除提示框层
  }
  function addingSuccess(argument)
 {
	var responseObj=eval('('+ argument.responseText +')');
	if(responseObj)
	{
		if(responseObj.result=="1")
		{
			document.getElementById('msgTxt').innerHTML="指定的红包不存在！";
			document.getElementById('confirm').onclick=removeObj;
		}else if(responseObj.result=="2")
		{
			document.getElementById('msgTxt').innerHTML="指定的红包已经下架！";
			document.getElementById('confirm').onclick=removeObj;
		}else if(responseObj.result=="3")
		{
			document.getElementById('msgTxt').innerHTML="指定的礼品不是红包！";
			document.getElementById('confirm').onclick=removeObj;
		}else if(responseObj.result=="4")
		{
		    document.getElementById('msgTxt').innerHTML="当前红包已经在购物车中！";
			document.getElementById('confirm').onclick=removeObj;
		}else if(responseObj.result=="5")
		{
			document.getElementById('msgTxt').innerHTML="红包金额不能大于2000元！";
			document.getElementById('confirm').onclick=removeObj;
		}else{
		    removeObj();
			document.location.replace('/shoppingcart.do?_methodName=view');
		}		
	}
 }
 
 function addingFailure(argument)
 {
 }
  var button2=document.createElement('img');
  button2.setAttribute("src",'/images/common/confirm.jpg');
  button2.setAttribute("id","confirm");
  button2.style.marginRight="10px";
  var product=document.createElement('input');
  product.setAttribute("type",'hidden');
  product.setAttribute("value",id);
  product.setAttribute("id","product");
  button2.onclick=applayObj;
  function applayObj()
  {
     var result=document.getElementById("redbag").value;
     var _product=document.getElementById("product").value;
     var callback={success: addingSuccess, failure: addingFailure};	
	 var cObj=YAHOO.util.Connect.asyncRequest('POST', '/shoppingcart.do?_methodName=adding&_product_id='+_product, callback, 'mny='+result); 
  }  
  document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj
  document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title
  var txt=document.createElement("div");//创建一个p对象（提示框提示信息）
  txt.setAttribute("id","msgTxt");
  txt.style.textAlign="left";
  txt.style.paddingLeft="50px";
  txt.style.width="250px";
  txt.style.height="60px";
  txt.style.marginTop="30px"
 //输入文本框的位置
  txt.innerHTML="请输入红包金额(不能超过2000元)<br><input id='redbag' type='text' style='border:1px solid #9FB6CD;width:200px' />";//来源于函数调用时的参数值
  var buttonDiv=document.createElement("div");
  buttonDiv.style.marginLeft="90px";
  document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt
  buttonDiv.appendChild(button2);
  buttonDiv.appendChild(button);
  document.getElementById("msgDiv").appendChild(buttonDiv);
//在提示框div中添加按钮对象button
  document.getElementById("msgDiv").appendChild(product);  
}
function bringBackConsumerByPhone(user,obj){
	var consumerForm = document.forms[0];
	consumerForm.consumerId.value=user[0];
  	consumerForm.consumerName.value=user[1];
  	document.getElementById('phone').innerHTML=user[2];
  	consumerForm.qq.value=user[5];
  	consumerForm.msn.value=user[6];
  	consumerForm.mail.value=user[3];
  	consumerForm.city.value=user[4];
  	obj.close();
}
 function xyk()
    {
     	window.open("/xyk.htm","_blank",'height=600px,width=650px,scrollbars=yes,top=50px,left=200px');
    }
     function zfb()
    {
     	window.open("/zfb.htm","_blank",'height=600px,width=650px,scrollbars=yes,top=50px,left=200px');
    }
    
function addR(id,custom){
	var callback={success : shopSuccess, failure : shopFail};
    YAHOO.util.Connect.asyncRequest('POST', '/shoppingcart.do?_methodName=add&_product_id='+id+'&custom='+custom, callback);
}
function shopSuccess(){
	alert('您已成功将礼品放入购物车');
_cart_ttc_()
}
function shopFail(){}
function searchByCondition(condition,value){
	var url = "/gift.do?_methodName=searchere";
	if(condition=='category')
	 if(value != document.getElementById(condition).value){
	 	location.href=url+"&category="+value;
	 	return;
	 }
	if(condition)
	document.getElementById(condition).value=value;
	var o = document.getElementById('object').value;
	var occassion = document.getElementById('occassion').value;
	var price = document.getElementById('price').value;
	var category = document.getElementById('category').value;
	var sort = document.getElementById('sort').value;
	var page = document.getElementById('page').value;
	var totalpage = document.getElementById('totalPage').value;
	 if(page && page<=0)
	    page =1;
	 if(page && totalpage && page-totalpage>0)
	    page = totalpage;
	var display = document.getElementById('display').value;
	location.href=url+"&category="+category+"&object="+o+"&occassion="+occassion+"&price="+price+"&sort="+sort+"&page="+page+"&display="+display;
}
