// netel 123mall project
var opera_save ="save";
var opera_edit ="edit";
var opera_delete ="delete";
var opera_new ="new";
var opera_update="update";
var opera_search="search";

window.attachEvent('onload',initCityAndProvince);
window.attachEvent('onload',restoryAllDate);

function samePasswod(p1,p2){
	if(p1.value!=p2.value){
		alert("确认密码有误!");
		p2.focus();
       setErrCssForElement(p2);
		return false;
	}
		return true;
}

function goPolling(obj){
		var pid = obj.pollingId;
		var oid = 0;
		//基本高度
		var windowHeight=60;
		var Options = document.all.OPTION_ID;
		for(var i=0;i<Options.length;i++){
			if(Options[i].checked){
				oid = Options[i].value;
			}
			//每一项要增加的高度
			windowHeight+=40;
		}
		if(oid==0){
			alert("请选择投票项,谢谢");
			return;
		}
		window.open('ViewPolling.jsp?PID='+pid+'&OID='+oid,'GoPolling','status=0,status=0,resizable=no,toolbar=0,scrollbars=0,width=300,height='+windowHeight);
}

function changeQuestionDisplay(obj,imageObj){
 if(obj.style.display=='none'){
     obj.style.display='';
     imageObj.src='images/system/ico/ico_question_off.gif';
  }else{
     obj.style.display='none';
     imageObj.src='images/system/ico/ico_question_on.gif';
  }
}

function turn_count_num(obj,boo)
{
	if(boo){
		intpuObj =obj.parentElement.firstChild.firstChild;
	}else{
		intpuObj =obj.parentElement.parentElement.firstChild.firstChild.firstChild;
    }
	if(intpuObj!=null){
		var num = parseInt(intpuObj.value);
		if(isNaN(num)){
			num =0;
        }
		if(boo){
			num++;
		}else if(num>1){
			num--;
        }
        intpuObj.value = num;
        if(this.changeTurnCountOver!=null){
			this.changeTurnCountOver(intpuObj);
          }
    }
}

// to set action menu

function restoryAllDate(check_form_etem)
{
   if(check_form_etem!=null&&check_form_etem.tagName=='FORM')
	  {
		  for(var i=0;i<check_form_etem.length;i++)
		  {
			  var temp_boolean=true;
			  var temp_comp=check_form_etem.elements[i];
			  var perElememt = check_form_etem.elements[i-1];
			  var temp_type= temp_comp.type;

			  if( temp_comp.defvalue!=null&&temp_comp.defvalue!=''&&temp_comp.defvalue!='null')
			  {
				 if(temp_type=='file' || temp_type=='hidden' || temp_type=='text' ||temp_type=='textarea'|| temp_type=='password')
				 {
					temp_comp.value = temp_comp.defvalue;
				 }

				 if(temp_type=='select-one')
				 {
                   for(var j=0;j<temp_comp.length;j++)
 				     {

   					     if(trim(temp_comp.options[j].value)==temp_comp.defvalue)
                        {
								temp_comp.selectedIndex=j;
                                //注意要先判断有否even
                                if(temp_comp.needchange!=null && temp_comp.onchange!=null){
									temp_comp.onchange();
                                }
								break;
   	 				    }
  				    }
				 }

				 if(temp_type=='checkbox')
				 {
                   	if(temp_comp.value == temp_comp.defvalue)
                 	{
                       temp_comp.checked=true;
                    }
				 }
                 //-----------
                 if(temp_type=='radio')
				 {
                 	if(temp_comp.value == temp_comp.defvalue)
                 	{
                       temp_comp.checked=true;
                    }
				 }
			  }

              //特别注意设置时间时候以小写的even
              if(temp_type=='file' || temp_type=='hidden' || temp_type=='text' ||temp_type=='textarea'|| temp_type=='password'){
			  	//如果有isDigit属性那么只能按数字按键
                if(temp_comp.isdigit!= null){
					temp_comp.onkeypress = function (e){
						onlyDigit();
                      };
                    temp_comp.onchange = function (e){
                      if (!e) e = event;
                      var t = e.target ? e.target : e.srcElement;
                      t.value=formatNum(t.value,0);
                      };
              	 }
                 //如果有isFloat属性那么只能按数字按键
				if(temp_comp.isfloat!= null||temp_comp.isFloat!= null){
					temp_comp.onkeypress = function (e){
						onlyDigit();
					};
					temp_comp.onchange = function (e){
						if (!e) e = event;
						var t = e.target ? e.target : e.srcElement;
						t.value=formatNum(t.value,1);
                      };
              	 }
              }

				if(temp_type=='button'){
						if(temp_comp.className=="buttonPaste"){
					  		if(perElememt&&perElememt.type=='text'){
									temp_comp.targetText = perElememt;
									temp_comp.title="粘贴文本内容";
                                    temp_comp.value="";
									temp_comp.onclick=function(e){
							  				this.targetText.value = window.clipboardData.getData("Text");
							  		};
							}
						}
						if(temp_comp.className=="buttonCopy"){
									temp_comp.onclick=function(e){
							  				window.clipboardData.setData("Text",this.copyvalue);
											alert('内容已拷贝至剪贴板');
							  		};
					  	}
						if(temp_comp.isgoodclass!=null || temp_comp.className=="buttonGoodClass"){
									temp_comp.onclick=function(e){
										showClassDiv(this);
							  		};
					  	}

						if(temp_comp.className=='menuButton'&&temp_comp.onclick==null){
						temp_comp.onclick = function (e){
								if (!e) e = event;
								var t = e.target ? e.target : e.srcElement;
								showButtonMenu(t);
							};
						}
						if(temp_comp.className=='buttonDate'){

						}
	  			}
              if(temp_type=='checkbox'){
                //如果有select_all_index属性那么只将有全选的功能
                if(temp_comp.select_all_index!=null)
                {
                	temp_comp.onclick = function ()
                	{
                      checkallbox(this);
                      if(this.deletecheck!=null && checkActonFrame()){
                        	top.actionFrame.checkDelectElement();
                      }
	             	};
                }
                //如果有select_all_index属性能检测并设置全选按钮的状态
                if(temp_comp.select_index!=null)
                {
                	temp_comp.onclick = function ()
                	{
                      checkparentbox(this);
                      //添加对删除按钮的显示
                      if(this.deletecheck!=null && checkActonFrame()){
                        	top.actionFrame.checkDelectElement();
                      }
	             	};
                }
              }

	  }
        status ='Restore All Data..';

	  }	  else
	  {
        status ='no form! kony_han!';
        //递归调用重置的方法
        for(i=0;i<document.forms.length;i++){
           restoryAllDate(document.forms[i]);
        }
	  }


}

function initCityAndProvince(){
	  var pselect = document.all.ADDR_PROVINCE;
	  if(pselect==null) return;
	  for(var i=0;i<ProvinceArr.length;i++){
			var poption=new Option(ProvinceArr[i][0],ProvinceArr[i][0]);
			poption.pid=ProvinceArr[i][1];
			pselect.add(poption);
		}
	  pselect.needchange = true;
	  pselect.onchange = function(e){
					pchange(this.options[this.selectedIndex].pid);
			}
      pselect.onchange();
}

function pchange(pid){
	var cselect = document.all.ADDR_CITY;
    if(cselect!=null){
    cselect.length=0;
	for(var i=0;i<CityArr.length;i++){
		  if(CityArr[i][1]==pid){
			var coption=new Option(CityArr[i][0],CityArr[i][0]);
			coption.cid=CityArr[i][1];
			cselect.add(coption);
		}
	  }
    }
}

function onlyDigit()
{
  if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
         || (window.event.keyCode == 13) || (window.event.keyCode == 46)
         || (window.event.keyCode == 45)))
  {
    window.event.keyCode = 0 ;
  }
}



function format(expr,decplaces){
  var str = ""+Math.round((expr)*(Math.pow(10,decplaces)));
  if(trim(str).toUpperCase()=="NaN".toUpperCase()||str==null||trim(str)==""){
    return "";
  }else{
    while(str.length<=decplaces){
      str = "0"+str;
    }
    var decpoint = str.length - decplaces;
	if(decplaces==0)
	return str.substring(0,decpoint);
	else
    return str.substring(0,decpoint)+"."+str.substring(decpoint,str.length);
  }
}

function trim(inputString) {
  var retValue = inputString;
  var ch = retValue.substring(0, 1);
  while (ch == " ") {
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
  }
  ch = retValue.substring(retValue.length-1, retValue.length);
  while (ch == " ") {
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1, retValue.length);
  }
  while (retValue.indexOf("  ") != -1) {
    retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
  }
  return retValue;
}

function checkallbox(_allbox){
for(var i=0;i<document.forms[0].elements.length;i++) {
    var e = document.forms[0].elements[i];
     if(e.type=='checkbox'&&e.select_index==_allbox.select_all_index) {
      if(_allbox.checked) e.checked=true; else e.checked=false;
      }
   }
}
function checkparentbox(childbox){
var tempboo=true;
//find the parentbox
for(var i=0;i<document.forms[0].elements.length;i++) {
  var e = document.forms[0].elements[i];
  if(e.type=='checkbox'&&e.select_all_index==childbox.select_index){
			for(var j=0;j<document.forms[0].elements.length;j++) {
				var ce = document.forms[0].elements[j];
				if(ce.type=='checkbox'&&ce.select_index==childbox.select_index){
    	  		tempboo = tempboo && ce.checked;
   		   }
		}
       	e.checked = tempboo;
		break;
    }
  }
}


function Check_checkbox(_index) {
      for (var i=0; i<document.forms[0].elements.length; i++) {
        var e = document.forms[0].elements[i] ;
        if(e.type == "checkbox" &&e.select_index==_index && e.checked)
          return true ;
      }
  alert("Please select delete record!") ;
  return false ;
}

function verifyData(check_form_etem)
  {
	  if(check_form_etem!=null&&check_form_etem.tagName=='FORM')
	  {
		  for(var i=0;i<check_form_etem.length;i++)
		  {
			  var temp_boolean=true;
			  var temp_comp=check_form_etem.elements[i];
			  var temp_type= temp_comp.type;
			  //alert(eval('document.all.'+temp_comp.name).length);
			  if(temp_comp!=null&&temp_comp.msg!=null)
			  {
                if(temp_type=='textarea'||temp_type=='text' || temp_type=='file'||temp_type=='password')
                 {
                   temp_boolean=temp_boolean && trim(temp_comp.value)!='';
                   //判断是否有isemail属性
                   if(temp_boolean && temp_comp.isemail!=null){
                     		temp_boolean = temp_boolean && ValidateEmail(temp_comp.value);
                   }
				   //判断是否有isdigit属性
                   if(temp_boolean && temp_comp.isdigit!=null){
							temp_boolean = temp_boolean && parseInt(temp_comp.value);
                   }
				 }
				 if(temp_type=='select-one')
				 {
					temp_boolean=temp_boolean && temp_comp.value!='0' && temp_comp.value!='';
				 }
				 if(!temp_boolean)
				 {
				 	alert(temp_comp.msg);
                   	setErrCssForElement(temp_comp);

					return false;
				 }
			  }
		  }

	  }
	  else
	  {
		alert('javaScript方法调用错误！')
	  }
	  return true;
  }

//设置错误的式样
function setErrCssForElement(temp_comp){
    var temp_type = temp_comp.type;
	if(temp_type=='textarea'||temp_type=='text' || temp_type=='file'||temp_type=='password'){
		temp_comp.className="input_active";
    }
		try {
		temp_comp.focus();
	} catch(e){};
}

function ValidateEmail(str)
{
var ret = false;
	if (typeof(str) != "undefined")
	{
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(str))
			ret = true;
	}
	return ret;
}

function ValidateLooseEmail(str){
var resultStr = str.replace(/ /gi, "");
var atIndex   = resultStr.indexOf("@");
var dotIndex  = resultStr.lastIndexOf(".");
	if( resultStr == "" || !isASCII(resultStr) || dotIndex == -1)
		return "";
	if ( resultStr.lastIndexOf("@") != atIndex || resultStr.charAt(atIndex+1) == ".")
		return "";
	if ( atIndex <= 0 || dotIndex < atIndex ||  dotIndex >= resultStr.length-1)
		return "";
	return resultStr;
}
function isEmail(str) {
  var pass = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) pass = 1;
	}
	if (!pass)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	var tempbool = !r1.test(str) && r2.test(str);

	if	(!tempbool)
	 alert(" Err! Please check your email format!");
	return (tempbool);
}

function DisableButton(){
 for(i=0;i<document.all.tags("INPUT").length;i++){
   tempcomp = document.all.tags("INPUT")[i]
    if(tempcomp.type == 'button'){
       tempcomp.disabled = true;
   }
 }
}
function setSelectIndex(temp_comp,_index){
   for(var j=0;j<temp_comp.length;j++)
    {
	     if(temp_comp.options[j].value==_index)
         {
 		 	temp_comp.selectedIndex=j;
   	      	break;
  	 	 }
	 }
}
function dispData(rd,type){
if(rd!=null){
var items=rd.split("^~`@");
if(type==3){
dispDataPolling(items);
return;
}
for (i = 0 ; i <items.length-1 ; i ++)
{
	var tItem=items[i].split("'|");
	if(type==1) createItem(tItem[0],tItem[1],tItem[2],tItem[3],tItem[4],tItem[5]);
  	if(type==2) createGood(tItem[0],tItem[1],tItem[2],tItem[3],tItem[4]);
	if(type==4) createNews(tItem[0],tItem[1],tItem[2]);
	if(type==5) showItems(tItem[0],tItem[1],tItem[2],tItem[3],tItem[4]);
	if(type==6) showGoods(tItem[0],tItem[1],tItem[2],tItem[3],tItem[4]);
	if(type==7) showNews(tItem[0],tItem[1],tItem[2]);
}}}
//生成投票
function dispDataPolling(args){
if(args==''){
	return
}
var tp=args[0].split("'|");
document.write('<div id="DPollingTitle">'+tp[1]+'</div>');
for (i = 1 ; i <args.length-1 ; i ++)
{
	var to = args[i].split("'|");
	document.write('<div id="DPollingOption"><input type=radio name=OPTION_ID id=POO'+i+' value="'+to[0]+'"><label for="POO'+i+'">'+to[1]+'</label></div>');
}
document.write('<input style="margin:3px;" name=Submit type=button pollingId="'+tp[0]+'" class=buttonBase onclick="goPolling(this);" value=提交投票>');
}
//生成新闻
function createNews(id,title,cdate){
	document.write('<div id="DNewsItem"><div id="DNewsItemTitle"><a href="javascript:openNews('+id+');">'+title+'</a></div><div id=DNewsItemDate >日期:'+cdate+'</div></div>');
}

function showNews(id,title,cdate){
	document.write('<div id="DNewsItem"><div id="DNewsItemTitle"><a href="javascript:openNews('+id+');">'+title+'</a></div></div>');
}

//生成商城商品
function createItem(icod,img,name,price,cy,days){
document.write('<div class="Item">');
document.write('<div class="ItemImg"><a href="http://www.123mall.com/iif.jsp?icod='+icod+'" target="_blank"><img src="http://www.123mall.com/'+img+'" border="0"></a></div>');
document.write('<div class="ItemName"><a href="http://www.123mall.com/iif.jsp?icod='+icod+'" target="_blank">'+name+'</a></div>');
document.write('<div class="ItemPrice">'+price+cy+'</div>');
document.write('<div class="ItemDays">剩余'+days+'天</div>');
document.write('</div>');
}
//生成本店商品
function createGood(id,img,name,price,cy){
document.write('<div class="Item">');
document.write('<div class="ItemImg"><a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank"><img src="../'+img+'" border="0"></a></div>');
document.write('<div class="ItemName"><a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank">'+name+'</a></div>');
document.write('<div class="ItemPrice">普通/会员<br>'+price+cy+'</div>');
document.write('</div>');
}

function showItems(id,img,name,price,cy){
document.write('<div class="Item">');
document.write('<div class="ItemImg"><a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank"><img src="../'+img+'" border="0"></a></div>');
document.write('<div class="ItemName"><a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank">'+name+'</a></div>');
document.write('<div class="ItemPrice">'+price+cy+'</div>');
document.write('</div>');
}


function showGoods(id,img,name,price,cy){
document.write('<div id="newArrivalItem">');
document.write('<a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank"><img class="ItemImg" src="../'+img+'" border="0"></a>');
document.write('<div class="ItemName"><a href="ViewGoodsInfo.jsp?GOOD_ID='+id+'" target="_blank">'+name+'</a></div>');
document.write('<div class="ItemPrice">'+price+cy+'</div>');
document.write('</div>');
}


//生成分类
function createClass(){
var arr = allClass;
for(i=0;i<arr.length;i++){
	tc=arr[i];
	if(tc[1]==0){
		document.write('<div id="DClassMain">');
		document.write('<div id="DClassParentName"><a href="GoodsSearch.jsp?PARENT_CLASS_ID='+tc[2]+'">'+tc[0]+'</a></div>');
		for(k=0;k<arr.length;k++){
			if(arr[k][1]==tc[2]){
				document.write('<div id="DClassChild"><a href="GoodsSearch.jsp?CLASS_ID='+arr[k][2]+'">'+arr[k][0]+'</a></div>');
			}
		}
		document.write('</div>');
	}
}
}
//查看新闻公共
function openNews(NewsId){
	window.open('ViewNews.jsp?NID='+NewsId,'NewsW','status=0,status=yes,resizable=yes,toolbar=yes,scrollbars=yes,width=750,height=600');
}

function showAD(){
   var interval_time=5 ;
	var focus_width=390;	// 图片宽度
	var focus_height=270;	// 图片高度
	var text_height=0;
	var text_mtop = 3;
	var text_lm = 0;
	var textmargin = text_mtop+"|"+text_lm;
	var textcolor = "#ffffff|0xffffff";
	var text_align= 'center'; //标题文字对齐方式(left、center、right)
	var swf_height = focus_height+text_height+text_mtop;
	var text_size = 14;
	var borderStyle="0|0xffffff|0";
	//var pics = "http://www.tvscn.com/medialib/subject/12409062008069750070.jpg|http://www.tvscn.com/medialib/subject/12409037369357390087.jpg|http://www.tvscn.com/medialib/subject/12409095925112920066.jpg|http://www.tvscn.com/medialib/subject/12409014126338120088.jpg|http://www.tvscn.com/medialib/subject/12409110091834490011.jpg";
	//var links = "http://jinriyixian.act.tvscn.com/|http://yingju.act.tvscn.com/news/newscontent/238863/1.htm|http://tvs1promo.act.tvscn.com/news/newscontent/238446/1.htm|http://zzmengpian.act.tvscn.com/news/newscontent/238188/1.htm|http://tvsnrcy.act.tvscn.com/news/newscontent/238888/1.htm";
	//var texts = "米线社区|tvs5|tvs4|tvs2|tvs3";
	var bgcolor= "#ffffff";
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="http://mediainfo.tvscn.com:8088/swf/hot_new.swf"> <param name="quality" value="high">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="bgcolor" value="'+bgcolor+'">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&textmargin='+textmargin+'&textcolor='+textcolor+'&borderstyle='+borderStyle+'&text_align='+text_align+'&interval_time='+interval_time+'&textsize='+text_size+'">');
	document.write('<embed src="http://mediainfo.tvscn.com:8088/swf/hot_new.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&textmargin='+textmargin+'&textcolor='+textcolor+'&borderstyle='+borderStyle+'&text_align='+text_align+'&interval_time='+interval_time+'&textsize='+text_size+'" menu="false" bgcolor="'+bgcolor+'" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');		document.write('</object>');
}



