function checknull(theField,theAlert)
{
	if (theField.value==""){
		alert(theAlert); 
		theField.focus();
		return false;
	}else{
		tmp=theField.value;
		while(tmp.charAt(0)==" ")
			tmp=tmp.substring(1);
		if (tmp==""){
			alert(theAlert);
			theField.focus();
			return false;
		}
	}
	return true;
}

function checkbox(theField,theAlert){
   if (theField.value){
		if (!theField.checked){
				alert(theAlert); 
			return false;
			}
   }else{
		len=theField.length;
		flag=false;
		for (i=0;i<len;i++)
		{
			if ( theField[i].checked)
				flag=true;
		}
		if (!flag){
			alert(theAlert);
			return false;
		}
   } 
   return true;
 }

function checksize(theField,theNum,theAlert)
{
	if (theField.value.length>=theNum){
		alert(theAlert);
		return false;
	}
	return true;
}

function checkemail(theField,theAlert)
{
	temp=theField.value
	if ((temp == null) || (temp.length == 0)){
	    window.alert(theAlert);	
		theField.focus();
		return false;
	}		
	len = temp.length;
	if(len>0)
	{
	  if (len > 100)
	  {
		window.alert(theAlert);
		theField.focus();
		return false;
	  }
	  pos1 = temp.indexOf("@");
	  pos2 = temp.indexOf(".");
	  pos3 = temp.lastIndexOf("@");
	  pos4 = temp.lastIndexOf(".");
	  if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
	  {
		window.alert(theAlert);
		theField.focus();
		return false;
	  }
	  else
	  {
		if( (pos1 == pos2 - 1)||(pos1 == pos2 + 1)||( pos1 != pos3 )||( pos4 < pos3 ) )
		{
			window.alert(theAlert);
		    theField.focus();
		    return false;
		}
	  }		
	}
	return true;
}

function load(Object)
{ 
	if (Object.selectedIndex > 0) 
		location = Object.options[Object.selectedIndex].value;
}

function load1(Object)
{ 
	if (Object.selectedIndex >= 0) 
		location = Object.options[Object.selectedIndex].value;
}

function showPic()
{
 	return window.showModalDialog("../uploadfile/selectfile.php");
}

function OpenUpload(theField)
{
	if(showPic) {
		var str=null;
		str=showPic();
		if (str!=null)	
			theField.value=str;
	}	
	else
		alert("Not Avaliable!")
}

function OpenIndex(theIndex){
	if(showIndex) {
		var str=null;
		var strindex=null;
		str=showIndex();
		if (str!=null){
			strindex=str;			
			theIndex.value=strindex;
		}
	}	
	else
		alert("Not Avaliable!")
}

function showCity()
{
	return window.showModalDialog("/METS/include/selectprov.php","","status:no;resizable:no;dialogHeight:180px;dialogWidth:500px;unadorne:yes");
}

function OpenCities(theProv,theProvId,theCity,theCityId){
	if(showCity) {
		var str=null;
		var strprov=null;
		var strcity=null;
		var strprovname=null;
		var strprovid=null;
		var strcityname=null;
		var strcityid=null;
		str=showCity();
		if (str!=null){
			strprov=str.substring(0,str.indexOf("|"));
			strcity=str.substring(str.indexOf("|")+1,str.lastIndexOf("|"));
			strprovname=strprov.substring(0,strprov.indexOf("&"));
			strprovid=strprov.substring(strprov.indexOf("&")+1,strprov.lastIndexOf("&"));
			strcityname=strcity.substring(0,strcity.indexOf("&"));
			strcityid=strcity.substring(strcity.indexOf("&")+1,strcity.lastIndexOf("&"));		
			theProv.value=strprovname;
			theProvId.value=strprovid;
			theCity.value=strcityname;
			theCityId.value=strcityid;
		}
	}	
	else
		alert("Not Avaliable!")
}

function showEmpl()
{
	return window.showModalDialog("/METS/include/selectempl.php","","status:no;resizable:no;dialogHeight:100px;dialogWidth:400px;unadorne:yes");
}

function OpenEmpls(theName,theCont,theAddr,theTel,theFax,theIndus,theAttri){
	if(showEmpl) {
		var str=null;
		var strname=null;
		var strcont=null;
		var straddr=null;
		var strtel=null;
		var strfax=null;
		var strindus=null;
		var strattri=null;
		str=showEmpl();
		if (str!=null){
			strname  =  str.substring(0,str.indexOf("|"));
			strcont  =  str.substring(str.indexOf("|")+1,str.lastIndexOf("}"));
			straddr  =  str.substring(str.indexOf("}")+1,str.lastIndexOf("{"));
			strtel   =  str.substring(str.indexOf("{")+1,str.lastIndexOf("]"));
			strfax   =  str.substring(str.indexOf("]")+1,str.lastIndexOf("["));
			strindus =  str.substring(str.indexOf("[")+1,str.lastIndexOf("/"));
			strattri =  str.substring(str.indexOf("/")+1,str.indexOf("%"));
			theName.value=strname;
			theCont.value=strcont;
			theAddr.value=straddr;
			theTel.value=strtel;
			theFax.value=strfax;
			theIndus.value=strindus;
			theAttri.value=strattri;
		}
	}	
	else
		alert("Not Avaliable!")
}

function checkdel(theField)
{
	if (!checkvalue(theField))
		return false;
    if (confirm("Confirm the deletion?"))
		return true;
		else
		return false;
}

function checkoperate(theField)
{
	if (!checkvalue(theField))
		return false;
    if (confirm("Confirm the operation?"))
		return true;
		else
		return false;
}

function checkSlected(theField,theAlert)
{
	if (!checkvalue(theField))
		return false;
    if (confirm(theAlert))
		return true;
		else
		return false;
}

function checkvalue(theField)
{
   if (theField.value){
		if (!theField.checked){
				alert("Please make a selection!"); 
			return false;
			}
   }else{
		len=theField.length;
		flag=false;
		for (i=0;i<len;i++)
		{
			if ( theField[i].checked)
				flag=true;
		}
		if (!flag){
			alert("Please make a selection!");
			return false;
		}
   } 
   return true;
 }

function cfmdel()
{
    if (confirm("Confirm the deletion?"))
		return true;
		else
		return false;
}

function cfmclick(theAlert)
{
    if (confirm(theAlert))
		return true;
		else
		return false;
}

function cfmreset()
{
    if (confirm("Confirm to empty the form?"))
		return true;
		else
		return false;
}

function openWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function checksearch()
{
	if(!checknull(document.search.keystr,"Please input keyword(s)!")) return false;
	return true;
}

function checklogin()
{
	if(!checknull(document.login.uid,"Please input your ID, e.g. your emailbox.")) return false;
	if(!checknull(document.login.uid,"Please input password.")) return false;
	return true;
}

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openthis(theID)
{
	for (i=1;i<26;i++)
	{
		if(i!=theID)
		{
			document.all("line"+i).style.display="none";
		}
	}

	if(document.all("line"+theID).style.display=="none")
	{
		document.all("line"+theID).style.display="block";
	}
	else
	{
		document.all("line"+theID).style.display="none";
	}
	return true;
}

function switchmenu(td,submenu,count)
{
	document.fm1.currentID.value=submenu;
	for (i=0;i<count;i++)
	{
		if(i!=submenu)
		{
			document.all("A_"+i).style.backgroundColor="#8FC3EA";
			document.all("B_"+i).style.display="none";
		}
	}
	td.style.backgroundColor="#F47E24";
	document.all("B_"+submenu).style.display="block";
	document.fm1.currentID.value=submenu;
	return true;
}
function onColor(td)
{
	td.style.backgroundColor='#F47E24';
	td.style.color='#FFFFFF';
}
function offColor(td,submenu)
{
	if (document.fm1.currentID.value == submenu){
		td.style.backgroundColor='#F47E24';
		td.style.color='#333333';
	}else{
		td.style.backgroundColor='#8FC3EA';
		td.style.color='#333333';	
	}
}