function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

// prompt confirm delete message
function confirmDel(msg)
{
  if (confirm(msg) == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

// prompt confirm delete message
function confirmDelete(frm) 
{
  var noChecked = 0; // Change to 1 when a checkbox is checked.

  for(var i=0;i < frm.length;i++) 
  {
	if(frm.elements[i].type == "checkbox" && frm.elements[i].checked == true)
	{
	  noChecked = 1;
	}
  }

  if(noChecked == 0) // No record selected. Prompt error message.
  {
	alert("Please select a record to delete!");
	return false;
  }	
  if (confirm("Are you sure you want to delete this record?") == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

// prompt confirm delete message
function confirmUpdate(frm) 
{
  var noChecked = 0; // Change to 1 when a checkbox is checked.

  for(var i=0;i < frm.length;i++) 
  {
	if(frm.elements[i].type == "checkbox" && frm.elements[i].checked == true)
	{
	  noChecked = 1;
	}
  }

  if(noChecked == 0) // No record selected. Prompt error message.
  {
	alert("Please select a record to update!");
	return false;
  }	
  if (confirm("Are you sure you want to update this record?") == 0) 
  {
      return false;
	  }
  else
  {
      return true;
  }
}

//Filter characters on keypress. eg. onKeypress="return FilterChar(event.keyCode,'numbkdash')"
function FilterChar(char,type)
{
	if(type == "nospc" && char == 32) return false;//No space allow.
	if(type == "num") //Numeric only.
	{
		if(char < 48 || char > 57) return false;
	}
	if(type == "numspc") //Numeric only. Space allow.
	{
		if(char < 48 && char != 32 || char > 57) return false;
	}
	if(type == "numdot") //Numeric only. . allow.
	{
		if(char < 48 && char != 46 || char > 57) return false;
	}
	if(type == "numdash") //Numeric only. - allow.
	{
		if(char < 48 && char != 45 || char > 57) return false;
	}
	if(type == "numbkdash") //Numeric only. / allow.
	{
		if(char < 48 && char != 47 || char > 57) return false;
	}
	if(type == "alp") //Alphabet only.
	{
		if(char < 65 || char > 90 && char < 97 || char > 122) return false;
	}
	if(type == "alpspc") //Alphabet only. Space allow.
	{
		if(char < 65 && char != 32 || char > 90 && char < 97 && char != 32 || char > 122) return false;
	}
	if(type == "alpnum_s") //Alphabet(Small Cap only) and numeric only.
	{
		if(char < 48 || char > 57 && char < 97 || char > 122) return false;
	}
	if(type == "alpnum") //Alphabet and numeric only.
	{
		if(char < 48 || char > 57 && char < 65 || char > 90 && char < 97 || char > 122) return false;
	}
	if(type == "email") //Alphabet and numeric only. Allow @.
	{
		if(char < 48 && char != 45 && char != 46 || char > 57 && char < 65 && char != 64 || char > 90 && char < 97 && char != 95 || char > 122) return false;
	}
	return true;
}

function is_Numeric(data,length,type) //Check for numeric.
{
	temp=data.value;
	
	if(length != 0) //Check for length if value is not 0.
	{
		if(temp.length < length) return false;
	}
	if(type == "num")
	{
		for(i=0; i<temp.length; i++)
		{
			if (temp.charAt(i) < "0" || temp.charAt(i) > "9")
				return false;
		}
	}
	return true;
}

function is_Email(data)
{
	// create a regular expression.
	myExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if(myExp.test(data.value) == false)
	{
		return false;
	}
	return true;
}

function ValidateEnquiry(data)
{
	if(data.contact.value == "")
	{
		alert("Please enter your name!");
		data.contact.focus();
		return false;
	}
	if(data.email.value == "")
	{
		alert("Please enter your email address!");
		data.email.focus();
		return false;
	}
	if(is_Email(data.email) == false)
	{
		alert("Invalid email address!");
		data.email.focus();
		return false;
	}
	if(data.contactno.value == "")
	{
		alert("Please enter your contact number!");
		data.contactno.focus();
		return false;
	}
	if(is_Numeric(data.contactno,8,"num") == false)
	{
		alert("Invalid contact number!");
		data.contactno.focus();
		return false;
	}
	if(data.enquiry.value == "")
	{
		alert("Please enter your enquiry!");
		data.enquiry.focus();
		return false;
	}
	return true;
}

// Highlight on focus.
function HLonFocus(face,field_color,text_color)
{
	if (document.documentElement)
	{//if browser is IE5+ or NS6+
		face.style.backgroundColor=field_color;
		face.style.color=text_color;
	}
}

// Toggle all. Can be used together with a menu listbox for selective checking.
// Check and uncheck checkboxes.
function ToggleChkBx(frm,val)
{
	for(var i=0;i < frm.length;i++)
	{
		// field 'ToggleSelect' is not present or value is blank.
		if(frm.ToggleSelect.value == "")
		{
			if(frm.elements[i].type == "checkbox")
			{
				if(val == true)
				{frm.elements[i].checked = true;}
				else
				{frm.elements[i].checked = false;}
			}
		}
		// field 'ToggleSelect' value is not blank.
		else
		{
			if(frm.elements[i].type == "checkbox")
			{
				// create a regular expression.
				myExp = new RegExp(frm.ToggleSelect.value,"g");
				// test to see if the expression exists in the string.
				if(val == true && myExp.test(frm.elements[i].value) == true)
				{frm.elements[i].checked = true;}
				if(val == false && myExp.test(frm.elements[i].value) == true)
				{frm.elements[i].checked = false;}
			}
		}
	}
}

//
function 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=findObj(n,d.layers[i].document);
  	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_findObj(n, d) { //v4.01
  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;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 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];}}
}

// valid form fieldboxs
function validFrm(str,val) 
{
  	// General declare for messages.
  	var i,p,nm,counter,condition,errors='',args,title,val;
  	counter = 0;
  	args = str.split(",");
	// loop through all the fields
  	for (i=1; i<(args.length-1); i+=2) 
  	{  
    	if (counter == 0) 
		{
    		condition=args[i+1];
	 		nm=(findObj(args[i])); 
			title=nm.name;
			val=nm.value;
			// check for empty fields
			if (val !="") 
	    	{
				// verify number
            	if (condition.indexOf('N')!=-1) 
            	{
                	if (isNaN(val))
					{
						errors=title+' must be a number.\n';
						counter = i;
					}
	        	}
				// verify email
				else if (condition.indexOf('E')!=-1) 
				{ 
			    	p=val.indexOf('@');
					x=val.indexOf('.');
					myExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
				
               		// if (p<1 || p==(val.length-1)) 
			   		if(myExp.test(val) == false)
					{
						errors=title+' must be a valid e-mail address.\n';
						counter = i;
					}
				}
        	}
        	else if (condition.charAt(0) == 'V') 
			{
				errors =title+' is required.\n'; 
				counter = i;
			}
		}
  	} 
	// 	displays error message
  	if (counter != 0) 
  	{
  		alert(errors);
		nm.focus();
		return false;
  	}
	else
	{
		return location.href='press.asp?enter=true&email='+val;
	}
}

// Ask user whether to start printing when page load.
function AutoPrint()
{
	question=confirm("Select OK to start printing or Cancel to abort.");
	if (question !="0")
	{
		print()
	}
	else
	{
 		window.close();
	}
}

// focus selected fieldbox
function GetFocus(focusfield)
{
	focusfield.focus();
	return false;
}

function jm_datemask(t)
{
	var donepatt = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	var patt = /(\d{2}).*(\d{2}).*(\d{4})/;
	var str = t.value;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null)
		{
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + '/' + result[2] + '/' + result[3];
			t.value = str;
		}
		else
		{
			if (t.value.match(/[^\d]/gi))
			t.value = t.value.replace(/[^\d]/gi,'');
		}
	}
}
