﻿
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function dialog_close(t, mes, w, h, ok_script){
    Dialog.alert(mes, 
        {
            windowParameters: {
                className: "alphacube", width: w, height: h
            },
            title: t,
            okLabel: "确定", 
            ok: function(win) {
                win.close();
                eval(ok_script);
                 if(mes=="您已经注册成功"){
                 
                  window.location.href=redUrl;
            }
            }
        }
    );
}


function dialog_ok_cancel(t, mes, w, h, ok_script, cancel_script){
    Dialog.confirm(mes, 
        {
            windowParameters: {
                className: "alphacube", width: w, height: h
            },
            title: t,
            okLabel: "确定",
            cancelLabel: "取消",
            ok: function(win){
                win.close();
                eval(ok_script);
            }, 
            cancel: function(win){
                win.close();
                eval(cancel_script);
            }
        }
    );
}

var validation = {
    "isphone" :  function(passed){
	    if(passed==""){
		    return false;
	    }
	    for(i=0;i<passed.length;i++){
		    if(passed.charAt(i)=='-'){
			    if((i!=3&&i!=4)||(i==passed.length-1)){
				    return false;
			    }
		    }
		    else if(passed.charAt(i)<"0"){
			    return false;
		    }
		    else if(passed.charAt(i)>"9"){
			    return false;
		    }
	    }
	    return true;
    },
    "ismail" : function(s){
        var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
        var re = new RegExp(regu);
        if(s.search(re) != -1){
	        return true;
        }
        else{
	        return false;
	    }
    },
    "isint" : function(input){
        var regu = "^-?[1-9]\\d*$";
        var re = new RegExp(regu);
        if(s.search(re) != -1){
	        return true;
        }
        else{
	        return false;
	    }
    },
    "isfloat" : function(input){
        var regu = "^[1-9]\\d*(\\.\\d+|)$";
        var re = new RegExp(regu);
	    if(input.search(re) != -1){
		    return true;
	    }
	    else{
		    return false;
		}
	},
	"isdate" : function(str){
      var   datestr   =str;   
      var   lthdatestr=str.length   ;     
      var   tmpy="";   
      var   tmpm="";   
      var   tmpd="";   
      var   status;     
      status=0;     
      var   status1;     
      status1=0;   
        
      if   (datestr=="")   return   true;   
        
      for   (i=0;i<lthdatestr;i++)   {     
      if   (datestr.charAt(i)==   '/')   {     
      status++;     
      }     
        
      }   
      if   (status>2||status==1)   {   
      return   false;     
      }     
      for   (i=0;i<lthdatestr;i++)   {     
      if   (datestr.charAt(i)==   '-')   {     
      status1++;     
      }     
        
      }   
      if   (status1>2||status1==1)   {     
      return   false;     
      }     
        
      status=0;     
      datestr   =   replace(datestr,   "-",   "/")   
        
      if   (lthdatestr==   0)   {   
      return   false;     
      }   
      for   (i=0;i<lthdatestr;i++)   {     
      if   (datestr.charAt(i)==   '/')   {     
      status++;     
      }     
      if   (status>2)   {     
      return   false;     
      }     
        
      if   ((status==0)   &&   (datestr.charAt(i)!='/'))   {     
      tmpy=tmpy+datestr.charAt(i)     
      }     
      if   ((status==1)   &&   (datestr.charAt(i)!='/'))   {     
      tmpm=tmpm+datestr.charAt(i)     
      }     
      if   ((status==2)   &&   (datestr.charAt(i)!='/'))   {     
      tmpd=tmpd+datestr.charAt(i)     
      }     
      }     
      year=new   String   (tmpy);     
      month=new   String   (tmpm);     
      day=new   String   (tmpd)     
      if   ((tmpy.length!=4)   ||   (tmpm.length>2)   ||   (tmpd.length>2))   {     
      return   false;     
      }     
      if   (!((1<=month)   &&   (12>=month)   &&   (31>=day)   &&   (1<=day))   )   {     
      return   false;     
      }     
      if   (!((year   %   4)==0)   &&   (month==2)   &&   (day==29))   {   
      return   false;     
      }   
      if   ((month<=7)   &&   ((month   %   2)==0)   &&   (day>=31))   {     
      return   false;     
      }     
      if   ((month>=8)   &&   ((month   %   2)==1)   &&   (day>=31))   {     
      return   false;     
      }     
      if   ((month==2)   &&   (day==30))   {     
      return   false;     
      }     
      return   true;  
    }
}
function replace(str, oldStr, newStr)
{   
    var buffer = "";   
    var length = oldStr.length;   
    var beginIndex = 0;                         
    if(length > 0)
    {   
        index = str.indexOf(oldStr);   
        while(index >= 0)
        {   
            buffer = buffer + str.substring(beginIndex, index); 
            buffer = buffer + newStr;
            beginIndex = index + length;   
            index = str.indexOf(oldStr,   beginIndex);
        }   
    }   
    buffer = buffer + str.substring(beginIndex);   
    return buffer;   
}
