﻿/*
	M818 v3 Global Js
*/

/* Pager functions */

var MenuCount = 10;

function SetMenuCount(obj)
{
	MenuCount = obj
}

String.format = function() {
	if( arguments.length == 0 )
		return null;
		var str = arguments[0];
	for(var i=1;i<arguments.length;i++) {
		var re = new RegExp('\\{' + (i-1) + '\\}','gm');
		str = str.replace(re, arguments[i]);
	}
	return str;
}

function isInteger(str){
	var regu = /^[-]{0,1}[0-9]{1,}$/;
	return regu.test(str);
}

function getleng(targetid,tareaLength,maxNum)
                            {
                                if(document.getElementById(targetid).value.length>maxNum)
                                {
                                    document.getElementById(targetid).value = document.getElementById(targetid).value.substring(0,maxNum);
                                }
                                document.getElementById(tareaLength).innerHTML = document.getElementById(targetid).value.length + "/"+maxNum;
                            }

function goto_page(elementID,gotoPage,pageCount){

	var goto_num=jQuery("#"+elementID).val();

	if(isInteger(goto_num)&&(goto_num>0&&goto_num<=Number(pageCount))){

		 window.location.href=String.format(gotoPage,goto_num);

	}else{
		jQuery("#"+elementID).val("");
	}
}
 function isnicetag(obj,idobj)
	{
	    if(/^[a-zA-Z0-9]*$/g.test(obj)){   
	    document.getElementById(idobj).value = obj.toLocaleUpperCase();
	  }
	  else
	  {
	    document.getElementById(idobj).value=obj.substring(0,obj.length-1)
	
	  }
	}
	
function accountText(obj,idobj){
	 
	 	if(obj!=""){

	    if(obj.match("^[a-zA-Z0-9]+$")){   
		    
		  }
		  else
		  {
		    document.getElementById(idobj).value=obj.substring(0,obj.length-1)
		
		  }
		}
	}

  function TotalMoneyFormat(money,Num){
			    return Math.round(money*Math.pow(10,Num))/Math.pow(10,Num);
			} 

function  abda(oField)

            {
             var str=oField.value;
             var regexp =/^(\+|[0-9])([0-9])*([0-9]|\.){0,1}([0-9])*$/;
             var temp=str.match(regexp);
	      if(str!=null&&str!=""){
             if(temp&&Number(str)>0)
                {
                }
             else
                {
                 alert("您输入的格式不正确");
                }
		}
            }


function revalidate(value,targetid,sourceid,errorid){
            var price=jQuery("#"+targetid).val();
            if(Number(value)!=Number(price)){
                jQuery("#"+errorid).text("两次输入价格不一致");
                jQuery("#"+sourceid).val("");
            }else{
                jQuery("#"+errorid).empty();
            }
        }

function checkDate(theDate){
              var reg = /^\d{4}-((0{0,1}[1-9]{1})|(1[0-2]{1}))-((0{0,1}[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;  
              var result=true;
              if(!reg.test(theDate))
                result = false;
              else{
                var arr_hd=theDate.split("-");
                var dateTmp;
                dateTmp= new Date(arr_hd[0],parseFloat(arr_hd[1])-1,parseFloat(arr_hd[2]));
                if(dateTmp.getFullYear()!=parseFloat(arr_hd[0])
                   || dateTmp.getMonth()!=parseFloat(arr_hd[1]) -1 
                    || dateTmp.getDate()!=parseFloat(arr_hd[2])){
                    result = false
                }
              }
              return result;
            }

/*for all pages*/
function showSmallMenu(name,id,count){
	for(var i=0; i<count; i++){
		document.getElementById(name+"content"+i).style.display = "none";
	}

	for(var i=0; i<count; i++){
		document.getElementById(name+"tab"+i).className = "inactive";
	}

	document.getElementById(name+"tab"+id).className = "active";
	document.getElementById(name+"content"+id).style.display = "block";
}

/* for game */
function showMenu(id){
	for(var i=0; i<8; i++){
		document.getElementById("content"+i).style.display = "none";
	}
	for(var i=0; i<8; i++){
		document.getElementById("tab"+i).className = "inactive";
	}
	document.getElementById("tab"+id).className = "current";
	document.getElementById("content"+id).style.display = "block";
}


jQuery(document).ready(function(){

	jQuery(".stripe tr").mouseover(function(){
		jQuery(this).addClass("over");}).mouseout(function(){
		jQuery(this).removeClass("over");})

	jQuery(".stripe tr:even").addClass("alt");

	jQuery('.narrow1rowtable').find('td').each(function(i){
		if(i%2 == 0){
		  jQuery(this).addClass('tdtitle');
		}
	
		jQuery("#a1").click(function () {
                          jQuery("#AccountTypeValue").val("");
                          jQuery("#span2").toggle();
                          jQuery("#span1").toggle();
                        });
                       jQuery("#a2").click(function () {
                          jQuery("#AccountTypeValue").val("");
                          jQuery("#span1").toggle();
                          jQuery("#span2").toggle();
                        });								

		
	});

	jQuery('.detailtable').find('td').each(function(i){
		if(i%2 == 0){
		  jQuery(this).addClass('tdtitle');
		}
	});

	try{
		if (jQuery.getAllQueryStrings()["menuNum"].value != undefined){
			showSmallMenu('a',jQuery.getAllQueryStrings()["menuNum"].value, MenuCount);
		}
	}
	catch(e){}

});

//停机维护提醒 start start --------------------------------------------------
    
if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}

    
		function stopSererTips(){

			//set auto task
			$.cookie('alertedTimeList', "-1,", {expires:1});
		    setInterval("DoAlertTask()", 10000);
		}
		
		function DoAlertTask(){ 
		    // fetch timestamp to serviceOffline
		    if ($.cookie('timeToGoOffline') == null){
				$.getJSON("/OffLineAlert.aspx?jsoncallback=?", function(data){
					SetTimeStamp(data.secondsToOff);
				});
		    }else{

				// check timestamp & do alert
				DoOfflineAlert();
			}
		}

		function SetTimeStamp(seconds){
			var stamp = new Date();  
			stamp.setTime(stamp.getTime() + parseInt(seconds)*1000);
			$.cookie('timeToGoOffline', stamp, {expirssses:1});
		}

		function DoOfflineAlert(){

			//count time delta
			var now = new Date();
			var alertTimeList = new Array("1","2","3","4","5","10","30");
			var alertedStatus = $.cookie('alertedTimeList');
			var alertedTimeList = alertedStatus.split(',');
			var stamp = new Date($.cookie('timeToGoOffline'));
			var deltaMins = Math.floor(( stamp.getTime() - now.getTime() ) /1000/60).toString();

			//check alertTime list
			if (alertTimeList.indexOf(deltaMins) != -1){
				if (alertedTimeList.indexOf(deltaMins) == -1){
					//alert, when found in list
					//alert("亲爱的汇畅用户，系统将在19:00开始一次版本更新，届时将出现短时间内页面无妨访问的现象，预计持续时间为10分钟。请勿在19点进行任何交易相关的操作，以免造成损失。带来不便，尽请谅解！（汇畅网运营团队）");
				    alert("亲爱的汇畅用户，系统将在 " + deltaMins + " min(s). 后有一次版本更新,届时将出现短时间内页面无妨访问的现象，预计持续时间为10分钟。请勿在此期间进行任何交易相关的操作，以免造成损失。带来不便，尽请谅解！（汇畅网运营团队）;");
					//update alerted time list
					$.cookie('alertedTimeList', $.cookie('alertedTimeList') + deltaMins + ',', {expires:1});
				}
			}
		}
		
		//停机维护提醒 start end --------------------------------------------------
		
		 function priceFormat(price){
		                        if(price.value=="")
		                        {
		                            return;
		                        }
                                if(/^(\+|[0-9])([0-9])*([0-9]|\.){0,1}([0-9])*$/.test(price.value)){
                                    
                                }else{
                                    alert("请输入正确的格式");
                                    price.value="";
                                }
                            }
          
          //多个tab收索问题 start  --------------------------------------------------           
          jQuery(function() { 
             	        
             	        //为菜单栏的超连接绑定清除cookie
             	        
             	        jQuery(".tab li ul li a").click(function(){
                            jQuery.cookie("tabsIndex",null);
                            }
                        );
             	        
             	        var tabsIndex=null;
             	        
//             	        try{
//             	            tabsIndex=jQuery.getAllQueryStrings()["tabsIndexTemp"].value;
//             	        }catch(e){
//             	            tabsIndex=null;
//             	        } 
             	        if(tabsIndex==null||tabsIndex==""){
             	                try{
             	                    tabsIndex=jQuery.cookie("tabsIndex"); 
             	                }catch(e){
             	                    tabsIndex=0;
             	                }
             	        }
             	         if(tabsIndex==null||tabsIndex==""){
     	                    tabsIndex=0;
     	                }
             	        
                        $('#tabmenu > ul').tabs({selected: tabsIndex});
                        //jQuery.cookie("tabsIndex",null);
                      }
                    );
                    
                function checkTabsIndex(index){ 
                    jQuery.cookie("tabsIndex",index);
                }
                
                //按按供货者统计页面调用 
//                 function checkTabsIndexTemp(index){
//                    checkTabsIndex(index);
//                    jQuery("#tabsIndexHidden").val(index);
//                }
               //Menu.vm页面调用 点菜单栏时清空cookie中的tabsIndex
               
               
              
            //多个tab收索问题 end  --------------------------------------------------      
            
            
            //Complaints.vm页面调用
            
            function complaintsFormsubmit(){
                if(jQuery("[id='IsReimburse0'][checked]").val()){
                     var ReimburseMoney=jQuery("#ReimburseMoney").val();
                     if(/^(\+|[0-9])([0-9])*([0-9]|\.){0,1}([0-9])*$/.test(ReimburseMoney)){
                        if(Number(ReimburseMoney)<0.001||Number(ReimburseMoney)>=100000){
                            alert("金额必须大于0.001或小于100000"); 
                            return false;
                        }else{
                            return true;
                        }
                     }else{
                        alert("请输入正确的格式");
                        jQuery("#ReimburseMoney").val("");
                        return false;
                     }
                }
                return false;
         } 
         
       //UserManager.vm 解锁功能调用
       
       function selectDealer(){
                    if(jQuery("[name='UserID'][checked]").val()){  
                        var temp=0;
                        for(i=0;i<document.all('UserID').length;i++){ 
                           if(document.all('UserID')[i].checked){
                                temp=temp+1;
                           }
                        }
                        
                        if(temp>1){
                            alert("只能选择一个帐号");
                            
                        }else{
                            jQuery("#DealerIDRemove").val(jQuery("[name='UserID'][checked]").val());
                            tb_show('帐户解锁','TB_inline?height=100&width=300&inlineId=trans2',false); 
                        }
                    }else{
                        alert("必须选中一个经销商");
                    }
                }
                
                 function  CheckPass1(Password)
                   {
                     var OperatorID=jQuery("#OperatorID1").val();
                     jQuery.getJSON("M818.json",{MethodName:"Dealer.ValidatePassword",UserID:OperatorID,Password:Password,random:(new Date()).getTime()},
                     function (msg){
                       if(msg==false)
                       {
                        alert("请输入正确的密码");
                        jQuery("#PassWord1").val("");
                       }
                     
                     });
                   }      
                   
                   
           //
           
           function passUnClocked(OperatorID){
                    if(jQuery("[name='UserID'][checked]").val()){  
                        var temp=0;
                        for(i=0;i<document.all('UserID').length;i++){ 
                           if(document.all('UserID')[i].checked){
                                temp=temp+1;
                           }
                        }
                        
                        if(temp>1){
                            alert("请选择员工帐号");
                            
                        }else{
                            var DealerID=jQuery("[name='UserID'][checked]").val();
                            jQuery.getJSON("M818.json",{MethodName:"Dealer.RemovePasswordLockDealer",OperatorID:OperatorID,DealerID:DealerID,random:(new Date()).getTime()},
                            function (json){
                               if(Number(json)==3){
                                    alert("操作成功");
                               }else{
                                    alert("操作失败");
                               }
                            }
                        );
                        }
                    }else{
                        alert("请选择员工帐号");
                    }
                }
           //同时发送至多个DealerID的站内信
           function DealerIDValidate(){
                var DealerIDS=jQuery("#ToDealerIDs").val();
                var Domain=jQuery("#Domain").val();
                if(Domain!=null&&Domain!=""&&DealerIDS!=null&&DealerIDS!=""){
                    if(DealerIDS.split(";").length>=31){
                        alert("一次最多只能发送至30个商户");
                        jQuery("#ToDealerIDs").val("");
                    }else{
                        jQuery.getJSON("M818.json",{MethodName:"Message.ValidateReciverID",UserDomain:Domain,ReceiverID1:DealerIDS,random:(new Date()).getTime()},
                                function (json){
                                        if(json!=null){
                                            jsons=json.split(",");
                                            jQuery("#ToDealerIDs").val(jsons[0]);
                                            jQuery("#ToDealerNames").text(jsons[1]); 
                                            if(jsons[2]!=null&&jsons[2]!=""){
                                                alert("帐号 : "+jsons[2] +" 不正确");
                                            }
                                            
                                        }
                                    }
                                );
                    }
                }
           }
           
           
           //------------------------------message ---------------------------------------------
           
           
           //转发信息调用
                    
                     function domainValidate()
           
                        {
                            if(jQuery("#Domain").val()=="")
                            {
                              alert("请选择一种域类型");
                              return false;
                            }
                            return true;
                        }
           
           //js 限制文本框特殊字符 目前用于商品         
           
           function textValidate(textid,value){ 
                jQuery("#"+textid).val(value.replace(/[\\]/g,'/'));//用正斜杠替换反斜杠
           }
           
           //登陆令牌显示js
           function EkeyInputTypeFocus(InputObj) {
                if(InputObj.value == "没有则不填"){
					document.getElementById("EkeyInputDiv").innerHTML = "<input size='12' id='rePass' name='ekeyOpt' type='password' />";
					document.getElementById("rePass").focus();
					document.getElementById("rePass").focus();
                }
           }