// JScript File
function TrimSections(){
	divHeader = document.getElementById("Header");
	divFooter = document.getElementById("Footer");
	divLeft = document.getElementById("ColLeft");
	divRight = document.getElementById("ColRight");
	divTopHeader = document.getElementById("topheader");
	if(divHeader){
		if(divHeader.firstChild)divHeader.style.display='block';
		else divHeader.style.display='none';
	}
	if(divFooter){
				if(divFooter.firstChild)divFooter.style.display='block';
		else divFooter.style.display='none';
	}
	if(divLeft){
				if(divLeft.firstChild)divLeft.style.display='block';
		else divLeft.style.display='none';
	}
	if(divRight){
				if(divRight.firstChild)divRight.style.display='block';
		else divRight.style.display='none';
	}
	if(divTopHeader){
				if(divTopHeader.firstChild)divTopHeader.style.display='block';
		else divTopHeader.style.display='none';
	}
}

function OpenWebSite(obj)
{
   window.open(obj.options[obj.selectedIndex].value,"","");
}

function getQueryStringValue(qString) {
	  var allVars = window.location.search.substring(1).split("&");
	  for (var i=0;i<allVars.length;i++) {
	    var variable = allVars[i].split("=");
	    if (variable[0].toUpperCase() == qString.toUpperCase()) {
	      return variable[1];
	    }
	  }
	  return "null";
}
function LTrim(strText)
{
	while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);
	return strText;
} 
function checkTBKeyPress(obj,tbtype,length,precision)
{
	
	if(obj.value.length >=length)
	{
		window.event.keyCode=0;
		return;
	}
		
	if(tbtype=="alphanumeric")
	{
		return;
	}

	if(tbtype=="alpha")
	{
		if((window.event.keyCode<65 || window.event.keyCode>90) && 
		   (window.event.keyCode<97 || window.event.keyCode>122))
		{
			window.event.keyCode=0;
			return;
		}
	}	
	
	if(tbtype=="float")
	{			
		if(window.event.keyCode==46)
		{			
			if(precision==0)
			{
				window.event.keyCode=0;
				return;
			}
							
			if(length-obj.value.length==1)
			{
				window.event.keyCode=0;
				return;
			}
			
			if(obj.value.length==0)
			{
				obj.value="0";
				return;
			}
			
			var ind=obj.value.indexOf(".");
			if(ind>=0)
				window.event.keyCode=0;
		}
		else if(window.event.keyCode<48 || window.event.keyCode>57)
		{
			window.event.keyCode=0;
			return;
		}

		var ind=obj.value.indexOf(".");
		if(ind>=0)
		{
			var sstr=obj.value.substring(ind);
			if(sstr.length>precision)
				window.event.keyCode=0;
			return;
		}			
	}

	if(tbtype=="integer")
	{
		if(window.event.keyCode<48 || window.event.keyCode>57)
		{
			window.event.keyCode=0;
			return;
		}
	}		
}
function RTrim(strText)
{
	while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
	return strText;
}

function Trim(strText)
{
	return RTrim(LTrim(strText));
}

function CheckBlank(objText,strMessage)
{
	if(Trim(objText.value)=="")
	{
		alert(strMessage);
		objText.focus();
		return false;
	}
	return true;
}

function CheckBlankDropDown(objDropDown,strMessage)
{
    if(objDropDown){
        if(objDropDown.options && objDropDown.options.length>=1){
	        if(objDropDown.options[objDropDown.selectedIndex].value<=0)
	        {
		        alert(strMessage);
		        objDropDown.focus();
		        return false;
	        }
	        return true;
	    }
	    return true;
	}
	return true;
}
function CheckBlankOtherTextBoxCheckBoxList(objCheckBox,errMsg){
	var chkOtherName = objCheckBox[0].name+"_Other_Chk";
	var txtOtherName = objCheckBox[0].name+"_Other";
	if(document.getElementById(chkOtherName).checked)
	{
		if(Trim(document.getElementById(txtOtherName).value)=="")
		{
			alert(errMsg);
			document.getElementById(txtOtherName).focus();
			return false;
		}
		return true;
	}
	return true;
}

//function CheckBlankOtherTextBox

function CheckBlankCheckBoxRadio(objChk,errMsg){
	var checkedOne = false;
	for(var i=0;i<objChk.length;i++){
		if (objChk[i].checked)
			checkedOne = true;
	}
	if(!checkedOne){
		var chkOtherName = objChk[0].name+"_Other_Chk";
		//alert(chkOtherName);
		if(objChk.type!="radio" && document.getElementById(chkOtherName)!=null)
			if(document.getElementById(chkOtherName).checked)
				checkedOne = true;
	}
	if(!checkedOne){
		alert(errMsg);
		objChk[0].focus();
		return false;
	}
	return true;
}

function CheckOtherTextBoxDDLList(objDDL,errMsg){
	var checkedOne = false;
	for(var i=0;i<objDDL.options.length;i++){
		if(objDDL.options[i].value=="other"){
			if(objDDL.options[i].selected)
				checkedOne=true;
		}
	}
	if(checkedOne){
		var txtOtherName = objDDL.name + "_Other"
		if(Trim(document.getElementById(txtOtherName).value)==""){
			alert(errMsg);
			document.getElementById(txtOtherName).focus();
			return false;
		}
	}
	return true;
}

function CheckBlankDropDownList(objDDL,errMsg){
	var checkedOne = false;
	for(var i=0;i<objDDL.options.length;i++){
		if(objDDL.options[i].selected)
			checkedOne=true;
	}
	if(!checkedOne){
		alert(errMsg);
		objDDL.focus();
		return false;
	}
	return true;
}

function CheckBlank2(objText)
{
	if(Trim(objText.value)=="")
	{
		objText.focus();
		return false;
	}
	return true;
}

function checkEmail(objEmail,strMsg){
	if(CheckBlank(objEmail,strMsg)){
		var filter= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(objEmail.value))
			return true;
		else{
			alert(strMsg);
			objEmail.select();
			objEmail.focus();
			return false;
		}
	}
	return false;
}
function ValidEmail(strEmail){
	var filter= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(strEmail))
			return true;
		else{
			return false;
		}
}
function checkURL(objUrl,strMsg){
    var httpregex=/^([a-zA-Z]+:\/\/)/;
    var urlregex=/^\w+.[.\w]*\w$/;
    var value=objUrl.value;
    var match=value.match(httpregex); // has a protocol indicator
     if (match){
          match=objUrl.value.substr(match[1].length,value.length)
          match=match.match(urlregex);
     }else{
          var match=value.match(urlregex);
     }
     if(!match){
          if (strMsg) alert(strMsg);
          objUrl.focus();
          return false;
     }else return true;
}
