var frm = document.forms['aspnetForm'];
if (!frm) {
    frm = document.aspnetForm;
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function PreLoadImages() {
	MM_preloadImages('images/Interface/NavButtons/AboutB_H.jpg','images/Interface/NavButtons/ServicesB_H.jpg','images/Interface/NavButtons/ReqInfoB_H.jpg','images/Interface/NavButtons/NewsB_H.jpg','images/Interface/NavButtons/SupportB_H.jpg','images/Interface/NavButtons/ContactB_H.jpg','images/Interface/NavButtons/HomeIconB_H.jpg','images/Interface/NavButtons/EmaiIconlB_H.jpg')
}


var popWin   = null;
var winCount = 0;
var winName  = "popWin";
var popUps=new Object();

function openPopWin(winURL, winWidth, winHeight, moveX, moveY, winFeatures, sWinName){
 	winName = "popWin" + winCount++;
	if (sWinName){
		winName = sWinName;
		winName = ReplaceBlank(winName);		
	}else{
		popWin = null;
		try {
 			closePopWin();
		}
		catch(e){

		}	 			
	}
	
	if (winWidth!='')	winFeatures+=", width=" + winWidth;
	if (winHeight!='')	winFeatures+=", height=" + winHeight;
	if (moveX!='')		winFeatures+=", Left=" + moveX;
	if (moveY!='')		winFeatures+=", Top=" + moveY;
	
 	popWin = window.open(winURL, winName, winFeatures);
  	popWin.focus(true);

 	popUps[winName]=popWin;
}

function closePopWin(){
	var winCount=null;  
	if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) { //do not close if early IE
		
		if ((popWin != null) && (!popWin.closed)){
			popWin.close();
		}

		for (winCount in popUps ){
			if ( (popUps[winCount] != null) || (!popUps[winCount].closed) ){
				popUps[winCount].close();
				popUps[winCount]=null;
				delete popUps[winCount];
				delete popWin;					
				
			}
		}
				     
	}	 
}

function ReplaceBlank(str){
   var sReplace = / /g;
   var sResult = str.replace(sReplace , "_");
   return(sResult);
}


function LargeImage(sImageName, str){
    if (sImageName!= ''){

        openPopWin('LargeImage.aspx?n=' + escape(sImageName) + '&c=' + str, 200, 200, '', '', 'toolbar=0,scrollbars=1,location=0,frameborder=0,border=0,status=1,menubar=0,resizable=1,titlebar=0', 'ImageWindow')
    }
}


function Trim(s) {
    //Trim leading and trailing space.
    var str = s.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'');
    //Below is for whole string, not just leading and trailing space.
    //var str = s.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');
return str;
}

function isZip(s) 
{
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          return false;
     }
    return true;
}
function isEmail(e){ 

	var i = 1;
	var j;
	var sLength = e.length;

	if (sLength < 5) {
		return false;
	}

	while ((i < sLength) && (e.charAt(i) != "@")) { 
		i++;
	}

	if ((i >= sLength) || (e.charAt(i) != "@")) return false;
	else i += 2;

	j = i;

	while ((i < sLength) && (e.charAt(i) != "_")) {
		i++;
	}
	if ((i < sLength - 1) || (e.charAt(i) == "_")) return false;
	
	while ((j < sLength) && (e.charAt(j) != ".")) { 
		j++;
	}

	// there must be at least one character after the .
	if ((j >= sLength - 1) || (e.charAt(j) != ".")) return false;

	i = sLength;
	while ((i > 0) && (e.charAt(i) != ".")) {
		i--;
	}
	if ((i <= 0) || (e.charAt(i) != ".")) return false;
	else i += 1;
	
	if ((sLength - i) > 3) return false;
	
	j = 0;
	i = 0;
	while (i < sLength) {
		if (e.charAt(i) == "@") {
			j++;
		}
		i++;
	}
	if (j > 1) return false;

	i = 0;
	while (i < sLength) {
		if ((!isLetterOrDigit(e.charAt(i))) && (e.charAt(i) != "_") && (e.charAt(i) != ".") && (e.charAt(i) != "@")	&& (e.charAt(i) != "-")) {
			return false;
		}
		i++;
	}
	return true;
}



//   function validateRange()
//   {
//      var s = document.frmInput.txtInput.value;
//      var A = document.frmInput.txtA.value;
//      var B = document.frmInput.txtB.value;

//      switch (isIntegerInRange(s, A, B))
//      {
//         case true:
//            alert(s + " is in range from " + A + " to " + B)
//            break;
//         case false:
//            alert(s + " is not in range from " + A + " to " + B)
//      }
//   }

// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
function isIntegerInRange(s, a, b)
{   if (isEmpty(s))
     if (isIntegerInRange.arguments.length == 1) return false;
     else return (isIntegerInRange.arguments[1] == true);

  // Catch non-integer strings to avoid creating a NaN below,
  // which isn't available on JavaScript 1.0 for Windows.
  if (!isInteger(s, false)) return false;

  // Now, explicitly change the type to integer via parseInt
  // so that the comparison code below will work both on
  // JavaScript 1.2 (which typechecks in equality comparisons)
  // and JavaScript 1.1 and before (which doesn't).
  var num = parseInt (s);
  return ((num >= a) && (num <= b));
}

function isInteger(s)
{
  var i;

  if (isEmpty(s))
  if (isInteger.arguments.length == 1) return 0;
  else return (isInteger.arguments[1] == true);

  for (i = 0; i < s.length; i++)
  {
     var c = s.charAt(i);

     if (!isDigit(c)) return false;
  }

  return true;
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit(c)
{
  return ((c >= "0") && (c <= "9"))
}


function isLetterOrDigit(c){
   return (isLetter(c) || isDigit(c));
}


function isLetter(c){
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


