function checkuploadfile(that,no) {
	sr=that.value;
	if (sr.length > 1) {
		that.form["uploadbutton"+no].style.display="";
	}
}
function updatepreviewfile(that,no) {
	if (that.value.length>0) {
		sr='file:///'+that.value.replace(/:/,'|');
		document.images["Photo"+no].src=sr;

		reg = new RegExp("\\\\{1}\\([^\.]*\\)\\.","i");
		name = that.value.replace(reg,"\$1");
	} else {
		updatepreviewurl(that.form["Photo"+no+"-URL"],no)
	}
}

function trunchars(that,size) {
	v = that.value;
	if (v.length > size) {
		v = v.substr(0,size);
		if (confirm(that.name+" will be truncated to - \n---------------------------------\n"+v+"\n---------------------------------\n"+strings[4])) {
			that.value = v;
		}
	}
}

function countchars(that,size) {
	v = that.value;
	//that.form[that.name].value=v.length;
}
function other_focus(that) {
	if (that.value.indexOf('{')>-1) {
		that.value='';
	}
}
function other_blur(that) {
	if (that.value.length==0) {
		that.value=that.title;
	}
}
function check_step0(that) {
	ok = checkterms(that.YesNo_Terms);
	if (ok) {
		if (that.AccountName.value.length<3) {
			alert(strings[7]);
			that.AccountName.focus();
			return false;
		}
		if (that.AccountPhone.value.length<7) {
			alert(strings[8]);
			that.AccountPhone.focus();
			return false;
		}
		if (that.AccountEmail.value.length<5||that.AccountEmail.value.indexOf("{")==0||that.AccountEmail.value.indexOf("@")==-1) {
			alert(strings[9]);
			that.AccountEmail.focus();
			return false;
		}
		if (that.AccountContactMethod.selectedIndex==0) {
			alert(strings[10]);
			that.AccountContactMethod.focus();
			return false;
		}
		if (that.Password[0].value.length<2) {
			alert(strings[11]);
			that.Password[0].focus();
			return false;
		}
		if (that.Password[1].value.length<2) {
			alert(strings[11]);
			that.Password[1].focus();
			return false;
		}
		if (that.AccountURL.value.length>5) {
			if (that.AccountURL.value.indexOf("http://")!=0) {
				if (confirm(strings[13]+that.AccountURL.value+strings[14])) {
					that.AccountURL.value = "http://" + that.AccountURL.value;
					that.AccountURL.focus();
					alert(strings[12]);
					return false;
				}
			}
		}
	}
	return ok;
}

/* Alltrim an Expression
-------------------------*/
function trim(strComp) {
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}

//-------------------------------------------------------------------------------------------------
// Required Fields
//-------------------------------------------------------------------------------------------------
function isRequired(formObject, fieldDescription) {
	var tempFormValue ;
	var strError ="";
	var iFocus =-1;

	for (var i =0; i< isRequired.arguments.length;i=i+2) {
		if(typeof(isRequired.arguments[i]) == 'undefined')
			return false;
		tempFormValue =trim(isRequired.arguments[i].value);
		if (tempFormValue.length < 15) {
			deleteLoop = tempFormValue.length
		}
		else {
			deleteLoop = 15
		}
		for (var j = 0; j < deleteLoop; j++) {
			tempFormValue = tempFormValue.replace(/ / , "");
		}
		if (tempFormValue.length == 0) {
			strError = strError+ "\t- "+isRequired.arguments[i+1] + "\n"
			if (iFocus ==-1)
				iFocus = i;
		}
	}

	if (strError.length != 0) {
		alert( 'Following fields are required.\n\n' + strError)
	
		if(isRequired.arguments[iFocus].type != 'hidden') {
			if(isRequired.arguments[iFocus].type != 'hidden')
				isRequired.arguments[iFocus].focus();
		}
		return(false)
	}
	else
		return(true)
}

//-------------------------------------------------------------------------------------------------
// Validate Email
//-------------------------------------------------------------------------------------------------
function isEmail(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++) {
		if(ok.indexOf(e.charAt(i))<0) {
		return (false);
		}
	}
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
			} 
		}
}

//-------------------------------------------------------------------------------------------------
// Validates if the field obeys the rule
//-------------------------------------------------------------------------------------------------
/**
** Function isRule: Validates if the value of oComp object follows the rule specified through sRule
** oComp: Text box Object for which validation needs to be done
** sRule: Specifies the rule of validatin
** .....: Ex: if sRule is specified as 'ABCDEFGH...Zabcdef....xyz', any other character entered other
** .....: than those specified disobeys the rule. and false value is returned.
** sMessage: The message that has to be popped up. if no message is specified,
** ........: the function will not popup any alert.
***/
function isRule(oComp, sRule, sMessage, nLength, fdecimal) {
	if(fdecimal=="" || typeof('fdecimal')=='undefined')
		fdecimal=false;

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '') {
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined') {
		alert('Error: No rule/maximum length for input object specified.');
		return false;
	}

	var noError = true;

	//If object is specified and either of rule is specified,
	if(typeof(sRule) != 'undefined' && sRule != null) {
		var temp;
		sRule=sRule + "";

		if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i=0; i<oComp.value.length; i++) {
			temp = oComp.value.charAt(i);

			if(sRule.indexOf(temp) == "-1") {
				if(typeof(sMessage) != "undefined")
					alert(sMessage);
				//else
				//	alert(oComp.name + " disobeys rule")

				oComp.value = oComp.value.substring(0,i);
				noError = false;
				break;
			}
		}
	}

	if(nLength) {
		if(fdecimal) {
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";;
			if(dp >= 0) {
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else {
				p1 = oComp.value;
			}
			if(p1.length > nLength) {
				oComp.value = oComp.value.substring(0,nLength);
				return noError;
			}
			for(var i = 0;i < p2.length;i++) {
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9') {
					oComp.value = p1 + "." + p2.substring(0,i);
					return noError;
				}
			}
			if(p2.length > fdecimal) {
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength) {
			oComp.value = oComp.value.substring(0,nLength);
			if (typeof(sMessage)=='object')
				alert(sMessage);
			else
				alert('Cannot Exceed ' + nLength + ' characters...');
		}
	}
	return noError;
}

function toBin(decNumber) {
	base = parseInt(2);
	num = parseInt(decNumber);
	return num.toString(base);
}
function calc(objCheckBox) {
	var total = 0;
	var i = 0;
	if(typeof(objCheckBox)=='undefined')
		return 0;
	for(;i<objCheckBox.length;i++) {
		if(objCheckBox[i].checked) {
			total += eval(objCheckBox[i].value);
		}
	}

	return total;
}
function setCheckBox(oForm, sChkBox, decNum) {
	if(typeof(oForm)=='undefined')
	return false;

	var val = 1;
	var temp = new String();
	var arrVal = new Array();

	decNum = parseInt(decNum,10);
	temp = toBin(decNum);
	//if(sChkBox=='TMM')
	//	alert(decNum+' '+temp)
	for(i=temp.length;i>0;i--) {
		if(temp.substr(i-1,1)=='1') {
			if(typeof(eval('oForm.chk'+sChkBox+''+val))=='object')
				eval('oForm.chk'+sChkBox+''+val).checked=true;
		}
		val = val*2
	}
}
function displayProperties(obj) {
	var str = "";
	var arrProp = new Array();
	var prop;
	var arrIndex = 0;

	if(typeof(obj) == "undefined"){
		alert('displayProperties: Parameter is not an object!');
		return false;
	}
	
	if(typeof(obj[0]) != "undefined") {
		for(prop = 0;prop < obj.length;prop++) {
			str += "\n" + prop + "=" + obj[prop];
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}
	else {
		for(prop in obj) {
			str += "\n" + prop + "=" + eval("obj." + prop);
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}
	alert(arrProp.sort());
}

/****************************************
ERROR HANDLER
*****************************************/
window.onerror = errorHandler;
function errorHandler(e) {
	//alert(e);
}

/****************************************
DISABLE TEXT SELECTION AND MOUSE CLICKS
*****************************************/
var message="";
/*
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==1||e.which==2||e.which==3) {(message);return false;}
	}
}
if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else {document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")

function disableselect(e){return false;}
function reEnable(){return true;}

document.onselectstart=new Function ("return false")
if (window.sidebar){
	document.onmousedown=disableselect;
	document.onclick=reEnable;
}
*/

