function valRadioButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function noSpmLnk(v1,v2) {
    locationstring = "mailto:" + v1 + "@" + v2;
    window.location = locationstring;
    }


function linkConfirm(linkLocation){
	question = confirm("You are now leaving Altech's website\; Please note further review of any information is independent and not associated with www.altechts.com")
	if (question != "0"){
		//window.open("LINK LOCATION", "NewWin", "toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width=635,height=260")
		window.open(linkLocation, "_blank");
	}
}

function submitLoginForm(){
    var errMessage = '';
      if (isBlank(document.loginForm.Username.value)){
        errMessage = errMessage + 'Username is required!\n';
    	}
      if (isBlank(document.loginForm.Pass.value)){
        errMessage = errMessage + 'Password is required!\n';
    }
	
    //print out errors or submit        
    if (errMessage!=""){
        alert(errMessage);
    }
    else {
    	document.loginForm.submit();
        //return true;
        //alert(errMessage);
    }
}

function entsub() {
		  if (window.event && window.event.keyCode == 13){
		    submitLoginForm();
		    }
		  else{
		    return true;
		    }
}


function getUrl(page){
	document.location.href = page;
	//return;
}


function DoShow(div){
    obj = document.getElementById(div).style;
    obj.display='block';
}


function DoHide(div){
    obj = document.getElementById(div).style;
    obj.display='none';
}


	function switchPage(thisURL){
		if (!isBlank(thisURL)){
			location.href=thisURL;
		}
	}
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}



        function Left(str, n)
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }
        
        function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

function isEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.lastIndexOf("@") != email.indexOf("@")) {  // @ can't appear more than once
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function ajaxObject(layer,action) {
	var updating = false;
	
	this.update = function(passData) {
		if (updating==true) { return false; }
	
		updating=true;
		var AJAX = null;
	      
		if (window.XMLHttpRequest) {
			AJAX=new XMLHttpRequest();
		} else {
			AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		if (AJAX==null) {
			alert("Your browser doesn't support AJAX.");
			return false;
		} else {
			AJAX.onreadystatechange = function() {

				if (AJAX.readyState==4 || AJAX.readyState=="complete") {
					if (action == "redraw") {
						LayerID.value=AJAX.responseText;
					} 
					else if (action == "innerhtml") {
						LayerID.innerHTML=AJAX.responseText;
					} else {
						thisResponse = AJAX.responseText;
						// alert("WORD: " + thisResponse);
						
						clearPageIDChecks();

						thisArray = thisResponse.split(",");
						for ( var x=0, len=thisArray.length; x<len; ++x ){

							for (i = 0; i < userform.length; i++) {
								if (userform[i].name.indexOf('PageID[]') >= 0) {
							            		if (userform[i].value == thisArray[x]) {
										// alert("VALUE: " + userform[i].value + "\nHIT: " + thisArray[x]);
										userform[i].checked = true;
									}
							            	}
							}

						}
					}
					delete AJAX;
					updating=false;
				}
			}
	
			var uri = passData;
			AJAX.open("GET", uri, true);
			AJAX.send(null);
			return true;
		}
	}
	
	var LayerID = document.getElementById(layer);
}
// -->