function popupPage(theurl) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 200, yMax=200;

    var xOffset = (xMax - 450)/2, yOffset = (yMax - 200)/2;

    window.open(theurl,'my','location=No,scrollbars=Yes,menubar=No,toolbar=No,resizable=Yes,width=650,height=300,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}

function popupPage2(theurl) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 500, yMax=400;

    var xOffset = (xMax - 450)/2, yOffset = (yMax - 200)/2;

    window.open(theurl,'my','location=No,scrollbars=Yes,menubar=No,toolbar=No,resizable=Yes,width=550,height=300,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}
function urlencode(str) {
return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function urldecode(str) {
return unescape(str.replace('+', ' '));
}

function Goto(param)
{
	window.location = param ;
}
function GoBack()
{
	history.go(-1);
}
function DoDelete(param,num)
	{
	if (confirm("Do you want to permanently delete the record ref # " + num + "?"))
		window.location = param ;
	}
	
function DoPost(param,num)
	{
	if (confirm("Do you want to POST record ref # " + num + "?"))
		window.location = param ;
	}
	
	
function DoReg(param,num)
	{
	if (confirm("Create account to this record # " + num + "?"))
		window.location = param ;
	}
function delvar(dcode,param,num)
	{
	var codestr;
	if (dcode == "1")
		codestr = "Do you want to remove this image:"+ num +"?"
	else if  (dcode == "2")
		codestr = "Do you want to remove this CV:"+ num +"?"
	else
		codestr = "Do you want to remove this item:"+ num +"?"
		
	if (confirm(codestr))
		window.location = param ;
}
	

function expandcontract(tbodyid,ClickIcon) {
if (document.getElementById(ClickIcon).innerHTML == "Show"){
document.getElementById(tbodyid).style.display = "";
document.getElementById(ClickIcon).innerHTML = "Hide";
} else {
document.getElementById(tbodyid).style.display = "none";
document.getElementById(ClickIcon).innerHTML = "Show";
}
}

function reloadpar()
{
	window.opener.location.reload(); 
	window.close();
}
function passtru(tbl,el,dv)
{
	//alert ("tbl: "+tbl+"el10: "+el+"dv10: "+dv)
	document.forms[tbl].elements[el].value=dv;
}

function surfto(form) {
var myindex=form.dest.selectedIndex
location=form.dest.options[myindex].value;
}

function addthumbnail(fld,floc,id) {
	var newWindow;
	var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=500,height=500,top=100,left=200';
	newWindow = window.open('\/sim\/pro\/CMS\/justlist.asp?floc='+ floc +'&fld='+fld+'&id='+id, 'Upload_Images_to_server', props);
}
function uploadMenuImg(fld,floc) {
	var newWindow;
	var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=500,height=500,top=100,left=200';
	newWindow = window.open('\/sim\/pro\/CMS\/LOAD_MEDIA.asp?floc='+ floc +'&fld='+fld, 'Upload_Images_to_server', props);
}


function InsMedia(fldval,str,fldtyp,floc)
{

	if (floc == "B")
		document.forms["editor"].elements[fldval].value = str;
	else
	{
	if (fldtyp == "M")
		document.forms["editor"].AN_MEDIATY[0].checked = true;
	else
		document.forms["editor"].AN_MEDIATY[1].checked = true;
		
		document.forms["editor"].elements[fldval].value = str;
	}
}

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="button")
			//disable em
			tempobj.disabled=true
		}
	}
}





function getValidNRIC(nric,nation,id){ 
	//alert("company_flg:"+company_flg);
	var nricFront = nric.slice(0,1)
	var nricBACK = nric.slice(-1)
	var txn = true;
	
	if (nation == "SG"){
		if (nric.length<8){
			alert("Please enter a valid NRIC/Passport No.");
			txn = false;
			document.getElementById(id).value = "";
		}
		else{
			if (nricFront.toUpperCase() == "S"){
				nric = 	nric.slice(1,8)
			}
			else{
				nric = 	nric.slice(0,7)
			}
			
			if (isNaN(nric)) {
				alert('Please enter a valid NRIC/Passport No.');
				txn = false;
				document.getElementById(id).value = "";
			}
			else{
				processNRIC = (nric.charAt(0)*2)+(nric.charAt(1)*7)+(nric.charAt(2)*6)+(nric.charAt(3)*5)+(nric.charAt(4)*4)+(nric.charAt(5)*3)+(nric.charAt(6)*2);
				processNRIC = processNRIC%11;
				processNRIC = Math.abs(11-processNRIC);
				
				if (processNRIC == 1){
					nricBACKresult = "A";
				}
				if (processNRIC == 2){
					nricBACKresult = "B";
				}
				if (processNRIC == 3){
					nricBACKresult = "C";
				}
				if (processNRIC == 4){
					nricBACKresult = "D";
				}
				if (processNRIC == 5){
					nricBACKresult = "E";
				}
				if (processNRIC == 6){
					nricBACKresult = "F";
				}
				if (processNRIC == 7){
					nricBACKresult = "G";
				}
				if (processNRIC == 8){
					nricBACKresult = "H";
				}
				if (processNRIC == 9){
					nricBACKresult = "I";
				}
				if (processNRIC == 10){
					nricBACKresult = "Z";
				}
				if (processNRIC == 11){
					nricBACKresult = "J";
				}
				
				if (nricBACKresult != nricBACK) {
					alert('Please enter a valid NRIC/Passport No.');
					txn = false;
					document.getElementById(id).value = "";
				}
			}
		}
	}
	else{
		if (nric.length<=5){
			alert("Please enter a valid NRIC/Passport No.");
			txn = false;
			document.getElementById(id).value = "";
		}
		//isSpclChar(nric);
		//alert("isSpclChar:"+isSpclChar(nric));
	}
	
	if (txn == true){
		isSpclChar(nric,id);
	}
	
}


function isSpclChar(val,id){
   //alert("nric:"+nric);
   var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
   var mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\.]/;
   
   var strPass = val;
   var strLength = strPass.length;
   var lchar = val.charAt((strLength) - 1);
   
   if(lchar.search(mikExp) != -1) {
     alert ("The box has special characters. \nThese are not allowed.\n");
	 document.getElementById(id).value = "";
     return false;
   }
}

function validateEmail(id){  
  emailstr = document.getElementById(id).value;
  
  if (emailstr.length!=0){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(emailstr))){
	  return true;
	}
	
	alert("Please enter a valid Email Address. Only 1 Email Address allowed.");
	document.getElementById(id).value = "";
	return false;
  }
  else{
  	return true;
  }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}




// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================





