//##  Popup window & Dialog   ##
function PopupWindow(url,w,h){
  var Cwidth = parseFloat(screen.availWidth/2)-(w/2);
  var Cheight = parseFloat(screen.availHeight/2)-(h/2);
  return  window.open(url,'','width='+w+',height='+h+',top='+Cheight+',left='+Cwidth+',scrollbars=0');
//  return  window.open(url,'','width='+w+',height='+h+',top='+Cheight+',left='+Cwidth+',scrollbars=yes');
}

function PopupDialog(url,w,h){
  return  window.showModalDialog(url,window,'dialogWidth:'+w+'px;dialogHeight:'+h+'px;status:0;help:no;center:yes;');
}

function Wpop(url,img,w,h){
  var PopupMode = "1"; // 0: Popup window, 1: Dialog window
  if (window.navigator.appVersion.indexOf("MSIE")==-1) {PopupMode="0";} // if browser is firefox or not IE

  if(PopupMode=="0") {
    if(img=="yes"){url="ShowImgPopup.asp?im="+url;w=parseInt(w)+16; h=parseInt(h)+4;} 
    PopupWindow(url,w,h);
  }else{
    if(img=="yes"){url="ShowImgPopup.asp?im="+url;w=parseInt(w)+6; h=parseInt(h)+28;} 
    PopupWindow(url,w,h);
//    PopupDialog(url,w,h);    
  }
}

function OpenerReloadAndClose(){
  if (opener) {opener.location.reload();}  
  else {var xWin=window.dialogArguments; xWin.location.replace(xWin.location);}
  alert("Edit data complete.");
  self.close();
}

//##  Check input numberic only   ##
function Filter_Numberic() {
  var keycode = window.event.keyCode;
  if( keycode >=37 && keycode <=40 ) return true;  // arrow left, up, right, down  
  if( keycode >=48 && keycode <=57 ) return true;  // key 0-9
  if( keycode >=96 && keycode <=105 ) return true;  // numpad 0-9
  if( keycode ==110 || keycode ==190  ) return true;  // dot
  if( keycode ==8  ) return true;  // backspace
  if( keycode ==9 ) return true;  // tab
  if( keycode ==45 ||  keycode ==46 || keycode ==35 || keycode ==36) return true;  // insert, del, end, home
  return false;
}

//##  Check box checked & unchecked all   ##
var checkflag = "false";
function checkall(obj,field) {
  if (checkflag == "false") {
    for (i = 0; i < field.length; i++) { field[i].checked = true; }
    checkflag = "true";
    obj.title = "Unselect all data";
  }else{
    for (i = 0; i < field.length; i++) { field[i].checked = false; }
    checkflag = "false";
    obj.title = "Select all data";
  }
}

//##  Go to paging in this location  ##
function GoToPage(pageno,order){
  var PageNo = "";
  if(order==undefined){PageNo = "pageno=";}else{PageNo = "pageno"+order+"=";}
  var url = new String( window.location );
  var newurl = url.substring(url.lastIndexOf("/")+1,url.length);

  if (newurl.indexOf("#")>0)
  {    
	var exitS = "N";
    var startS = newurl.indexOf("#")-1;
	var charS = newurl.substring(0,newurl.indexOf("#"));
	do {
      if (newurl.charAt(startS+1)=="?" || newurl.charAt(startS+1)=="&" || startS+1==newurl.length) {exitS="Y";} 
	  startS++;
	} while (exitS=="N");
	charS += newurl.substring(startS,newurl.length);
	newurl = charS;
  } 

  if (url.indexOf("?")>0){
    if (newurl.indexOf(PageNo)<0){
	  newurl += "&"+PageNo+pageno;
	}else{
	  var getdata = "";
	  var arraydata = newurl.substring(newurl.indexOf("?")+1,newurl.length).split( "&" );
      for( i=0; i<arraydata.length; i++ ){ 
	    if (arraydata[i].indexOf(PageNo)<0){
	      getdata += "&"+arraydata[i];
		}else{
		  getdata += "&"+PageNo+pageno
		}
      }	  
	  getdata = getdata.substring(1,getdata.length);
	  newurl = newurl.substring(0,newurl.indexOf("?")+1)+getdata;	  
	}	
  }else{
	newurl += "?"+PageNo+pageno;
  }
  location.href=newurl;  
}

// ##  Validate email  ##
function chkemail(obj)
{
  if(obj.value=="") return true;
  var apos=obj.value.indexOf("@");
  var dotpos=obj.value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2) {
    alert("You enter email format incorrect.");
	obj.focus();return false;
  }  
}

