function _ID(obj){return document.getElementById(obj)}

/* */
function addEvent(obj, evType, fn){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function delEvent(obj, evType, fn){
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, false);
		return true;
	} else if (obj.detachEvent) {
		var r = obj.detachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function getTargetElement(evt)
{
	if ( evt.srcElement ) return target_Element = evt.srcElement; // 
	else return target_Element = evt.target; // 
}
function inArray( needle, haystack )
{
	for ( i = 0; i < haystack.length; i++ )
		if ( haystack[i] == needle ) return true;
	return false;
}

/**
 * selectDisabled(oSelect)
 */
function selectDisabled(oSelect){
	var isOptionDisabled = oSelect.options[oSelect.selectedIndex].disabled;
    if (isOptionDisabled){
        oSelect.selectedIndex = oSelect.preSelIndex;
        return false;
    } else oSelect.preSelIndex = oSelect.selectedIndex;
    return true;
}

function chkOption(obj)
{
	if (!selectDisabled(obj)) return false;
}

function sendcart(obj){
	var form = document.goods;
	form.addcart.value = obj;
	form.action="index.php?p=goods_cart";
	form.submit();
	return;
}
function addtocart(form,obj){
	form.addcart.value = obj;
	form.action="index.php?p=goods_cart";
	form.submit();
	return;
}
function sendwish_list(form,obj){
	form.addcart.value = obj;
	form.action="index.php?p=goods_cart&mode=wish_list";
	form.submit();
	return;
}
function popup_register(mode,gid,sno) {
	alert("请先登录");
}

// popup
function show_image(uid,img,width,height) {
    newWin = window.open("index.php?p=goods_view_img&image="+img+"&uid="+uid,"show","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function show_midea(uid,img,width,height) {
    newWin = window.open("index.php?p=goods_view_midea&uid="+uid,"show","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function show_mall_image(uid,img,width,height) {
    newWin = window.open("index.php?p=goods_view_img&image="+img+"&uid="+uid,"show","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function show_board_image(img,width,height) {
    newWin = window.open("index.php?p=board_image&image="+img,"show","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

var p_sel_num = 0;
function select_radio(num) {
   p_sel_num =  num;
}

function submit_vote() {
   if (p_sel_num == 0) {
      alert('请选择投票选项.');
      return;
   }
   winopen("index.php?p=poll_vote&action=vote&num="+p_sel_num,"问卷调查",450,350);
}

function view_vote() {
   winopen("index.php?p=poll_vote&action=view","问卷调查",450,350);
}

function winopen(url,title,w,h) {
		newwin = window.open(url,title,"toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,resizable=no,width=" + w + ",height=" + h + ",alwaysRadised=0");
		newwin.focus();
}

// 简单检索
function check_top_search() {
    var m=document.vii_top_search;

    if (m.keyword.value.length == "") {
       alert("请输入关键词");
       m.keyword.focus();
       return false;
    }
}

// popup移动脚本

function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';

  newWin= window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

// 拷贝
function accept_check(){
   var m = document.viiform;

   m.buyer_name3.value = m.buyer_name1.value;
   m.buyer_tel3.value = m.buyer_tel1.value;
   m.buyer_tel4.value = m.buyer_tel2.value;
   m.buyer_oicq1.value = m.buyer_oicq.value;
   m.buyer_msn1.value = m.buyer_msn.value;
   m.zip3.value = m.zip.value;
   m.address2.value = m.address.value;
   m.buyer_email1.value = m.buyer_email.value;
}

// 
function error (elem,text) {
	window.alert(text);
	elem.select();
	elem.focus();
}

function OverImg(imageUrl)
{
	if (document.images.overimage)
		document.images.overimage.src = imageUrl;
}
function outSubM(obj) {
	SubM.style.display = 'none';
}
function overSubM(obj) {
	SubM.style.display = 'block';
}

function verifyNumber(n)
{
	var patn = /^\d+$|^\d+\.\d{1,2}$/;
	if(patn.test(n))
		return false;
	return true;
}

function good_cal(val)
{
	if (val > 0){
		goods.ea.value = (goods.ea.value*1) + 1;
	} else {
		if(goods.ea.value>1){ 
			goods.ea.value = goods.ea.value - 1;
		}
	}
	return;
}

function error(elem,text) {
	window.alert(text);
	elem.select();
	elem.focus();
}

var preContent;
function view_content(obj)
{
	var div = obj.parentNode;

	if ( document.all ) obj = div.childNodes[ 1 ]; else obj = div.childNodes[ 3 ]; // 

	if (preContent && obj!=preContent){
		obj.style.display = "block";
		preContent.style.display = "none";
	}
	else if (preContent && obj==preContent) preContent.style.display = ( preContent.style.display == "none" ? "block" : "none" );
	else if (preContent == null ) obj.style.display = "block";

	preContent = obj;
	resizeFrame();
}

function resizeFrame()
{

    var oBody = document.body;
    var oFrame = parent.document.getElementById("inqna");
//    var i_height = oBody.scrollHeight + (oFrame.offsetHeight-oFrame.clientHeight);
//    oFrame.style.height = i_height;
}

// 地址
function GetProvince(strTheForm,strProvince,strCity,strCounty,strProvinceID)
{
	strProvince = strTheForm + "." + strProvince
	strCity = strTheForm + "." + strCity
	strCounty = strTheForm + "." + strCounty
	var TheProvince = eval(strProvince)
	var TheCity = eval(strCity)
	var TheCounty = eval(strCounty)
	TheCity.disabled = true
	TheCounty.disabled = true
    if(Province.length != 0)
    {
        TheProvince.options.length = 0
        TheProvince.options[0] = new Option('省份','')
        TheProvince.options[0].selected = true
        var j = 1
        for(i=0;i<Province.length;i+=2)
        {
            if(Province[i] == "" || Province[i+1] == "")
            {
            	continue
            }
        	else
        	{
        		TheProvince.options[j] = new Option(Province[i+1],Province[i])
        		j++
        	}
        }
    }
    if(strProvinceID != "")
    {
    	strProvinceID = strProvinceID.toString()
    	var L_strProvinceID = strProvinceID.length
    	if(L_strProvinceID < 12)
    	{
    		for(i=0;i<12-L_strProvinceID;i++)
    		{
    			strProvinceID += "0"
    		}
    	}
    	var DefaultProvince = strProvinceID.substring(0,6)
    	var DefaultCity = strProvinceID.substring(0,9)
    	var DefaultCounty = strProvinceID.substring(0,12)
    	GetDefaultItem(TheProvince,DefaultProvince)
    	GetCity(strTheForm,strProvince,strCity,strCounty)
    	GetDefaultItem(TheCity,DefaultCity)
    	GetCounty(strTheForm,strProvince,strCity,strCounty)
    	GetDefaultItem(TheCounty,DefaultCounty)
    }
}

function GetCity(strTheForm,strProvince,strCity,strCounty)
{
	strProvince = strTheForm + "." + strProvince
	strCity = strTheForm + "." + strCity
	strCounty = strTheForm + "." + strCounty
	var TheProvince = eval(strProvince)
	var TheCity = eval(strCity)
	var TheCounty = eval(strCounty)
	if(TheProvince.selectedIndex != 0)
	{
		TheCity.options.length = 0
		TheCity.options[0] = new Option('城市','')
		TheCity.options[0].selected = true
		TheCity.disabled = true
		TheCounty.options.length = 0
		TheCounty.options[0] = new Option('地区','')
		TheCounty.options[0].selected = true
		TheCounty.disabled = true
		CityIndex = TheProvince.options[TheProvince.selectedIndex].value
		var j = 1
        for(i=0;i<City[CityIndex].length;i+=2)
        {
            if(City[CityIndex][i] == "" || City[CityIndex][i+1] == "")
            {
            	continue
            }
        	else
        	{
            	TheCity.options[j] = new Option(City[CityIndex][i+1],City[CityIndex][i])
            	j++
            }
        }
        if(TheCity.options.length > 1) TheCity.disabled = false
	}
	else
	{
		TheCity.options.length = 0
		TheCity.options[0] = new Option('城市','')
		TheCity.options[0].selected = true
		TheCity.disabled = true
		TheCounty.options.length = 0
		TheCounty.options[0] = new Option('地区','')
		TheCounty.options[0].selected = true
		TheCounty.disabled = true
	}
}

function GetCounty(strTheForm,strProvince,strCity,strCounty)
{
	strProvince = strTheForm + "." + strProvince
	strCity = strTheForm + "." + strCity
	strCounty = strTheForm + "." + strCounty
	var TheProvince = eval(strProvince)
	var TheCity = eval(strCity)
	var TheCounty = eval(strCounty)
	if(TheProvince.selectedIndex != 0 && TheCity.selectedIndex != 0)
	{
		TheCounty.options.length = 0
		TheCounty.options[0] = new Option('地区','')
		TheCounty.options[0].selected = true
		TheCounty.disabled = true
		CountyIndex = TheCity.options[TheCity.selectedIndex].value
		var j = 1
        for(i=0;i<County[CountyIndex].length;i+=2)
        {
            if(County[CountyIndex][i] == "" || County[CountyIndex][i+1] == "")
            {
            	continue
            }
        	else
            {
            	TheCounty.options[j] = new Option(County[CountyIndex][i+1],County[CountyIndex][i])
            	j++
            }
        }
        if(TheCounty.options.length > 1) TheCounty.disabled = false
	}
	else
	{
		TheCounty.options.length = 0
		TheCounty.options[0] = new Option('地区','')
		TheCounty.options[0].selected = true
		TheCounty.disabled = true
	}
}

//把地点ID转为相应的地点
function getPlaceValue(strProvinceID)
{
    if (strProvinceID.length < 6) return false;//地点ID小于6是返回false
    var i = 0;
    var strProvince,strCity,strCounty;
    ProvinceID = strProvinceID.substr(0,6);
    CityID = strProvinceID.substr(0,9);
    CountyID = strProvinceID;
    for (i = 0;i < Province.length;i += 2)
    {
        if(Province[i] == ProvinceID)
        {
        	strProvince = Province[i+1]
        	break;
        }
    }
    if (strProvinceID.length > 8)//地点ID小于8不执行以下代码
    {
        for (i = 0;i < City[ProvinceID].length;i += 2)
        {
            if (City[ProvinceID][i] == CityID)
            {
                strCity = City[ProvinceID][i+1];
                break;
            }
        }
        if(strProvinceID.length > 11)//地点ID小于11不执行以下代码
        {
        
            for (i = 0;i < County[CityID].length;i += 2)
            {
                if (County[CityID][i] == CountyID)
                {
                    strCounty = County[CityID][i+1];
                    break;
                }
            }
        }
    }
	
	var strPlace = strProvince;
	if(strCity!=undefined){
		strPlace+=strCity;
		}
	if(strCounty!=undefined){
		strPlace+=strCounty;
	}
    ///var strPlace = strProvince + strCity + strCounty;
    ///return strPlace;
	
	return strPlace;
}

function ChecktoAddress(val){
    document.viiform.address.value=getPlaceValue(val);
}

if ( typeof( scrollingX ) == 'undefined' ){

	var scrollingX = function( objnm, elenm ){

		if ( objnm == '' ) return;
		if ( elenm == '' ) return;
		this.obj = objnm;
		this.ele = eval( "window.frames." + elenm );

		this.time = 20; // 
		this.drX = 1; // 
		this.scrollX = 0;
		this.is_move = 1;
		this.ele.scrollTo( 1, 0 );
	}

	scrollingX.prototype.stop = function(){ this.is_move = 0; }
	scrollingX.prototype.start = function(){ this.is_move = 1; }

	scrollingX.prototype.initScroll = function()
	{
		this.p_bound = this.ele.document.body.scrollWidth - this.ele.document.body.offsetWidth;
		this.p_moveRight = Math.floor( this.ele.document.body.scrollWidth / 2 );
		this.p_moveLeft = this.p_bound - this.p_moveRight;

		setInterval( this.obj + '.goScrolling()', this.time );
	}

	scrollingX.prototype.goMove = function( idx )
	{
		if ( idx == 0 ) this.drX = -Math.abs( this.drX );
		else this.drX = +Math.abs( this.drX );

		var pos = this.scrollX + idx;
		this.ele.scrollTo( pos, 0 );
	}

	scrollingX.prototype.goScrolling = function()
	{
		if ( !this.is_move ) return;
		this.scrollX = this.ele.document.body.scrollLeft + this.drX; // window.status = this.scrollX;
		if ( this.drX < 0 && this.scrollX < 1 ) this.scrollX = this.p_moveRight;
		if ( this.drX > 0 && this.scrollX > this.p_bound ) this.scrollX = this.p_moveLeft;
		this.ele.scrollTo( this.scrollX, 0 );
	}
}

if ( typeof( scrollingY ) == 'undefined' ){

	var scrollingY = function( objnm, elenm ){

		if ( objnm == '' ) return;
		if ( elenm == '' ) return;
		this.obj = objnm;
		this.ele = eval( "window.frames." + elenm );

		this.time = 20; // 
		this.drY = 1; // 
		this.scrollY = 0;
		this.is_move = 1;
		this.ele.scrollTo( 0, 1 );
	}

	scrollingY.prototype.stop = function(){ this.is_move = 0; }
	scrollingY.prototype.start = function(){ this.is_move = 1; }

	scrollingY.prototype.initScroll = function()
	{
		this.p_bound = this.ele.document.body.scrollHeight - this.ele.document.body.offsetHeight;
		this.p_moveBot = Math.floor( this.ele.document.body.scrollHeight / 2 );
		this.p_moveTop = this.p_bound - this.p_moveBot;

		setInterval( this.obj + '.goScrolling()', this.time );
	}

	scrollingY.prototype.goMove = function( idx )
	{
		if ( idx == 0 ) this.drY = -Math.abs( this.drY );
		else this.drY = +Math.abs( this.drY );

		var pos = this.scrollY + idx;
		this.ele.scrollTo( 0, pos );
	}

	scrollingY.prototype.goScrolling = function()
	{
		if ( !this.is_move ) return;
		this.scrollY = this.ele.document.body.scrollTop + this.drY; // window.status = this.scrollY;
		if ( this.drY < 0 && this.scrollY < 1 ) this.scrollY = this.p_moveBot;
		if ( this.drY > 0 && this.scrollY > this.p_bound ) this.scrollY = this.p_moveTop;
		this.ele.scrollTo( 0, this.scrollY );
	}
}

var price = new Array();
var reserve = new Array();
var consumer = new Array();

function calc_price(){
	
	var frm = document.goods;
	var cea = frm.ea.value;
	var isCntprice = frm.cntprice_yn.value;
	 
	if(isCntprice == "1"){
		var c1 = eval(frm.cnt_1.value);
		var c2 = eval(frm.cnt_2.value);
		var c3 = eval(frm.cnt_3.value);
		var c4 = eval(frm.cnt_4.value);
		
		var c1p = frm.cnt_1_price.value;
		var c2p = frm.cnt_2_price.value;
		var c3p = frm.cnt_3_price.value;
		var c4p = frm.cnt_4_price.value;
		
		
		if(c4 <= cea){
			frm.goods_price.value = c4p;
		}
		else if(c3 <= cea){
			frm.goods_price.value = c3p;
		}
		else if(c2 <= cea){
			frm.goods_price.value = c2p;
		}
		else if(c1 <= cea){
			frm.goods_price.value = c1p;
		}
		else{
			frm.goods_price.value = frm.goods_tmp_price.value;
		}
	}
}

function chg_cart_ea(obj,str,idx)
{
	if (obj.length) obj = obj[idx];
	if (isNaN(obj.value)){
		alert ("非法字符 购买数量只能是数字");
		obj.value=1;
		obj.focus();
	} else {
		if (str=='up') obj.value++;
		else  obj.value--;
		if (obj.value==0) obj.value=1;
	}
	calc_price();
}
function chkBox(El,mode)
{
	if (!El) return;
	if (typeof(El)!="object") El = document.getElementsByName(El);
	for (i=0;i<El.length;i++) El[i].checked = (mode=='rev') ? !El[i].checked : mode;
}
function isChked(El,msg)
{
	if (!El) return;
	if (typeof(El)!="object") El = document.getElementsByName(El);
	if (El) for (i=0;i<El.length;i++) if (El[i].checked) var isChked = true;
	if (isChked){
		return (msg) ? confirm(msg) : true;
	} else {
		alert ("没有选择项");
		return false;
	}
}
function reloadcode() {
  document.getElementById('checkcode').src="index.php?p=ajax&action=seccode&upcode="+Math.random();
}
function reloadcode_login() {
  document.getElementById('checkcode_login').src="index.php?p=ajax&action=seccode&upcode="+Math.random();
}