// currency format

function resize(image_seq) {
  var i=0;
  var add_size = 50;
  if (navigator.appName == 'Netscape') i=40;
	//if(document.images[1].width < 270) add_size=300;
  if (document.images[image_seq]) window.resizeTo(document.images[image_seq].width +add_size, document.images[image_seq].height+add_size);
  self.focus();
}

function formatCurrency(prefix, suffix, k_sep, c_sep, num) {
/*
	var prefix = '';
	var suffix = '&nbsp;&euro;';
	var k_sep = ',';
	var c_sep = '.';
*/
	var num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num))
		num = "0";

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();

	if(cents < 10)
		cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length - ( 1 + i )) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + k_sep + num.substring(num.length - (4 * i + 3));

	return (((sign)? '' : '-') + prefix + num + c_sep + cents + suffix);
}

// form validation functions -- Chee Leong 21/09/2004
function is_empty(value) {
	if(value == '')
		return true;
	else
		return false;
}

// form validation functions -- yploo 23/09/2004
// Required Field
// - td id for showing the errormsg should be <element's name>_err
// - the element only considered as required field while <element's name>_err appear in that form
//  Confirmation
// - the function will validate the confirmation field while 'confirm' word appear in the element name and 
//   the remaining word for that element name is an another element's name in the form.
//   eg. if confirmemail and email is two element's name in the form, then function will check the confirmation
// Email
// - if the element's name content the 'email' word, then function will validate the email format
// Tel
// - if the element's name content the 'tel' word, then function will validate the tel format

function validateform(docform,docall) {
	var d = docform;
	var pass =true;
	var i=0;
	var errorColor = '#E1CCE1';
 
	for(i=0; i<d.elements.length; i++) {
		//check if it have td which id is <inputname>_err
		if(docall[d.elements[i].name+'_err']){
			if(d.elements[i].value==''){
				docall[d.elements[i].name+'_err'].style.display = 'inline';
				docall[d.elements[i].name].style.background = errorColor;
				pass =  false;
			}
			else{
				docall[d.elements[i].name+'_err'].style.display = 'none';
				docall[d.elements[i].name].style.background = '#FFFFFF';
				//check confirmation
				if(d.elements[i].name.search(/confirm/gi)!=-1){
					if((d[d.elements[i].name.replace(/confirm/gi,'')])&&d[d.elements[i].name.replace(/confirm/gi,'')].value!=''){
						if(d[d.elements[i].name.replace(/confirm/gi,'')].value!=d.elements[i].value){
							docall[d.elements[i].name+'_err'].style.display = 'inline';
							docall[d.elements[i].name].style.background = errorColor;
							pass = false;
						}
					}
				}
				//validate for tel input
				if(d.elements[i].name.search(/tel/gi)!=-1){
					
					//alert('tel');
				}
				
				//validate numeric input
				
				if(d.elements[i].name.search(/postcode/gi)!=-1){
					
					if(!is_number(d.elements[i].value)){
						docall[d.elements[i].name+'_err'].style.display = 'inline';
						docall[d.elements[i].name].style.background = errorColor;
						pass = false;
						
					}
				}
				
				//validate email input
				if(d.elements[i].name.search(/email/gi)!=-1){
					if(!is_email(d.elements[i].value)){
						docall[d.elements[i].name+'_err'].style.display = 'inline';
						docall[d.elements[i].name].style.background = errorColor;
						pass = false;
						
					}
				}
			}
			
		}
		
	}
	return pass;
	
}
function validateemailform(docform,doc) {
	var d = docform;
	var pass =true;
	var i=0;
	var fieldColor = '#FFAE00';
 	var count=0;
	var noOfTextField = 5;	
	for(i=0; i<d.elements.length; i++) {

		if(doc.getElementById(d.elements[i].name+'_err')){
			doc.getElementById(d.elements[i].name+'_err').style.display = 'none';
			if(d.elements[i].value==''){
				count= count + 1;
				//alert('data_empty'+docall[d.elements[i].name].name);
				if (count==noOfTextField){
					doc.getElementById('email1_err').style.display = 'inline';				
					pass =  false;
				}
			}
			
			if(d.elements[i].value!=''){
				if(d.elements[i].name.search(/email/gi)!=-1){
					if(!is_email(d.elements[i].value)){
						doc.getElementById(d.elements[i].name+'_err').style.display = 'inline';
						pass = false;	
					}
				}
			}
			
		}
		
	}
	return pass;
}
function is_email(email) {
	var pattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
	var flag = pattern.test(email);
	if(!flag)
		return false;
	else
		return true;
}

// check numeric
function is_number(value){
	var checkOK = "0123456789";
	var i;
	var j;
	
	for (i = 0 ; value.length > i ; i++) {
		ch = value.charAt(i);
		for (j = 0 ; checkOK.length > j ; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)				
			return false;
	}
	return true;
}

function new_window(mypage, myname, w, h, scroll) {

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresize'
	win = window.open(mypage, myname, winprops);

	if (parseInt(navigator.appVersion) >= 4) {
		win.focus();
	}
}
// This function strip all passed-in text of any html tags, you can pass in as many argument as you like.
function stripHTML(text){
	var re= /<\S[^><]*>/g
	str = text;
	return str.replace(re,"");
}

// This function convert all special chars to its html entities correspondent eg < to &lt;
function html2entities(text){
	var re=/[(<>"'&]/g
	//for (i=0; i<arguments.length; i++)
	//arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
	str = text;
	return str.replace(re, function(m){return replacechar(m)});
	
}

function replacechar(match){
	if (match=="<")
	return "&lt;"
	else if (match==">")
	return "&gt;"
	else if (match=="\"")
	return "&quot;"
	else if (match=="'")
	return "&#039;"
	else if (match=="&")
	return "&amp;"
}

// ======================================================
//  Text Zooming : Use <Span> Tag to do zooming
// ======================================================	
var min=8;
var max=50;
function increaseFontSize() {
   var p = document.getElementsByTagName('Span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}


function decreaseFontSize() {
   var p = document.getElementsByTagName('Span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 10;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

// Disable Right Click Function
function trap(){
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS;
	}
	else{
		document.onmouseup=clickNS;
		document.oncontextmenu=clickIE;
	}
	document.oncontextmenu=new Function("return false")
}
function clickIE() {
	if (document.all) {
		//(message);
		return false;
	}
}

function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			//(message);
			return false;
		}
	}
}
