//////////////////////////////////////////////////////////////
function openPopWindow()
{
	var args = openPopWindow.arguments;
	w=300;
	h=170;
	title = "";
	bScrollbar = "yes";
	bResize = "yes";
	page = args[0];
	if(args.length >= 2) w = args[1];
	if(args.length >= 3) h = args[2];
	if(args.length >= 4) title = args[3];
	if(args.length >= 5) bScrollbar = args[4];
	if(args.length >= 6) bResize = args[5];
	var winstyle = "width="+ w + ", height="+ h +", toolbar=no, directories=no, status=no, scrollbars="+ bScrollbar +", resize="+ bResize +", menubar=no";
	open(page, title, winstyle);
}

//////////////////////////////////////////////////////////////////
function openWindow(page)
{
	open(page);
}

////////////////////////////////////////////////////////////////////
function setStatusText(StatusText)
{
	self.status = StatusText;
	return true;
}

///////////////////////////////////////////////////////////////////
function openNoBorderWin()
{
	var args = openNoBorderWin.arguments;
	w=300;
	h=170;
	winname = "ledi";
	bScrollbar = "yes";
	bResize = "yes";
	page = args[0];
	if(args.length >= 2) w = args[1];
	if(args.length >= 3) h = args[2];
	if(args.length >= 4) winname = args[3];
	if(args.length >= 5) bScrollbar = args[4];
	if(args.length >= 6) bResize = args[5];
	var winstyle = "width="+ w + ", height="+ h +", toolbar=no, location=0, directories=no, status=no, scrollbars=yes, resize=yes, menubar=no";
	open(page, winname, winstyle);
}

/////////////////////////////////////////////////////////////////////////
function GetDocumentObj(ObjName) {
	if (document.getElementById) { // if support this function, means IE5 or above
		return document.getElementById(ObjName); // IE5 above and Mosaic supported
	}
	else {
		return document.all(ObjName); //IE4 supported
	}
}

////////////////////////////////////////////////////////////////////////
function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   
   if (typeof(inputString) != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

////////////////////////////////////////////////////////////////////////
function check(input) {
  var ok = true;

  for (var i = 0; i < input.length; i++) {
    var chr = input.charAt(i);

    // not a number
    if(isNaN(chr)){
    	// is sign # or -
    	if(chr != "#" && chr != "-" && chr != " "){
    		ok = false;
    		break;
    	}
    	else{
    		// 符號在最前與最後也是錯的
    		if(i==0 || i == input.length-1){ 
    			ok = false;
    			break;
    		}
    	}
    }
  }
 
  return ok;
}

function chkTel(input) {

  if (!check(input)) {
    return false;
  }
  else {
    return true;
  }
}

function IsEmailValid(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myFirstDotAt = checkThisEmail.indexOf('.');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
var myDoubleDotAt = checkThisEmail.indexOf("..");


// aa@.aa : NOT valid
if(myFirstDotAt == myAtSymbolAt+1)
	myEMailIsValid = false
	
// aa@aa..aaa : NOT valid	
if(myDoubleDotAt > 0)
	myEMailIsValid = false	


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

return myEMailIsValid
}
