/* set up browser checks and add a simple emulation for IE4 */

// check browsers
var op = /opera 5|opera\/5/i.test(navigator.userAgent);
var ie = !op && /msie/i.test(navigator.userAgent);	// preventing opera to be identified as ie
var mz = !op && /mozilla\/5/i.test(navigator.userAgent);	// preventing opera to be identified as mz

if (ie && document.getElementById == null) {	// ie4
	document.getElementById = function(sId) {
		return document.all[sId];
	};
}

/* end browser checks */

function isEmpty(str) {
	for (var intLoop = 0; intLoop < str.length; intLoop++)
		if (" " != str.charAt(intLoop))
			return false;
	return true;
}

function isEmail(s){  
	var i = 1;
	var j = 1;
	var sLength = s.length;
		
	while (j < sLength){
		if (s.charAt(j) == " ")
			return false;
		j++;
	}
	while ((i < sLength) && (s.charAt(i) != "@")) 
		i++;
	if ((i >= sLength) || (s.charAt(i) != "@")) 
		return false;
	else
		i += 2;
	while ((i < sLength) && (s.charAt(i) != "."))
		i++;
	if ((i >= sLength - 1) || (s.charAt(i) != "."))
		return false;
	else
		return true;
}

function reportServerSideValidation(frm)
{
	if (typeof validationMessages != "undefined")
	{
		var alertText = "";
		for(var i = 0; i < validationMessages.length; i++) 
		{
				alertText += validationMessages[i] + "\n";
		}
		alert(alertText);
		if (typeof validationFormIDs != "undefined")
		{
			frm[validationFormIDs[0]].focus();
		}
	}
	return true;
}

function SetFocus(ClientID)
{
	eval("document.forms[0]."+ClientID+".focus();");
	eval("document.forms[0]."+ClientID+".scrollIntoView(true);");
}

function SetOnLoadEvent(func)
{
	// DOM2 (N 6)
	if (typeof window.addEventListener!="undefined")
		window.addEventListener("load", func, false);

	// IE 
	else if(typeof window.attachEvent!="undefined")
		window.attachEvent("onload", func);

	else
	{
		if(window.onload!=null)
		{
			var oldOnload=window.onload;
			window.onload=function(e){
				oldOnload(e);
				func();
			};
		}
		else 
			window.onload=func;
	}
}


SetOnLoadEvent(function (){reportServerSideValidation(document.forms[0])});