//Functions in this file is global to all objects
function __rvtrim(sString, sToTrim){
if(sString == "") return "";
while (sString.substring(sString.length-1, sString.length) == sToTrim){
	sString = sString.substring(0, sString.length-1);
}
return sString;
}

function __lvtrim(sString, sToTrim){
if(sString == "") return "";
while (sString.substring(0, 1) == sToTrim){
	sString = sString.substring(1, sString.length);
}
return sString;
}

function __vtrim(sString, sToTrim){
var tmpstr = __lvtrim(sString, sToTrim);
return __rvtrim(tmpstr, sToTrim);
}

function __rtrim(sString){
if(sString == "") return "";
while (sString.substring(sString.length-1, sString.length) == " "){
	sString = sString.substring(0, sString.length-1);
}
return sString;
}

function __ltrim(sString){
if(sString == "") return "";
while (sString.substring(0, 1) == " "){
	sString = sString.substring(1, sString.length);
}
return sString;
}

function __trim(sString){
var tmpstr = __ltrim(sString);
return __rtrim(tmpstr);
}

function __isonull(obj){
return obj == null;
}

function __isvnull(clientid){
return document.getElementById(clientid) == null;}

function __getobject(clientid){
return document.getElementById(clientid);
}

function __replace(argvalue, x, y) {
  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;}
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;}
  return argvalue;
}

function __vcompare(str1, str2, trim){
if(trim){
return __trim(str1).toLowerCase()==__trim(str2).toLowerCase();
}
else{
str1.toLowerCase()==str2.toLowerCase();
}
}

function __vempty(str){
return __trim(str)=="";
}

function __isnum(obj){
return typeof(obj) == "number";
}

function __isfunction(obj){
return typeof(obj) == "function";
}

function __undefined(obj){
return typeof(obj) == "undefined";
}

function __typeof(obj){
return typeof(obj);
}

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {//alert('find');
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

	function getScrollXY2(){
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ){
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}
	function OnSubmitHandler(){
		var coord = getScrollXY2();
		if (document.getElementById('hdnScrollX') != null)
			document.getElementById('hdnScrollX').value = coord[0];
		if (document.getElementById('hdnScrollY') != null)
			document.getElementById('hdnScrollY').value = coord[1];
		return true;
	}
var a= 0;
	function cycleAds(arrName, thisAd, timeout){
	//a= (a*1) + 1;
	//window.status='in' + a;
		var arr=eval(arrName);
		//alert(arrName);
		if (arr==null || arr.length==0)	{return false;}
		if (document.getElementById(arr[thisAd]) != null)
		document.getElementById(arr[thisAd]).style.display='none';
		if(++thisAd==arr.length){thisAd=0;}
		if (document.getElementById(arr[thisAd]) != null)
		{document.getElementById(arr[thisAd]).style.display='';
		setTimeout("cycleAds('"+arrName+"', "+thisAd+", "+timeout+")", timeout);}
		//a= (a*1) + 1;
	//window.status='out' + a;	
	}
	
function PreventDoublePostback(formObj)
{
	if(formObj.submitted == true)
		return false;

	if(ValidatorOnSubmit
		&& !ValidatorOnSubmit()) 
			return false;

	formObj.submitted = true;
	return true;
}

function SurveyResponseValidator_RequiredTexboxValidation(textBox)
{
	if(textBox == null)
		return false;
	
	return (textBox.value.length > 0)
}

function SurveyResponseValidator_RequiredFieldValidation(element) 
{
	var ctl = document.getElementById(element.controltovalidate);
	var input_ctls = null;
	var i = 0;

	input_ctls = ctl.getElementsByTagName('textarea');
	for(i = 0; i < input_ctls.length; i++)
	{
		if(SurveyResponseValidator_RequiredTexboxValidation(input_ctls[i]))
			return true;
	}

	input_ctls = ctl.getElementsByTagName('input');
	for (i = 0; i < input_ctls.length; i++) 
	{
		if (input_ctls[i].checked) 
			    return (input_ctls[i].value.length > 0);

		if(input_ctls[i].type.toLowerCase() == "text")
			if(SurveyResponseValidator_RequiredTexboxValidation(input_ctls[i]))
				return true;
	}

	input_ctls = ctl.getElementsByTagName('option');
	for (i = 0; i < input_ctls.length; i++) 
	{
		if (input_ctls[i].selected) 
			    return (input_ctls[i].value.length > 0);
	}

	return false;
}