//Function: Change Enter To Tab on Form
//Parameter:
//          LastControl--the last input control's ID
//          defaultbutton--the default submit button' ID
//          formID--the Form's ID
//Designer: wubin
//DesignTime:2006-12-26
//Warnning:you must use 'return' keyword before this function name where you invoted.
function KeyPress(LastControl,defaultbutton,formID)
{
    var obj;
    obj = document.activeElement;
    
    if(obj.name==LastControl)
    {   if(event.keyCode==13)
        {
            if(checkInput(formID))
            { 
                return WebForm_FireDefaultButton(event, defaultbutton)
            }
            else
            {
               return false;
            }
        }
    }
    else
    {
        if(event.keyCode==13 &&event.srcElement.type!='file'&&event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!='textRegion' && event.srcElement.type!='') 
        event.keyCode=9; 
    }
   
}

function KeyPressForLayer(LastControl,defaultbutton,formID)
{
    var obj;
    obj = document.activeElement;
   // alert(document.getElementById('divNoticeInfo').style.visibility);
    if(document.getElementById('divNoticeInfo').style.visibility=='visible')
    {
   // alert(document.getElementById('divNoticeInfo').style.visibility);
     //  obj.blur(); 
      HiddenMe();
      if(event.keyCode==13)
      {
       HiddenMe();
       }
      return false;
    }
    if(obj.name==LastControl)
    {   if(event.keyCode==13)
        {
            if(checkInputForTip(formID))
            { 
                return WebForm_FireDefaultButton(event, defaultbutton)
            }
            else
            {
               return false;
            }
        }
    }
    else
    {
        if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!='textRegion' && event.srcElement.type!='') 
        event.keyCode=9; 
    }
   
}
//Show tip layer
 function ShowTipLayer()
 {
	        document.getElementById('divNoticeInfo').style.display='';
	        document.body.style.overflow='hidden';
	       // document.getElementById('lblNoticeInfo').innerHTML=message;
}
function ShowTipLayerParm(message)
{
        document.getElementById('divNoticeInfo').style.display='';
        document.getElementById('lblNoticeInfo').innerHTML=message;
        document.body.style.overflow='hidden';
}
function HiddenTipLayer()
{
   document.getElementById('divNoticeInfo').style.display='none';  
   document.body.style.overflow='';
}
//2007-04-15 add by wubin
function OpenUpdateWindow_H(id,url,width,height)
{
	//Open windows
	var rnd = Math.random();
	var rtn = window.showModalDialog(url + "?id=" + id + "&TemporaryParms=" + rnd,
		"edit",
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:no");
	if(rtn == 1)
	{
		document.forms[0].submit();
		//location.href= location.href;
		//location.reload();
	}
}


function OpenThridCalendar(idname, postBack)
{
	var screenleft = (screen.availWidth - 250)/2;
	var screentop = (screen.availHeight - 250)/2;
	popUp = window.open('../../../COM/TimeControl.aspx?SubmitFormName=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		"width=250 ,height=250,left=" + screenleft+",top=" + screentop);
}

function OpenTwoCalendar(idname, postBack)
{
	var screenleft = (screen.availWidth - 250)/2;
	var screentop = (screen.availHeight - 250)/2;
	popUp = window.open('../../COM/TimeControl.aspx?SubmitFormName=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		"width=250 ,height=250,left=" + screenleft+",top=" + screentop);
}

function OpenOneCalendar(idname, postBack)
{
		var screenleft = (screen.availWidth - 250)/2;
		var screentop = (screen.availHeight - 250)/2;
	popUp = window.open('../COM/TimeControl.aspx?SubmitFormName=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		"width=250 ,height=250,left=" + screenleft+",top=" + screentop);
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}	

function __doPostBack(eventTarget, eventArgument) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["form1"];
	}
	else {
		theform = document.Form1;
	}
	//********************************************
	//the following 2 centences is very important
	//for a window created by dialogue
	//********************************************
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}		
function OpenAddWindow(url,width,height)
{
	//
	var rnd = Math.random();
	window.showModalDialog(url + "?TemporaryParms=" + rnd,
		"add",
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:no");
}

function OpenLogin(url,width,height)
{
	//
	var rnd = Math.random();
	window.showModelessDialog(url + "?TemporaryParms=" + rnd,
		"add",
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:no");
}

function ModelesslWindowForAdd(id,url,width,height)
{
	//
	var rnd = Math.random();
	var rtn = window.showModalDialog(url + "?id=" + id + "&TemporaryParms=" + rnd,
		"add",
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:no;unadorned:yes");
	if(rtn == 1)
	{
		document.forms[0].submit();
		//location.href= location.href;
		//location.reload();
	}
}

function OpenAddWindowModal_wusg(id,url,width,height)
{
	//
	var rnd = Math.random();
	var rtn = window.showModalDialog(url + "?id=" + id + "&TemporaryParms=" + rnd,
		"add",
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:yes;unadorned:yes");
	if(rtn == 1)
	{
		document.forms[0].submit();
		//location.href= location.href;
		//location.reload();
	}
}
function KeyDownToNext(LastControl)
{
    var obj;
    obj = document.activeElement;
  
     if(document.getElementById('divNoticeInfo').style.visibility=='visible')
    {
   // alert(document.getElementById('divNoticeInfo').style.visibility);
     //  obj.blur(); 
      HiddenMe();
      if(event.keyCode==13)
      {
       HiddenMe();
       }
      return false;
    }
    
    if(obj.name==LastControl)
    {   if(event.keyCode==13)
        {
            if(checkInputForTip('form1'))
            { 
                return WebForm_FireDefaultButton(event, 'btnSave')
            }
            else
            {
               return false;
            }
        }
    }
    else
    {
        if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!='textRegion' && event.srcElement.type!='') 
        event.keyCode=9; 
    }
   
}
//Return to Previous Page
function GoBack()
{ 
	window.history.back();
}	
//checking the inputed have single quotes.
function CheckQ(strInput)
{
	var ilength=strInput.length;
	for(i=0;i<ilength;i++)
	{  
		if(strInput.charCodeAt(i)==39)
		{
			return false; 	
		}
	}	
	return true;
}

//checking the inputed is validate Chinese.
function IsChineseStr(Instr)
{
	return (Instr)?(!/[^\u4E00-\u9FA0]+/.test(Instr)):false;
}

//----------------------------------------------------------
//checking the inputed is validate URL
//----------------------------------------------------------
function isURL(strInput)
{
	var strURL="^http://";
	var strURL2="^https://";
	var re = new RegExp(strURL);
	var re2=new RegExp(strURL2);
	if(strInput.search(re)!=-1 || strInput.search(re2)!=-1 )
	{
		return true;
	}
	else
	{
		return false;
	}
}
//checking the inputed is validate MailBox.
function isEmail(s)
{
		if (s.length > 128)
		{
				return false;
		}
		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|cn|CN)$";
		var re = new RegExp(regu);
		if (s.search(re) != -1)
		{
			return true;
		}
		else
		{
			return false;
		}
}
//checking the inputed data is validate telephone number.
function checkphone(sIn){
//try{
//	if (!sIn) return false;
//	var s=sIn.split(";");
//	var re1=/^0\d{2}\-\d{8}$/;
//	var re2=/^0\d{3}\-\d{7}$/;
//	var re3=/^0?13\d{9}$/;
//	var re4=/^\d{7,8}$/;
//	if (s[0]) flag1=re1.test(s[0]) || re2.test(s[0]) || re3.test(s[0]) || re4.test(s[0]);
//	if (s[1]) flag2=re1.test(s[1]) || re2.test(s[1]) || re3.test(s[1]) || re4.test(s[1]);
//	return s[1]?(flag1 && flag2):flag1;
//	}
//	catch(e){}
    var reg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}((-\d{3})?)$/;//区号3到4位,号码7到8位,分基号3位
    return reg.test(sIn);
}


function checkMobileNO(inMobileNo)
{ 
    var a = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15[89]\d{8}$/ ; 
    if( !inMobileNo.match(a) )
    {
//        alert("不符合");
        return false;
    }
    else
    { 
//        alert("符合");
        return true; 
    } 
} 


//---------------------------------------------------------
//checking the inputed data's length
//---------------------------------------------------------
function checklength(strInput,intLength)
{
	var j = 0;
	for (var i=0; i<strInput.length;i++)
	{
		if (strInput.substr(i,1).charCodeAt(0)>255)
			j = j + 2;
		else
			j++;
	}	
	if(j>intLength)
		return false;
	else
		return true; 
}

//---------------------------------------------------------
//get the length of inputed data
//---------------------------------------------------------
function getlength(strInput)
{
	var j = 0;
	for (var i=0; i<strInput.length;i++)
	{
		if (strInput.substr(i,1).charCodeAt(0)>255)
			j = j + 2;
		else
			j++;
	}	
	return j;
}

//---------------------------------------------------------					
// Function：checking string is validate date type					
// Parameters：					
//---------------------------------------------------------
function isDateTime(timeStr)
{
var timeArray;
	timeArray=timeStr.split("-");
	if (timeArray.length<2||timeArray.length>3)
	{
		return false;
	}
	if (timeArray.length==2)
	{
		timeArray[2]=1
	}
if (!isDigital(timeArray[0]))
	{
		return false;
	}
	if (!isDigital(timeArray[1]))
	{
		return false;	
	}
	if (!isDigital(timeArray[2]))
	{
		return false;
	}

		
	if (!isValidDate(timeArray[0],timeArray[1],timeArray[2]))
		{
		return false;
	}	
	return true;
}
//----------------------------------------------------------
// function：check the string is validate digital					
// Parameters：strInput					
//---------------------------------------------------------
function isDigital(strInput)
{
	var j = 0;
	var i;
	var TemporaryParms;
	for (var i=0;i<strInput.length;i++)
	{
		TemporaryParms = strInput.substr(i,1);
		if (!((TemporaryParms >= '0') && (TemporaryParms <= '9')))
			return false;
	}
	
	return true;
}
function IsRealNumber(strInput)
{   
    //是否是实数
    var reg = /^(-|\+)?\d+(\.\d+)?$/;  
    return reg.test(strInput);
}   
//-----------------------------------------------------------
//function：check the data which user input is validate post code.
//Parameters：strInput,checked string
//-----------------------------------------------------------
function isPostCode(strInput)
{
	if(strInput.length!=6)
	{
		return false
	}
	else
	{
		if(!isDigital(strInput))
		{
			return false;
		}
	
	}
	return true;

}
//---------------------------------------------------------
// Function：Check the parameters is date
//---------------------------------------------------------
function isValidDate( year, month, day )
{
	year  = parseInt(year,10);
	month = parseInt(month,10);
	day   = parseInt(day,10);
	if (year<0||year>9999)
	{ 
		return (false);
	}	
	if (month<1||month>12)
	{
		return (false);
	}	
	if ( month==4 || month==6 || month==9 || month==11 )
	{ if ( day < 1 || day > 30 )
	{ 
	return (false);
	}
	}
	else
	{ if ( month!=2 )
	{ if ( day < 1 || day > 31 )
	{  
		return (false);
	}
	}
	else
	{  month == 2
	if ( ( year % 100 ) != 0 && (year % 4 == 0) || ( year % 100 ) == 0 && ( year % 400) == 0 )
	{ if ( day > 29 )
		{ 
			return (false);
		}
	}
	else
	{ if ( day > 28 )
		{ 
		return (false);
		}
	}
	}
	}
	return (true);
}
	
	function PopInfo(Message)
{
	if(Message != ""&&Message != null)
	{
		alert(Message);				
	}
}
//Get Object by ID
function FindHTMLObjectByID(ControlID) { 	
	var obj;
	if (ControlID) {
		if (document.layers) {
			obj = document.layers[ControlID];
		} else if (document.all) {
			obj = document.all(ControlID);
		} else if (document.getElementById) {
			obj = document.getElementById(ControlID);
		}        
		return obj;
}
obj = null;
return obj;
}

function selectid(objChek)
{
    
	var id = objChek.id;
	
	var objhdDelID = FindHTMLObjectByID("ctl00_hdDelID");
	if(objhdDelID != null)
	{   
		if(objhdDelID.value == "")
			objhdDelID.value = id + ",";
		else
		{
			if(objhdDelID.value.indexOf(id) != -1)
			{
				if(!objChek.checked)
				{
					objhdDelID.value = objhdDelID.value.replace(id+",","");
					
				}
			}
			else
			{
			    objhdDelID.value = objhdDelID.value + id + ",";
			   
			}
		}
	}
}

function checkSet()
{
	var delID = FindHTMLObjectByID("ctl00_hdDelID").value;
	if(delID != "")
    {
		var checkArray = new Array();
		checkArray = document.all.tags("INPUT");
	    
		for(var i=0; i<checkArray.length; i++)
		{	
		    //alert(checkArray[i].value);			   
			if(delID.indexOf(checkArray[i].id) != -1)
			{
			   checkArray[i].checked = true;
			}
		}
    }
}	
//Check all the checkbox in delete collum.
//Notice:
//      1.You must place a Hidden which named 'objhdDelID' in the Form
//      2.add onclick event to the checkbox which control all the checkbox in GridView 
//Designer:wubin
//DesignTime:2006-12-26
function chkAll(objectChkAll)
{
    var objhdDelID = FindHTMLObjectByID("objhdDelID");
    var delID = objhdDelID.value;
    var checkArray = new Array();
    checkArray = document.all.tags("INPUT");
   
    if(objectChkAll.checked)
    {			
	    for(var i=0; i<checkArray.length; i++)
	    {	
	        if(checkArray[i].type=="checkbox")
	        {
	            if(checkArray[i].id.indexOf("GridView") != -1)
	            {
	                checkArray[i].checked = true;
		          		   
		            if(delID.indexOf(checkArray[i].id) == -1)
		            {
		               delID = delID + checkArray[i].id + ",";
		            }
		        }
		   }
	    }
	    
    }
    else
    {
	     for(var i=0; i<checkArray.length; i++)
	    {	
	    if(checkArray[i].type=="checkbox")
	    {
	         if(checkArray[i].id.indexOf("GridView") != -1)
	        {
	            checkArray[i].checked = false;
		        		   
		        if(delID.indexOf(checkArray[i].id) != -1)
		        {
		           delID = delID.replace(checkArray[i].id+",","");
		        }
		    }
	    }
	    }
    }
    objhdDelID.value = delID;
    	
}

//reversed selecting the  checkbox in delete collum.
//Notice:
//      1.You must place a Hidden which named 'objhdDelID' in the Form
//      2.add onclick event to the checkbox which control all the checkbox in GridView 
//Designer:wubin
//DesignTime:2006-12-26
function ReversedCheck(objectChkAll)
{
    var objhdDelID = FindHTMLObjectByID("objhdDelID");
    var delID = objhdDelID.value;
    var checkArray = new Array();
    checkArray = document.all.tags("INPUT");
	    for(var i=0; i<checkArray.length; i++)
	    {	
	        if(checkArray[i].type=="checkbox")
	        {
	            if(checkArray[i].id.indexOf("GridView") != -1)
	            {
	                //If have checked then cancel selected and clean the value in objhddelid
	                if(checkArray[i].checked==true)
	                {
	                    checkArray[i].checked=false;
		                if(delID.indexOf(checkArray[i].id) != -1)
		                {
		                   delID = delID.replace(checkArray[i].id+",","");
		                }
		            }
		            else
		            {
		                checkArray[i].checked=true;
		                if(delID.indexOf(checkArray[i].id) == -1)
		                {
		                   delID = delID + checkArray[i].id + ",";
		                }
		            
		            }
		        }
		   }
	    }

    objhdDelID.value = delID;
   
}
//Open mode window which have Refreshed and Scrolled properties.
function OpenWindowModal(id,url,width,height,isScroll)
{
	//Open a new window when have two layers.
	
	var rnd = Math.random();
	var rtn;
	if(isScroll == 'true')
	{
	rtn = window.showModalDialog(url + "?id=" + id + "&TemporaryParms=" + rnd,
		"add",				
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:yes;unadorned:yes");
	}
	else
	{
		rtn = window.showModalDialog(url + "?id=" + id + "&TemporaryParms=" + rnd,
		"add",				
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;resizable:no;status:no;scroll:no;unadorned:yes");
	}
	if(rtn == 1)
	{
		document.all.hdFresh.value = rtn;
		document.forms[0].submit();					
	}
}
function HiddenMe(Control)
{
   var obj=FindHTMLObjectByID(Control);
   obj.style.visibility='hidden';
    
}		
