/*
Highlight Image Script II- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
function borderit(which,color){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
which.style.borderColor=color
}
}

function printLayout() {
	var strCode="";
	var strFilePath = getQueryString("Image");
	 
	var strFileType = strFilePath.substring(strFilePath.lastIndexOf(".")+1, strFilePath.length);
	if (strFileType=="gif" || strFileType=="jpg" || strFileType=="jpeg") {
		strCode = "<img src='" + strFilePath + "' alt=''>";
	} else if (strFileType=="mpg" || strFileType=="mpeg" || strFileType=="wmv" || strFileType=="asf") {
		strCode = composeASF(strFilePath);
		//strCode = composeASF(intWidth, intHeight, strFilePath);
	} else if (strFileType=="wma" ) {
		strCode = composeWMA(strFilePath);
	} else if (strFileType=="swf") {
		strCode = composeSWF(intWidth, intHeight, strFilePath);
	} else if (strFileType=="mov") {
		strCode = composeMOV(intWidth, intHeight, strFilePath);
	}
	document.write(strCode);
}

function getimage(input, intWidth, intHeight) {
	var strCode="";
	var strFilePath = input;
	var strFileType = strFilePath.substring(strFilePath.lastIndexOf(".")+1, strFilePath.length);
	if (strFileType=="gif" || strFileType=="jpg" || strFileType=="jpeg") {
		strCode = "<img src='" + strFilePath + "' width='" + intWidth + "' alt=''>";
	} else if (strFileType=="mpg" || strFileType=="mpeg" || strFileType=="wmv" || strFileType=="asf") {
		strCode = composeASF(strFilePath);
		//strCode = composeASF(intWidth, intHeight, strFilePath);
	} else if (strFileType=="wma" ) {
		strCode = composeWMA(strFilePath);
	} else if (strFileType=="swf") {
		strCode = composeSWF(intWidth, intHeight, strFilePath);
	} else if (strFileType=="mov") {
		strCode = composeMOV(intWidth, intHeight, strFilePath);
	} else if (strFileType=="pdf") {
		strCode = "<a href='" + strFilePath + "' target='_blank' class='blue_bold'>Click here</a> to download";
	}
	document.write(strCode);
}

function openWindow(url,toolbar ,x ,y) {
	subWindow=open(url, "newwin", "left=10,screenX=0,top=10,location=0,status=yes, resizable=yes, toolbar="+toolbar+", scrollbars=yes, width="+x+", height="+y+"");
	if(subWindow.opener==null) subWindow.opener=self;
}
function openFullscreen(frmurl, scrollbar, wd, hg) {
	if (wd==0) {
	var wd=screen.width-50;
	}
	if (hg==0) {
	var hg=screen.height-100;
	}
	winame='wininfo';
	features='scrollbars='+scrollbar+',width='+ wd +',height='+ hg +',left=0,screenX=0,top=0,screenY=0,status=0,resizable=yes';
	window.open(frmurl,winame,features);

}

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];}}
}

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;
}

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;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
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_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function isNumeric(val) {
	var digits=" .+-0123456789";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) {	return false; }
	}
	return true;
}
function emptyfield(check,err_msg){
   if (check.value == ""){
      alert(err_msg);
	  check.focus();
	  return false;
   }
}
function valid(vl,errm) // varying number of arguments
{
	var i;
	validated=true;
	// scan regular expressions
	for (i=2;i<valid.arguments.length;i++) 
	{
		var rx;
		//alert(valid.arguments[i]);
		rx=new RegExp(valid.arguments[i]);
		if ((a=rx.exec(vl))!=null && a[0].length==vl.length) {
			//alert("output:" + a[0]);
			return true;  // ok
		}
	}
	// no matches...
	alert(errm);
	validated=false;  // tell onsubmit if necessary
	return false;
}

function checkOneEmail(check, err_msg)
{
	// [\w-_]+(\.[\w-_]+)*\@+[\w-_]+(\.[\w-_]+)+
	//alert(vl);
	rv=valid(check,err_msg,"[\\w-_]+(\\.[\\w-_]+)*\\@+[\\w-_]+(\\.[\\w-_]+)+");
	return rv;
}
 
function checkBox(check,err_msg){
   var counter=0;
   for(var i=0;i<check.length;i++)
   {
     if(check[i].checked)
	 {
	   counter=counter+1;
	 }
   }
   if(counter < 1 )
   {
     alert(err_msg);
	 check[0].focus();
	 return false;
   }
}

function checkclientdirectory(frm) {
	if(emptyfield(frm.certnumber,"Please key in certificate no.: (xxxxxx) and Click “Enquiry”")==false) return;
	frm.submit();
}
function feedback_check(frm) {
	if(emptyfield(frm.fullname,"Please enter Name")==false) return;
	if(checkOneEmail(frm.emailaddress.value,"Please enter Valid Email Address")==false) {
		frm.emailaddress.focus();
	   	return;
	}
	if (frm.tel.value != "") {
		if (!isNumeric(frm.tel.value)){
			alert("Telephone must be integer.");
			frm.tel.focus();
			return;
		}

	}
	if (frm.fax.value != "") {
		if (!isNumeric(frm.fax.value)){
			alert("Facsimile must be integer.");
			frm.fax.focus();
			return;
		}

	}
	if(emptyfield(frm.captchacode,"Please enter the 6 numbers of the image into the left input field.")==false) return;
	frm.submit();
}
 
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}