function _ID(obj){return document.getElementById(obj)}
function inFocus1(i) {
	(i).style.border='1px solid #c24949';
}
function outFocus1(i) {
	(i).style.border='1px solid #cccccc';
}
function LogininFocus(i) {
	(i).style.border='3px solid #00a8ff';
	(i).style.height='22px';
}
function LoginoutFocus(i) {
	(i).style.border='1px solid #242425';
	(i).style.height='22px';
}
/*** line ***/
function linecss(){
	var obj = document.getElementsByTagName('input');
	var obj_txa = document.getElementsByTagName('textarea');
	for( e =0; e < obj.length; e++ ){
		var type = obj[e].getAttribute('type');
		if( type == 'text' || type == 'password' || type == 'file'){
			var isClsnm = false;
			var clsnm = obj[e].className.toString().split(' ');
			for (c = 0; c < clsnm.length; c++){
				if (inArray(clsnm[c], Array('lline', 'line', 'rline', 'cline', 'loginline', 'textarea', 'input-product-price'))) isClsnm = true;
			}
			if (isClsnm === true){
				addEvent(obj[e], 'focus', function(e) { inFocus1(getTargetElement(e)); });
				addEvent(obj[e], 'blur', function(e) { outFocus1(getTargetElement(e)); });
			}
		}
	}

	for( t =0; t < obj_txa.length; t++ ){
		var clsnm = obj_txa[t].className.toString().split(' ');
		if (inArray("tline", clsnm)){
			addEvent(obj_txa[t], 'focus', function(e) { inFocus1(getTargetElement(e)); });
			addEvent(obj_txa[t], 'blur', function(e) { outFocus1(getTargetElement(e)); });
		}
	}
}

/* */
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;
	var msg = form.soption.value;
	/*
	if ($(".selSize #onlickSelSize").length == 0) {
        alert('请选择尺码');
        return;
    }
	
	if(form.size) {
	    if (form.size.value == '') {
	        alert('请选择尺码');
		    return;
	    }
	}
	
	if(form.goods_option1) {
	    if (form.goods_option1.value == '') {
	        alert('请选择'+msg);
		    return;
	    }
	}
	*/
	form.addcart.value = obj;
	form.action="index.php?p=cart&ps_mode=addtocart";
	form.submit();
	return;
}
function addtocart(form,obj){
	form.addcart.value = obj;
	form.action="index.php?p=cart&ps_mode=addtocart";
	form.submit();
	return;
}
function sendwish_list(form,obj){
	form.addcart.value = obj;
	form.action="index.php?p=cart&ps_mode=wishlist";
	form.submit();
	return;
}
function popup_register(mode,gid,sno) {
	alert("请先登录");
}

function show_midea(uid,img,width,height) {
    newWin = window.open("index.php?p=midea&uid="+uid,"show","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,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&action=vote&num="+p_sel_num,"问卷调查",450,350);
}

function view_vote() {
   winopen("index.php?p=poll&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) {
	document.getElementById('big_img').href = imageUrl;
		document.images.overimage.src = imageUrl;
		document.images.overimage.jqimg = imageUrl;
		obj_src = imageUrl;
    }
function change(id,img) { 
    var image = document.getElementById(id);
    image.innerHTML = img;
}

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;
}

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();
}
function recode() {
  document.getElementById('code').src="index.php?p=ajax&action=seccode&upcode="+Math.random();
}
function getCookie( name )
{
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x<= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}

		x = document.cookie.indexOf( " ", x ) + 1;

		if ( x == 0 ) break;
	}
			return "";
}
