
var varClearBackground = "#FFFFFF";
var varHeightLightBackground = "#FFFFFF";

function ValidateReqField(field, alerttxt)
{
  try
  {	 
    with (field)
    {   
        if (field.value == null || field.value.trim() == "")
        {	
				try
				{
				  field.select();
				  field.focus();
				} catch(err) { }
				field.style.background = varHeightLightBackground;
            alert(alerttxt);
            return false;
        }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}

function ValidateReqFieldWithSpanID(field, spanID,alerttxt)
{
  try
  {	 
    with (field)
    {   
        if (field.value == null || field.value.trim() == "")
        {	
				try
				{
				  field.select();
				  field.focus();
				} catch(err) { }
				field.style.background = varHeightLightBackground;
            spanID.innerHTML=alerttxt;
            return false;
        }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}


function ValidateCheckBoxWithSpanID(field, spanID,alerttxt)
{
  try
  {	 
    with (field)
    {   
        if (!field.checked)
        {	
				try
				{
				  field.select();
				  field.focus();
				} catch(err) { }
				field.style.background = varHeightLightBackground;
            spanID.innerHTML=alerttxt;
            return false;
        }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}

function CheckDropDownValue(List, falsevalue, alerttxt)
{
  try
  {	 
    with (List)
    {   
		  var selIndex = List.selectedIndex;
        if (List.options[selIndex].value == falsevalue)
        {	
				try
				{
				  List.select();
				  List.focus();
				} catch(err) { }
				List.style.background = varHeightLightBackground;
            alert(alerttxt);
            return false;
        }
        else 
        {
				List.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}

function IsListBoxSelected(List, alerttxt)
{
  try
  {	 
    with (List)
    {   
		  var selIndex = List.selectedIndex;
        if (selIndex <= -1)
        {	
				try
				{
				  List.select();
				  List.focus();
				} catch(err) { }
				List.style.background = varHeightLightBackground;
            alert(alerttxt);
            return false;
        }
        else 
        {
				List.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}
function ValidateEmail(field, alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var emailid = field.value;
		  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailid)))
		  {			 
				try
				{
				  field.select();
				  field.focus();
				} catch(err) { }
				field.style.background = varHeightLightBackground;
				alert(alerttxt);
				return false;
		  }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}


function ValidateEmailWithSpanID(field, spanID,alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var emailid = field.value;
		  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailid)))
		  {			 
				try
				{
				  field.select();
				  field.focus();
				} catch(err) { }
				field.style.background = varHeightLightBackground;
				spanID.innerHTML=alerttxt;
				return false;
		  }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}


function CompareFields(field1, field2, alerttxt)
{
  try
  {
    var val1 = field1.value
    var val2 = field2.value;
    
    if (val1 != val2)
    {  
		  try
		  {
		    field1.select();
		    field1.focus();
		  } catch(err) { }
		  field1.style.background = varHeightLightBackground;
		  field2.style.background = varHeightLightBackground;
        alert(alerttxt);
        return false;
    }
    else
    {
		  field1.style.background = varClearBackground;
		  field2.style.background = varClearBackground;
        return true;
    }
 }
 catch(err) { alert(err.description); } 
}

function CompareFieldsSpanID(field1, field2,spanID, alerttxt)
{
  try
  {
    var val1 = field1.value
    var val2 = field2.value;
   
    if (val1 != val2)
    {  
		  try
		  {
		    field1.select();
		    field1.focus();
		  } catch(err) { }
		  field1.style.background = varHeightLightBackground;
		  field2.style.background = varHeightLightBackground;
          spanID.innerHTML=alerttxt;
        return false;
    }
    else
    {
		  field1.style.background = varClearBackground;
		  field2.style.background = varClearBackground;
        return true;
    }
 }
 catch(err) { alert(err.description); } 
}

function CompareDropDownList(List1, List2, alerttxt)
{
  try
  {
   var val1;
    var val2;
    with (List1)
    {
       var selIndex1 = List1.selectedIndex;
       val1 = List1.options[selIndex1].value
    }
      
    with (List2)
    { 
       var selIndex2 = List2.selectedIndex;
       val2 = List2.options[selIndex2].value
    }
    if (val1 == val2)
    {  
		  try
		  {
		    List1.select();
		    List1.focus();
		  } catch(err) { }
		  List1.style.background = varHeightLightBackground;
		  List2.style.background = varHeightLightBackground;
        alert(alerttxt);
        return false;
    }
    else
    {
		  List1.style.background = varClearBackground;
		  List2.style.background = varClearBackground;
        return true;
    }
 }
 catch(err) { alert(err.description); } 
}
function chkNumeric(field)
{
  // only allow 0-9 be entered, plus any values passed
  // (can be in any order, and don't have to be comma, period, or hyphen)
  // if all numbers allow commas, periods, hyphens or whatever,
  // just hard code it here and take out the passed parameters
  var checkOK = "0123456789";		
  alert(checkOK);
  var checkStr = field;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";

  for (i = 0;  i < checkStr.value.length;  i++)
  {
	 ch = checkStr.value.charAt(i);
	 for (j = 0;  j < checkOK.length;  j++)
	 if (ch == checkOK.charAt(j))
	 break;
	 if (j == checkOK.length)
	 {
		allValid = false;
		break;
	 }
	 if (ch != ",")
	 allNum += ch;
  }
  if (!allValid)
 {	
	 try
	 {
	   field.select();
	   field.focus();
	 } catch(err) { }
	 alert("Please enter only Numeric Values.");
	 return (false);
  }
  else
  {	 
	 field.style.background = varClearBackground;
	 return true;
  }
}


function ValidateInteger(field, alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var controlvalue = field.value;
		  var expression=new RegExp(); 
		  expression.compile('^[0-9]{5}$');
		  if (controlvalue!= null && controlvalue.trim() != "")
          {
             if (!(expression.test(controlvalue)))
		     {	 
				    try
				    {
				      field.select();
				      field.focus();
				    } catch(err) { }
				    field.style.background = varHeightLightBackground;
				    alert(alerttxt);
				    return false;
		     }
            else 
            {
				field.style.background = varClearBackground;
                return true
            }
          }
     }
  }
  catch(err)  
  { 
  //alert(err.description); 
  return false; 
  } 
}

function chkLength(field,alerttext)
{	
  var checkStr = field;  

  if (checkStr.value.length >= 6)
  {
      if (checkStr.value.length <= 15)
      {
             return true;
      }  
      else
      { 
        alert(alerttext);
        return (false);   
      }   
  }
  else
  { 
    alert(alerttext);
    return (false);   
  }   
}
function CheckAdminEmail(email_field, rooturl)
{
  try
  {
    var emailaddress = email_field.value;
    var http_req = httpRequest();
    var url = rooturl + "Handlers/AdminUser.ashx?email=" + emailaddress;
 	 http_req.open("GET", url, true);
 	 http_req.onreadystatechange = function()
 	 {
 		if(http_req.readyState == 4 && http_req.status == 200)
 		{
 			var result = http_req.responseText;
 			if(result.indexOf("+Used") >= 0)
 			{
 				alert("The entered Email Address is already in use!\nPlease try another!");
 				email_field.style.background = varHeightLightBackground;
 				email_field.focus();
 				return false;
 			}
 			else if(result.indexOf("+NotValid") >= 0)
 			{
 				alert("The entered Email Address is not valid!\nPlease try another!");
 				email_field.style.background = varHeightLightBackground;
 				email_field.focus();
 				return false;
 			}
 			else if(result.indexOf("+OK") >= 0)
 			{
 			   email_field.style.background = varClearBackground;
 			}
 		}
 	 };
 	 http_req.send(null);
 	 }
 	 catch(err)   {    alert(err.description);   } 
}
function chkMinLength(field, minLength, minlength_alerttext)
{	 
  var varReturn = true;

  with (field)
  {  
	  if (field.value.length < minLength && minLength > 0 )
	  {
		 try
		{
		  field.select();
		  field.focus();
		} catch(err) { }
		alert(minlength_alerttext);
		field.style.background = varHeightLightBackground;
		varReturn = false;
	  }
	  else
	  {	
		  field.style.background = varClearBackground;
	  }
  }
  return varReturn;
 }
function chkPasswordLength(field,alerttext)
{	
  var checkStr = field;  

  if (checkStr.value.length >= 6)
  {
      if (checkStr.value.length <= 15)
      {
             return true;
      }  
      else
      { 
        alert(alerttext);
        return (false);   
      }   
  }
  else
  { 
    alert(alerttext);
    return (false);   
  }   
}
function httpRequest()
 {
 	var http_req = false;
 	
 	try
 	{
 		http_req = new ActiveXObject("Msxml2.XMLHTTP");
 	}
 	catch(e)
 	{
 		try
 		{
 			http_req = new ActiveXObject("Microsoft.XMLHTTP");
 		}
 		catch(err)
 		{
 			http_req = false;
 		}
 	}
 	
 	if(!http_req && typeof(XMLHttpRequest) != 'undefined')
 		http_req = new XMLHttpRequest();
 		
 	return http_req 
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


function ValidateURL(field, alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var controlvalue = field.value;
		  var expression=new RegExp(); 
		  expression.compile('^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$');
		  if (controlvalue!= null && controlvalue.trim() != "")
          {
             if (!(expression.test(controlvalue)))
		     {	 
				    try
				    {
				      field.select();
				      field.focus();
				    } catch(err) { }
				    field.style.background = varHeightLightBackground;
				    alert(alerttxt);
				    return false;
		     }
            else 
            {
				field.style.background = varClearBackground;
                return true
            }
          }
     }
  }
  catch(err)  
  { 
  //alert(err.description); 
  return false; 
  } 
}


function ValidateUSERIDPWD(field,spanID,alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var controlvalue = field.value;
		  var expression=new RegExp(); 
		  expression.compile('^([a-zA-Z0-9@*#]{5,15})$');
		  if (controlvalue!= null && controlvalue.trim() != "")
          {
             if (!(expression.test(controlvalue)))
		     {	 
				    try
				    {
				      field.select();
				      field.focus();
				    } catch(err) { }
				    field.style.background = varHeightLightBackground;
				    spanID.innerHTML=alerttxt;
				    return false;
		     }
            else 
            {
				field.style.background = varClearBackground;
                return true
            }
          }
     }
  }
  catch(err)  
  { 
  //alert(err.description); 
  return false; 
  } 
}


function ValidateUSERIDPWD(field,spanID,alerttxt)
{
  try
  {	 
    with (field)
    {	    
		  var controlvalue = field.value;
		  var expression=new RegExp(); 
		  expression.compile('^([a-zA-Z0-9@*#]{5,15})$');
		  if (controlvalue!= null && controlvalue.trim() != "")
          {
             if (!(expression.test(controlvalue)))
		     {	 
				    try
				    {
				      field.select();
				      field.focus();
				    } catch(err) { }
				    field.style.background = varHeightLightBackground;
				    spanID.innerHTML=alerttxt;
				    return false;
		     }
            else 
            {
				field.style.background = varClearBackground;
                return true
            }
          }
     }
  }
  catch(err)  
  { 
  //alert(err.description); 
  return false; 
  } 
}


function ValidateREGEX(RegexExp,field,spanID,alerttxt)
{
  try
  {	 
    with (field)
    {	  
		  var controlvalue = field.value;
		  var expression=new RegExp(); 
		  expression.compile(RegexExp);
		  if (controlvalue!= null && controlvalue.trim() != "")
          {
             if (!(expression.test(controlvalue)))
		     {	 
				    try
				    {
				      field.select();
				      field.focus();
				    } catch(err) { }
				    field.style.background = varHeightLightBackground;
				    spanID.innerHTML=alerttxt;
				    return false;
		     }
            else 
            {
				field.style.background = varClearBackground;
                return true
            }
          }
     }
  }
  catch(err)  
  { 
  //alert(err.description); 
  return false; 
  } 
}


function ValidateInputControl(field, alerttxt,extensions)
{
  try
  {	 
    with (field)
    {   
        if (field.value != null || field.value.trim() != "")
        {	
			try
			{
			   var filename=field.value;
			   if (filename!= null && filename.trim() != "")
               {
                   var ext=(filename.substr(filename.length-3,filename.length));			   
                   ext=ext.toLowerCase();
			       var extArray=new Array();
			       var IsValid=new Boolean(true); 
			       extArray=extensions.split(',');
			       for(var i=0; i<extArray.length; i++) 
			       {
	                    if((ext==extArray[i]))
	                    {
	                        IsValid=false;
	                        break; 
	                    }
	                    else
	                    {
	                        continue;
	                    }
                   }
			       field.select();
			       field.focus();
			       field.style.background = varHeightLightBackground;
			       if(IsValid)
			       {
                    alert(alerttxt);
                    return false;	
                   }
                   else
                   {
                   return true;
                   }
               }
			} 
			catch(err) 
			{ 
			}
        }
        else 
        {
			field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}



function $$(id)
{
 return document.getElementById(id);
}
   function toggle(divID) 
    {
        document.getElementById(divID).style.display = (document.getElementById(divID).style.display=='none'?'block':"none");
}


function ValidateStringEndsWithChar(field,character,alerttxt)
{
  try
  {	 
    with (field)
    {   
        if (field.value != null ||field.value != "")
        {	
			try
			{
			  var lastchr=field.value.substr(field.value.length-1);
			  if(lastchr!=character)
			  {
			   alert(alerttxt);
			   return false;
			  }
			  else
			  {
			   return true;
			  }
			} 
			catch(err) 
			{ 
			}
        }
        else 
        {
				field.style.background = varClearBackground;
            return true
        }
     }
  }
  catch(err)  { alert(err.description); return false; } 
}


function Right(str, n)
{
      if (n <= 0)
          return "";
      else if (n > String(str).length)
          return str;
      else
   {
          var iLen = String(str).length;
          return String(str).substring(iLen, iLen - n);
      }
}

function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function strLength(str)
{
   return String(str).length;
}


