function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
//    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
//        return true;
//    }

    var is_confirmed = confirm(theSqlQuery);
    if (is_confirmed) {
        //theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
    return true;
} // end of the 'confirmLink()' function

function openWindow(url,width,height) {
 if ((width==0) || (width==null)) {
  width=500;
 }
 if ((height==0) || (height==null)) {
  height=400;
 }
 
// window.open(url,"remotewin","width="+width+",height="+height+",scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no,directories=no");
 window.open(url,'',"width="+width+",height="+height+",scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no,directories=no");
}

function toggle_it(itemID){
      if ((document.getElementById(itemID).style.display == 'none'))
      {
        document.getElementById(itemID).style.display = 'inline';
      } else {
        document.getElementById(itemID).style.display = 'none';
      }
}

	var ie4 = (document.all) ? true : false;
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById && !document.all) ? true : false;
function hidelayer(lay) {
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.display = "none";}
}
function showlayer(lay) {
	
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
}

function verifyIP (IPvalue) {
	errorString = "";
	theName = "IP address";

	if (IPvalue == ''){
		return false;
	}

	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ipArray = IPvalue.match(ipPattern);
	
	if (IPvalue == "0.0.0.0")
		errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	else if (IPvalue == "255.255.255.255")
		errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	if (ipArray == null)
		errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	else {
		for (i = 0; i < 4; i++) {
			thisSegment = ipArray[i];
			if (thisSegment > 255) {
				errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
				i = 4;
			}
			if ((i == 0) && (thisSegment > 255)) {
				errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
			i = 4;
		      }
		   }
		}
	extensionLength = 3;
	if (errorString != ""){
		alert (errorString);
	        return false;
	}
}

function IsValidTime(timeStr) {

	var timePat = /^(\d{1,9}):(\d{2})(:(\d{2}))$/;
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		alert("Time is not in a valid format.");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	
	
	if (second=="") { second = null; }
	
	
	if (hour < 0 ) {
		alert("Hour must be larger than 0.");
		return false;
	}
	
	if (minute<0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	if (second != null && (second < 0 || second > 59)) {
		alert ("Second must be between 0 and 59.");
		return false;
	}
}
function emailCheck (emailStr) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}
	
	
	if (user.match(userPat)==null) {
	
	alert("The username doesn't seem to be valid.");
	return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }	
	}
	return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}
	
	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}
	
	return true;
}
function strtrim (str) {
    str=str.replace(/\s/mgi, '');
    str=str.replace(/\t\n\r\f\v/mgi, '');
    
   	if(str.match(/,/)){
		return 1;
	}

    
    return str;
}

function ValidateMacAddress_clid(macaddr) {

   var reg1 = /^[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}$/;
   var reg2 = /^[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}$/;
   var reg3 = /^\d+\d*$/;
   if (reg1.test(macaddr)) {
      return true;
   }else if (reg2.test(macaddr)) {
      return true;
   }else if (reg3.test(macaddr)) {
      return true;
   }else if (macaddr.value == null) {
      return true;
   } else {
      return false;
   }
}

