//只可輸入整數
function CheckInteger()
{
	if ((event.keyCode < 48 || window.event.keyCode > 57) && event.keyCode != 13) 
	{
		event.returnValue = false;
		return false;
	}
	return true;
}

//只可輸入小數
function CheckDouble()
{
	if (event.keyCode == 46) 
	{
		if (document.activeElement.value.indexOf('.') >= 0) 
		{
			event.returnValue = false;
			return false;
		}
    } else if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 13)
    {
		event.returnValue = false;
		return false;
	}
	return true;
}

//本來是Enter鍵，改成Tab鍵
function AutoTab()
{
	if(event.keyCode==13)
	{
		event.keyCode=9;
	}
}

function LyShowModalDialog(strURL,intHeight,intWidth,obj){
  var strFeatures;
  var retValue;

  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  retValue=window.showModalDialog(strURL,obj,strFeatures);
  //retValue=window.open(strURL);  
  //alert(retValue);
  return retValue;
}

function CallSingleButton(obj,strQS){
  //var strURL="SingleSelect.aspx?" + strQS;
  var strURL="/LyEDM/SingleSelectIfram.aspx?" + strQS;
  var strValue;
  var inti;
  var arytemp;
  var myObject = new Object();
  myObject.ThisValue = obj.value;

  var strFeatures;
  var intHeight=500;
  var intWidth=530;
     
  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  strValue = window.showModalDialog(strURL,myObject,strFeatures);  
  //window.open(strURL);

  //strValue = LyShowModalDialog(strURL,500,530,myObject);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    if (window.form1.elements(arytemp[inti] + '_Text') == null)
    {
      window.form1.elements(arytemp[inti]).value=arytemp[inti+1];
    }else{
      window.form1.elements(arytemp[inti] + '_Text').value=arytemp[inti+1];
    }
  }
}

function CallSingleTreeView(strQS){
  var strURL="SingleTreeViewIfram.aspx?" 
  var strValue;
  var inti;
  var arytemp;
  var myObject = new Object();
  myObject.ThisValue = strQS;

  var strFeatures;
  var intHeight=500;
  var intWidth=530;
     
  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  strValue = window.showModalDialog(strURL,myObject,strFeatures);  

  //strValue = LyShowModalDialog(strURL,500,530,myObject);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    if (window.form1.elements(arytemp[inti] + '_Text') == null)
    {
      window.form1.elements(arytemp[inti]).value=arytemp[inti+1];
    }else{
      window.form1.elements(arytemp[inti] + '_Text').value=arytemp[inti+1];
    }
  }
}

function CallMultiButton(obj,strQS){
  var strURL="MultiSelectIfram.aspx?oldvalue=" + strQS;
  //var strURL="MultiSelectIfram.aspx?oldvalue=" + strQS;
  var strValue;
  var inti;
  var arytemp;
  var myObject = new Object();
  myObject.ThisValue = obj.value;
  //alert(myObject.ThisValue);
  
  var strFeatures;
  var intHeight=500;
  var intWidth=530;
     
  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  strValue = window.showModalDialog(strURL,myObject,strFeatures);  
  //strValue = LyShowModalDialog(strURL,500,530,myObject.ThisValue);
  
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    if (window.form1.elements(arytemp[inti] + '_Text') == null)
    {
      window.form1.elements(arytemp[inti]).value=arytemp[inti+1];
    }else{
      window.form1.elements(arytemp[inti] + '_Text').value=arytemp[inti+1];
    }
  }
}

function CallMultiProductButton(obj,strQS){
  var strURL="MultiSelectIfram.aspx?" + strQS;
  var strValue;
  var inti;
  var arytemp;
  var myObject = new Object();
  myObject.ThisValue = obj.value;
  
  var strFeatures;
  var intHeight=500;
  var intWidth=530;
     
  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  strValue = window.showModalDialog(strURL,myObject,strFeatures);  
  
  //strValue = LyShowModalDialog(strURL,500,530,myObject);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    if (window.form1.elements(arytemp[inti] + '_Text') == null)
    {
      window.form1.elements(arytemp[inti]).value=arytemp[inti+1];
    }else{
      window.form1.elements(arytemp[inti] + '_Text').value=arytemp[inti+1];
    }
  }
}


function CallPms04Button(obj,strQS){
  var strURL="Pms04SelectIfram.aspx?" + strQS;
  var strValue;
  var inti;
  var arytemp;
  var myObject = new Object();
  myObject.ThisValue = obj.value;
  
  var strFeatures;
  var intHeight=500;
  var intWidth=530;
     
  strFeatures="dialogheight:" + intHeight + "px;dialogwidth:" + intWidth + "px;center:yes;";
  strValue = window.showModalDialog(strURL,myObject,strFeatures);  
  
  //strValue = LyShowModalDialog(strURL,500,530,myObject);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    var strValue = arytemp[inti+1];
    if (window.form1.elements(arytemp[inti] + '_Text') == null)
    {
     if ( trim(strValue) != '' )
      {    
        window.form1.elements(arytemp[inti]).value=strValue;
      }else{
        window.form1.elements(arytemp[inti]).value='';
      }        
    }else{
     if ( trim(strValue) != '' )
      {    
        window.form1.elements(arytemp[inti] + '_Text').value=strValue;
      }else{
       window.form1.elements(arytemp[inti] + '_Text').value='';
      }       
    }

  }
}

/*
function CallDateButton(obj){
  var strURL="CalendarForm.aspx";
  var strValue;

  strValue=obj.value;
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";
  strValue = LyShowModalDialog(strURL + '?date=' + strValue,280,372);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";
  obj.value=strValue;
}
*/

function CallPictureButton(obj,strQS){
  var strURL="ImageSelect.aspx?" + strQS;
  var strValue;
  var inti;
  var arytemp;

  strValue = LyShowModalDialog(strURL,550,450);
  if ((strValue == null) || (trim(strValue) == ""))
    strValue="";

  arytemp=strValue.split("\x01");
  for (inti=0;inti<arytemp.length-1;inti=inti+2)
  {
    //alert(arytemp[inti] + '=' + arytemp[inti+1]);
    window.form1.elements(arytemp[inti] + '_Text').value=arytemp[inti+1];
  }
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//按 Enter 送出
function EnterKey(){

	if(event.keyCode==13){
			 		
		//抓取觸發事件的頁面
		var strPath;
		strpath = location.pathname.split('/');
		
        switch(document.activeElement.name){
            case "txt_userid_Text", "txt_paswrd":
                document.getElementById("btn_Login").focus();
                break;
            case "txt_SearchString_Text"://	QueryList搜尋
                document.getElementById("cmdSeek").focus();
                break;
            default:
                document.getElementById('cmdSave').focus();
                break;
        }
    }

}




