﻿//*************************************************
// JScript File
// created  : kpo 
// modified : kpo 14/06/2006 adding rEplace
// modified : kpo 26/06/2006 adding randomid,guid
// modified : kpo 06/09/2006 addBookmarkForBrowser
// modified : sno 28/09/2006 adding EmailCheck
// modified : KPO 29/11/2006 adding gettodaystring
//*************************************************
//
//today
function _GetToDayString()
{
	return _FormatDateString('','','')
}
function _FormatDateString(pYear,pMonth,pMonthDay)
{
	var ppyear = parseFloat(pYear)
	var ppmonth = parseFloat(pMonth)
	var ppday = parseFloat(pMonthDay) 
	var istoday = new Date()				

	ppyear = isNaN(ppyear)?istoday.getFullYear():ppyear
	ppmonth = isNaN(ppmonth)?istoday.getMonth()+1:ppmonth
	ppday = isNaN(ppday)?istoday.getDate():ppday

 	var disp_Month = (ppmonth < 10) ? "0" + ppmonth : ppmonth;
 	var disp_Day = (ppday  < 10) ? "0" + ppday  : ppday;
	document.getElementById(_C_Month).selectedIndex = ppmonth -1;
	return disp_Day + "/" + disp_Month + "/" + ppyear;
 }	
 
 
  function FormatDateMMDDYYYY(mdate)
		 {
		    var mdate  =  mdate.split("/");
			var ppyear = parseFloat(mdate[2])
			var ppmonth = parseFloat(mdate[1])
			var ppday = parseFloat(mdate[0])
			
			var istoday = new Date()				

			ppyear = isNaN(ppyear)?istoday.getFullYear():ppyear
			ppmonth = isNaN(ppmonth)?istoday.getMonth()+1:ppmonth
			ppday = isNaN(ppday)?istoday.getDate():ppday

		 	var disp_Month = (ppmonth < 10) ? "0" + ppmonth : ppmonth;
		 	var disp_Day = (ppday  < 10) ? "0" + ppday  : ppday;
			document.getElementById(_C_Month).selectedIndex = ppmonth -1;
			return  disp_Month + "/" + disp_Day + "/" + ppyear;
		 }	
		 
		 




 
 
 	
//end xml loader
//change combo
function DochangeCposCombo(mCombo,mSelectText)
{
    try{
    document.getElementById(mCombo).value = mSelectText
    Changepos1(mCombo)
    }catch(e){
    }
}    
 
//focus !
function domyFocus(mycontrol)
{
  try{
    mycontrol.focus()
  }catch(e){
  }
}
//replace
function rEplace(mdata,mfind,mreplaced)

{
   var mreturn
   var mindex=0
   mreturn = mdata
   if (mreturn == null) return ''   
   if (mreturn == "") return mdata

   mindex = mreturn.indexOf(mfind,mindex) 
   while (mindex >= 0){
     mreturn = mreturn.substring(0,mindex) + mreplaced + mreturn.substring(mindex+mfind.length,mreturn.length)
     mindex = mreturn.indexOf(mfind,mindex)
   }
   return mreturn
}
//randomid
function RaNdomID()
{
   var mdate = new Date();
   return Math.floor(Math.random() * mdate.getDate()).toString(16)+ mdate.getMonth().toString(16) + 
        mdate.getFullYear().toString().substring(0,2).toString(16) + mdate.getFullYear().toString().substring(2,4).toString(16) + 
        mdate.getHours().toString(16) + mdate.getMonth().toString(16) + mdate.getSeconds().toString(16) + 
        Math.floor(Math.random() * mdate.getMilliseconds()).toString(16)
}
function getGuid()
{
var theguid = "{"; 
for (var i = 1; i <= 32; i++) 
 { 
 var n = Math.floor(Math.random() * 16.0).toString(16); 
 theguid += n; 
 if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) 
  theguid += "-"; 
 } 
theguid += "}"; 
return theguid   
}
//remove space
function dotrim(mtextstring)
{
    if (mtextstring == null) return ''
    if (mtextstring == '') return ''
    
    var icrc
    var icrc2
    var mtext
    mtext = mtextstring
    icrc = mtext.length
    icrc2=0	    
    while (mtext.substring(mtext.length-1,mtext.length) == ' '){
        mtext = mtext.substring(0,mtext.length-1)
        icrc2++;
        if (icrc2 > icrc) break;
    }    
    icrc = mtext.length
    icrc2=0	    
    while (mtext.substring(0,1) == ' '){
        mtext = mtext.substring(1,mtext.length)
        icrc2++;
        if (icrc2 > icrc) break;
    }    
    return mtext
}
//validate email
function validateemail(memail0) 
{  
   var memail = new String(memail0)
   if (dotrim(memail) == "") return true;
   var breturn = false
   var ioneindex=0
   var itmpindex=0
   var iatindex   
   iatindex = memail.indexOf("@")
   ioneindex = memail.indexOf(".",ioneindex)
   itmpindex = ioneindex

   while (itmpindex > 0)
   {
     itmpindex = memail.indexOf(".",++itmpindex)
     if (itmpindex > iatindex) {
        ioneindex = itmpindex  
        break;
     }
   }   
   //has one .
   //has one @
   //@ and . can't first
   if ((iatindex > 0) && (ioneindex >0))
   {    
     // . must after @ but not the next one.
     if (iatindex < ioneindex){
        //@ and . can't last
        if ((iatindex < (memail.length-1)) && (ioneindex < (memail.length-1))){
           //must has only 1 @
           iatindex = memail.indexOf("@",++iatindex)
           if (iatindex == -1){
              iatindex = memail.indexOf("@")
              if ((memail.charAt(iatindex-1) != '.') && (memail.charAt(iatindex+1) != '.')) breturn = true
           }
        }        
     }
   }
   return breturn
}

// compare date
//0 - equal
//1 - mdate1 > mdate2
//-1 - mdate1 < mdate2
//-255 - error
function CompareDate(mdate1,mdate2)
{
    var mday1
    var mday2
    var mmon1
    var mmon2
    var year1
    var year2
    mday1 = parseFloat(mdate1.substring(0,2))
    mday2 = parseFloat(mdate2.substring(0,2))
    mmon1 = parseFloat(mdate1.substring(3,5))
    mmon2 = parseFloat(mdate2.substring(3,5))
    year1 = parseFloat(mdate1.substring(6,10))
    year2 = parseFloat(mdate2.substring(6,10))
    var mdatev1
    var mdatev2 
    try{
    mdatev1 = new Date(year1,mmon1-1,mday1)    
    mdatev2 = new Date(year2,mmon2-1,mday2)  
    if ((mday1 == mday2) && (mmon1 == mmon2) && (year1 == year2)){
        return 0
    }else if (mdatev1 > mdatev2){
        return 1
    }else if (mdatev1 < mdatev2){
        return -1
    }
    }catch(e){
        return -255
    }
}
//compare time
//0 - equal
//1 - time1 > mtime2
//-1 - mtime1 < mtime2
//-255 - error
function cOmpareTime(time1,time2)
{
  var mtime1s
  var mtime2s 
  try{
  mtime1s = time1.split(':')
  mtime2s= time2.split(':')
  }catch(e){
    return -255;
  }

  if (mtime1s.length <= 1) return -255;
  if (mtime2s.length <= 1) return -255;

  if (parseFloat(mtime1s[0]) > parseFloat(mtime2s[0])){
     return 1  
  }
  else if (parseFloat(mtime1s[0]) < parseFloat(mtime2s[0])){
     return -1
  }
  else
  {
     if (parseFloat(mtime1s[1]) > parseFloat(mtime2s[1])){
        return 1  
     }
     else if (parseFloat(mtime1s[1]) < parseFloat(mtime2s[1])){
        return -1     
     }
     else
     { 
        return 0
     }
  }   
}
//chechking for Bank account checksum
// -1 : invalid length
// -2 : invalid format
// 1 : ok
function ValidateBankControl(mBank)
{       
    var st_temp
    var i_del=0
    var i_index
		if((mBank!= "")&&(mBank!=null)){
			st_temp = new String(mBank)
			//remove dash
			i_index = st_temp.indexOf("-")
			while (i_index > 0)
			{
			  st_temp = st_temp.substring(0,i_index) + st_temp.substring(i_index+1,st_temp.length)
       	      i_index = st_temp.indexOf("-")
			}
			st_temp1 = new String(st_temp)
			if((st_temp1 != null) && (st_temp1 != "")){
				if(st_temp1.length == 12){
					st_temp1 = st_temp1.substring(0,3)+st_temp1.substring(3,10)
					i_2 = parseFloat(st_temp1)
					i_2 = i_2 % 97
					if (i_2 == 0)
					{
						i_2 = 97
					}
					st_temp1 = st_temp.substring(10,12);
					if (i_2 != parseFloat(st_temp1)){
					    return -1
					}
					else{
					    return 1
					}
				}else{
					return -2
				}
			}
		}
}
// xml loader
// add item to select element the less
// elegant, but compatible way.
function appendToSelect(select, value, content) {
    var opt;
    opt = document.createElement("option");
    opt.value = content.nodeValue;
    opt.appendChild(content);
    select.appendChild(opt);
}
function getElementTextNS(prefix, local, parentElem, index) {

    var result = "";

    if (prefix && window.ActiveXObject) {
        // IE/Windows way of handling namespaces

        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {

        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}
function loadXMLDoc(url,funcarray) {
    var req 
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = function() {
      if (req.readyState == 4) {
         if (req.status == 200){
            try{
             for (var ifunc=0;ifunc<funcarray.length;ifunc++){                         
                if (funcarray[ifunc] !== ''){                   
                   eval(funcarray[ifunc]) 	                   
                }
             }
            }catch(e){
            }
         }
      }
    }
    req.open("GET", url, true);
    req.send(null);
}
//end xml loader 

function FillInCombo(req,lang,combo,field,defaultvalue)
{
    var select = document.getElementById(combo);
    var items = req.responseXML.getElementsByTagName(lang);
    var content
    for (var i = 0; i < items.length; i++) {
        content = document.createTextNode(getElementTextNS("", field, items[i], 0))
        appendToSelect(select, i,content);
        try{
        if (defaultvalue == content.nodeValue) select.options[i].selected = true
        }catch(e){
        }
    }
}

// ****************************************************************************
// PARAMETERS IN : selected combo and changing combo
// RETURN VALUE  : none
// PURPOSE       : change changed combo depend to select combo
//               : but you must enter value in combo     
// CALL FROM     : none
// Creation Date : 1999/02/15 (KPO)
// Modification  : Date          User        Comment                      Version
// ****************************************************************************
function Changepos(Comboselect,Combochange)
{
   if (Comboselect.selectedIndex > 0)
   { 
     var i_for
     var st_temp
     var st1
     var st2
     var bfoundyn = false
     st_temp = Comboselect.options[Comboselect.selectedIndex].text         
     st1 = st_temp.split(",")
     for (i_for=0;i_for < Combochange.length;i_for++)
     {
       st_temp = Combochange.options[i_for].text
       st2 = st_temp.split(",")
       if ((st2[0] == st1[1]) && (st2[1] == st1[0]))
       {	         
         Combochange.selectedIndex = i_for
         bfoundyn = true
         break
       }
     }	     
   }
   if (!bfoundyn) {
      Combochange.selectedIndex = -1
      Comboselect.selectedIndex = -1
   }
}
//loading combo
function _ULoading_combopos(mComboname,mSeltext)
{    
   var mCombo = document.getElementById(mComboname)
   var _mst = '';
   var _msts
   if (mSeltext  == '') return
   var _msels = mSeltext.split(",")
   if (_msels.length < 2) return  
   var bfoundyn = false
   for (var i=0;i<mCombo.options.length-1;i++){
        _mst = mCombo.options[i].text
        if (_mst != ''){
            _msts = _mst.split(",")
            if (_msts.length > 0){
                if ((_msts[0] == _msels[0]) && (_msts[1] == _msels[1])){
                    mCombo.selectedIndex = i   
                    bfoundyn = true
                    break;
                }   
            }
        }
   }
   if (!bfoundyn){
       //search again
       for (var i=0;i<mCombo.options.length-1;i++){
            _mst = mCombo.options[i].text
            if (_mst != ''){
                _msts = _mst.split(",")
                if (_msts.length > 0){
                    if (_msts[0] == _msels[0]){
                        mCombo.selectedIndex = i   
                        bfoundyn = true
                        break;
                    }   
                }
            }
       }
   }
   if (!bfoundyn) mCombo.selectedIndex = -1
   Changepos1(mComboname)
}
//validate size of textarea
function DoValidateTextAreaSize(mControl,mSize,mMessage,mLine)
{
    var mcommlen
    mcommlen = dotrim(document.getElementById(mControl).value)
    var mlines = 1
    if (parseFloat(mLine) > 0) mlines = parseFloat(mLine)
    if (mcommlen.length > (mSize*mlines)){
        alert(mMessage)
        domyFocus(document.getElementById(mControl))
        return true            
    }
}
//round with 2 decimal
function rxund(mvalue)
{
 return Math.round(mvalue*100)/100
}    
//val in javascript
function UVal(mText0,mCurrencyYN)
{
    var mText = mText0
    if (mCurrencyYN) mText = rEplace(rEplace(mText0,'.',''),',','.')
    var __mval
    __mval = parseFloat(mText,2)
    if (isNaN(__mval)) __mval = 0
    return rxund(__mval)
}

/****************************************************************/
function UReplace(mdata)
{
    return rEplace(mdata," ","")
}
function UReplacest(mdata,mst1,mst2)
{
    return rEplace(mdata,mst1,mst2)
}
function uParseStringforRemote(mString)
{
   return rEplace(rEplace(rEplace(mString,"<","&lt;"),">","&gt;"),"&","&amp;")
}
function uParseStringforRemoteAjax(mString)
{
   return rEplace(rEplace(rEplace(mString,"<",";lt;"),">",";gt;"),"&",";amp;")
}

//for convert string 
//case example
//	Newcell.innerHTML = "<td width='35'><font face='Courier New'><small>"+UmakestringforjavaHtml(arrVacation[kTemp+4])+"</td>"
function UmakestringforjavaHtml(mdata)
{
   var mvdata
   mvdata = rEplace(mdata,"<","&#60;")
   mvdata = rEplace(mvdata,">","&#62;")
   mvdata = rEplace(mvdata,"\'","&#39;")   
   mvdata = rEplace(mvdata,"\x0a","<BR>") 
   return mvdata
}
//case example
//	oCol3.innerHTML = "<font color='"+col3color+"' face='Arial'>" + UmakestringforjavawithHtml(tasknamewith <ahref>) + " &nbsp;</font>"
function UmakestringforjavawithHtml(mdata)
{
   var mvdata
   mvdata = rEplace(mdata,"\'","&#39;")   
   mvdata = rEplace(mdata,'"',"&quot;")   
   mvdata = rEplace(mvdata,"\x0a","<BR>") 
   return mvdata
}
//there is problem in replace in java
//case example
//	data_Tmp = Umakestringforjavalink(arrVacation[kTemp+4])
//	Newcell.innerHTML = "<td width=20><font face=Courier New><small>&nbsp;" +
//	 "<a class=Normal1 href=\"javascript:vacation('"+ UReplacefordatasplit(data_Tmp) +"')\">"+ 
//	 arrVacation[kTemp+2]+"</a></td>"
function Umakestringforjavalink(mdata)
{
   var mvdata
   mvdata = rEplace(mdata,"\'","&#92;&#39;")
   mvdata = rEplace(mvdata,"\x0a","&#92;n") 
   mvdata = rEplace(mvdata,"\x0d","") 
   mvdata = rEplace(mvdata,"\\","&#92;&#92;")  
   mvdata = rEplace(mvdata,'"',"&#34;") 
   return mvdata
}
//case example
//	mHTML = "<input type = text "+ mTaskLock + " name = 'txtA" + mLength + "' value = '" + Umakestringfortaskpage(mComment) + "' style='Background-color:#F7E7C4' style='width = 100%'>" 
function Umakestringfortaskpage(mdata)
{
   var mvdata
    mvdata = rEplace(mdata, "&", "&#38;")
    mvdata = rEplace(mvdata, ">", "&#62;")
    mvdata = rEplace(mvdata, "<", "&#60;")
    mvdata = rEplace(mvdata,"'","&#39;")	
    return  mvdata
}

function UmakestringforCombo(mdata)
{
   var mvdata
    mvdata = rEplace(mdata,"&#39;","'")	
    return  mvdata
}

//change comma to .
function ChangeComma(data)
{
	return rEplace(data,",",".")
}
//use for show the hyperlink <BUG XXXX>
//eg. oCol3.innerHTML = "<font color='"+col3color+"' face='Arial'>" + Umakestringforhyperlink(taskname) + "&nbsp;</font>"
function Umakestringforhyperlink(data)
{
	//fix problem about <a href =''><text></a>
	//change &#60; > 7 (normall user can't fill it)
	//change &#62; > 9 (normall user can't fill it)
	var mdata
	mdata = rEplace(data,"&#60;","\x07")
	mdata = rEplace(mdata,"&#62;","\x09")
	//change 	
	mdata = rEplace(mdata,"<","&#60;")
	mdata = rEplace(mdata,">","&#62;")
	//change back
	mdata = rEplace(mdata,"\x07","<")	
	mdata = rEplace(mdata,"\x09",">")
	
	//rEplace quote
	mdata = rEplace(mdata,'"',"&quot;")
	//there is some text with tab from bugtracking 
	mdata = rEplace(mdata,"\x08"," ")
	return mdata
}

//****************************************************************
//remove row from row.id
function RemoveRow(mRows,myid)
{  
  var ireturn=-1
  for (var irow=1;irow<mRows.length-1;irow++)
  {
     if (mRows[irow].id == myid){
        ireturn = irow;
        break;
     }
  }  
  return ireturn
}
//return value to space if null or undefine
function doISundefine(mvalue)
{
   return (mvalue == null)?'':mvalue
}
//bookmark
function addBookmarkForBrowser(title,url) {
if (window.sidebar != null) { 
    window.sidebar.addPanel(title, url,""); 
} else if( document.all != null) { 
    window.external.AddFavorite( url, title); 
} else if( window.opera && window.print ) { 
    return true; 
} 
}
//gettting scrolling 
function UgetScrollingPositionY()
{
var position='0';
if (typeof window.pageYOffset != 'undefined')
{
   position = window.pageYOffset
}
else if ((typeof document.documentElement.scrollTop != 'undefined') && (document.documentElement.scrollTop > 0))
{
    position = document.documentElement.scrollTop
}
else if (typeof document.body.scrollTop != 'undefined')
{
    position = document.body.scrollTop
}
return position;
}
//validate IE/Netscape
function UISIEBrowserYN()
{
    try{
       return (navigator.appVersion.indexOf("MSIE") > 0)
    }catch(e){
       return false
    }
}
function UReplaceFrenchForAjax(mdata)
{
		var myS = new String(mdata); 
        var i = 0;
        var tmpvalue = 0 
        var mvalue =""
      
        for(i=0;i<=myS.length -1;i++)
        {
            tmpvalue = myS.charCodeAt(i)
            mvalue   = myS.charAt(i) 
           
            if(parseFloat(tmpvalue) == 167){myS = myS.replace(mvalue,"%;Azbycx;")}     
      
            else if(parseFloat(tmpvalue) == 201){myS = myS.replace(mvalue,"%;Eacute;")}
            else if(parseFloat(tmpvalue) == 233){myS = myS.replace(mvalue,"%;eacute;")}
            else if(parseFloat(tmpvalue) == 200){myS = myS.replace(mvalue,"%;Egrave;")}

            else if(parseFloat(tmpvalue) == 232){myS = myS.replace(mvalue,"%;egrave;")}
            else if(parseFloat(tmpvalue) == 199){myS = myS.replace(mvalue,"%;Ccedil;")}
            else if(parseFloat(tmpvalue) == 231){myS = myS.replace(mvalue,"%;ccedil;")}

            else if(parseFloat(tmpvalue) == 192){myS = myS.replace(mvalue,"%;Agrave;")}
            else if(parseFloat(tmpvalue) == 224){myS = myS.replace(mvalue,"%;agrave;")}
            else if(parseFloat(tmpvalue) == 202){myS = myS.replace(mvalue,"%;Ecirc;")}

            else if(parseFloat(tmpvalue) == 226){myS = myS.replace(mvalue,"%;acirc;")}
            else if(parseFloat(tmpvalue) == 219){myS = myS.replace(mvalue,"%;Ucirc;")}
            else if(parseFloat(tmpvalue) == 234){myS = myS.replace(mvalue,"%;ecirc;")}

            else if(parseFloat(tmpvalue) == 203){myS = myS.replace(mvalue,"%;Euml;")}
            else if(parseFloat(tmpvalue) == 251){myS = myS.replace(mvalue,"%;ucirc;")}
            else if(parseFloat(tmpvalue) == 217){myS = myS.replace(mvalue,"%;Ugrave;")}

            else if(parseFloat(tmpvalue) == 235){myS = myS.replace(mvalue,"%;euml;")}
            else if(parseFloat(tmpvalue) == 249){myS = myS.replace(mvalue,"%;ugrave;")}
            else if(parseFloat(tmpvalue) == 194){myS = myS.replace(mvalue,"%;Acirc;")}
            
            else if(parseFloat(tmpvalue) == 43){myS = myS.replace(mvalue,"%;BzbycxB;")} //+

        }
        
    return myS

}

//-------------------- function for check email ----------------------
function emailCheck (emailStr,msgerr1,msgerr2,msgerr3,msgerr4,msgerr5,msgerr6,mshowmsgyn) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Finally, let's start trying to figure out if the supplied address is
   valid. */
/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */     
    if (mshowmsgyn){
	    if (msgerr1 == null) {
	       alert("Email address seems incorrect (check @ and .'s)")
	    }else{
	       alert(msgerr1)
	    }
	}
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    if (mshowmsgyn){
	if (msgerr2 == null) {
        alert("The username doesn't seem to be valid.")
	}else{
	   alert(msgerr2)
	}
	}
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        if (mshowmsgyn){
        	if (msgerr3 == null) {
	            alert("Destination IP address is invalid!")
	        }else{
	           alert(msgerr3)
	        }
	        }
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    if (mshowmsgyn){
	if (msgerr4 == null) {
	    alert("The domain name doesn't seem to be valid.")
	}else{
	    alert(msgerr4)
	}
	}
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   if (mshowmsgyn){
	if (msgerr5 == null) {
        alert("The address must end in a three-letter domain, or two letter country.")
	}else{
	    alert(msgerr5)
	}
	}
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
    if (mshowmsgyn){
    if (msgerr6 == null) {
       alert(errStr)
	}else{
	    alert(msgerr6)
	}
	}
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//------------------------------------  End ---------------------------->

//copy text in clipboard
function _copyInClipboard(mcontrol)
{
	try{
        var s = document.getElementById(mcontrol).createTextRange() 
        s.execCommand("SelectAll")	
        document.execCommand("Copy")   
	    return true
	}catch(e){
	    alert('Your browser don\'t permit the editor to automatically execute copying operations\n Please use the keyboard CTRL+C')
	}
}		

//------------------------------------  End ---------------------------->
//hidden combo when panel show
//before:
//				<select class="Normal" id="lstBackup" style="WIDTH: 560px; HEIGHT: 250px" size="5">
//              <option></option>
//				</select>
//
//after : put td with samename as combo+_show (with display = none)
//<table><tr><td id = "lstBackup_show">
//				<select class="Normal" id="lstBackup" style="WIDTH: 560px; HEIGHT: 250px" size="5">
//              <option></option>
//				</select></td></tr></table>

// 1) when show panel :-
//  _ShoWPanel_DIV_Swap(1,"comboname",bpanelyn)

// 2) put _UWaitPanel_DIV_Closeall when close panel
				
function _ShoWPanel_DIV_Swap(mno,mcombo,bpanelyn)
{
var _the_combo = document.getElementById(mcombo)
var _thecomboh = _the_combo.style.height
if (_thecomboh == 0) _thecomboh = '21px'
if (_the_combo.style.display == 'none') return
var _the_combolay = '<table border = 1 cellspacing = 0 cellpadding = 0 style = "height:'+_thecomboh+';width:'+_the_combo.style.width +';border:solid 1px black"><tr><td align = "left" valign = "'+ ((_the_combo.size == 0)?'middle':'top') +'">'
var bnoselect=false
document.getElementById("_waitPanelcall_"+mno).innerHTML = mcombo
if (bpanelyn){    
    for (var ifor=0;ifor<_the_combo.length;ifor++){        
       if (_the_combo.size == 0) {
           if (_the_combo.options[ifor].selected) {
                if (_the_combo.options[ifor].text == ''){
                _the_combolay += '&nbsp;'
                }else{
                _the_combolay += _the_combo.options[ifor].text 
               }
               bnoselect = true;
               break;
           }
       }else{
            if (ifor > 50) break;
            _the_combolay += _the_combo.options[ifor].text + '<br>'       
       }
    }
    _the_combolay += '</td></tr></table>'
    document.getElementById("_waitPanel_"+mno).innerHTML = document.getElementById(mcombo+"_show").innerHTML
    document.getElementById(mcombo+"_show").innerHTML = _the_combolay
}else{
    if (document.getElementById("_waitPanel_"+mno).innerHTML != ''){
    document.getElementById(mcombo+"_show").innerHTML = document.getElementById("_waitPanel_"+mno).innerHTML
    document.getElementById("_waitPanel_"+mno).innerHTML = ''
    }
}
}
//------------------------------------  End ---------------------------->
function _LOADING_Combo(mcomboname,mvalue)
{
    for (var i=0;i<document.getElementById(mcomboname).length;i++)
    {
        if (document.getElementById(mcomboname).options[i].value == mvalue){
           document.getElementById(mcomboname).selectedIndex = i;
           break;
        }
    }
}