function browser(){
	this.dom = (document.getElementById) ? true : false;
	this.ns4 = (document.layers) ? true : false;
	this.ie = (document.all) ? true : false;
	this.ns6 = this.dom && !this.ie
	this.ie4 = this.ie && !this.dom;
	this.opera = (navigator.userAgent.indexOf("Opera") != -1);
	this.mac = (navigator.appVersion.indexOf("Mac") != -1);
	this.macie4 = this.ie4 || this.mac;
	this.dhtml = (this.dom || this.ns4 || this.ie || this.ie4 || this.opera || !this.mac) ? true : false;
	this.dhtml = (this.mac)?false:true;
	return this;
}

var bw = new browser();

function toggleTable(el,st) {
	var myelement = document.getElementById(el);
	
	if(st == 1){
		if(bw.ie){
			myelement.style.display = "inline"
		}else{
			myelement.style.display = "table-cell"
		}
	}else{
		myelement.style.display = "none"	
	}	
}




function isEmail(str) {
	var pass = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) pass = 1;
	}
	
	if (!pass)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


function checkInt(){
	if(event.keyCode < 48 || event.keyCode > 57){
		event.returnValue = false;
	}else{
		if(event.which < 48 || event.which > 57){
			return false;
		}
	}
}



function trim_js( strSrc )
	{
		// this function returns a string which has been left and right trimmed.
		var tmpStr = new String();

		tmpStr = ltrim_js( strSrc );
		tmpStr = rtrim_js( tmpStr );
		return tmpStr;
	}

	function strreverse_js( strSrc )
	{
		var intI = new Number();
		var strTmp = new String();

		intI = strSrc.length - 1;
		strTmp = "";
		while ( intI >= 0 )
		{
			strTmp += strSrc.charAt( intI );
			intI--;
		}
		return strTmp;
	}
	
	function ltrim_js( strSrc )
	{
		var tStr = new String();
		var i = new Number();
		var blnFoundChar = new Boolean();

		i = 0;
		tStr = '';
		blnFoundChar = false;

		while ( i < strSrc.length )
		{
			if ( blnFoundChar == false )
			{
				if ( strSrc.charAt( i ) != ' ' )
				{
					tStr += strSrc.charAt( i );
					blnFoundChar = true;
				}
			}
			else
			{
				tStr += strSrc.charAt( i );
			}
			i++;
		}
		return tStr;
	}		

	function rtrim_js( strSrc )
	{
		var tStr = new String();
		var i = new Number();
		var blnFoundChar = new Boolean();

		i = strSrc.length - 1;
		tStr = '';
		blnFoundChar = false;

		while ( i >= 0 )
		{
			if ( blnFoundChar == false )
			{
				if ( strSrc.charAt( i ) != ' ' )
				{
					tStr += strSrc.charAt( i );
					blnFoundChar = true;
				}
			}
			else
			{
				tStr += strSrc.charAt( i );
			}
			i--;
		}
		tStr = strreverse_js( tStr );
		return tStr;
	}			

function isBlank_js( objControl, strFailMsg )
{	
		// this function accepts a reference to the html input field ( type=text ) and a message to display
		// it trims the input value and if it returns an empty string, the function will return true.
		var blnRet = new Boolean();
		var objTmp = new Object();
		blnRet = false;
		if ( trim_js( objControl.value ) == '' )
		{
			if ( strFailMsg != '' )
			{
				objTmp = objControl.form;	// get a ref to the form object

			}
			blnRet = true;
		}
		return blnRet;
	}	
	
		
	
function theSubmit(theform){
	var failed;
	var str;
	var tmp = true;
	failed = 0;
	
	if(array_elements.length > 0){
	
		for(x=0;x<array_elements.length;x++){
			str = array_elements[x];
			if (isBlank_js( theform.elements[str], 'x' ) == true ){
				theform.elements[str].className = "error";
				if(failed != 1){
					theform.elements[str].focus();
				}
				failed = 1;
			}else{
				theform.elements[str].className = "";
			}
		}
	
		
		
		if(failed != 1){
			var count = array_email.length;
			
			if(count>0){
				for(x=0;x<count;x++){
					str = array_email[x]["field"];
					err = array_email[x]["error"];
					check = isEmail(theform.elements[str].value);
					//alert(check);
					if (check == false){
						theform.elements[str].className = "error";
						theform.elements[str].focus();
						alert(err);
						return false;
					}else{
						theform.elements[str].className = "";
					}
				}	
			}
		}
		
		if(failed == 1){
			alert("Please make sure that all mandatory fields (*) are filled in.");
			return false;
		}
	}	
	
	
	if(function_call != ""){
		eval("tmp = " + function_call);
	}
	
	
	if(tmp == true){
		theform.submit();
	}else{
		return false;
	}	
}	