function popup(URL, pWidth, pHeight)
{
	var iHandle = window.open(URL,'_blank','width=' + pWidth + ',height=' + pHeight + ',toolbar=no,top=100,left=100,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	return true;
}
	
function replace(pStr,pFind,pReplace) 
{
    var strLength = pStr.length, txtLength = pFind.length;
    if ((strLength == 0) || (txtLength == 0)) return pStr;

    var i = pStr.indexOf(pFind);
    if ((!i) && (pFind != pStr.substring(0,txtLength))) return pStr;
    if (i == -1) return pStr;

    var newstr = pStr.substring(0,i) + pReplace;

    if (i+txtLength < strLength)
        newstr += replace(pStr.substring(i+txtLength,strLength),pFind,pReplace);

    return newstr;
}	

function removeit(pObj)
{
	if (pObj.selectedIndex != -1) {
	    var iCount = 0;
		while (iCount<pObj.length) {
			if (pObj[iCount].selected) {
				pObj[pObj.selectedIndex] = null;
				iCount = 0;
			}	
			else
			    iCount++;
		}	
	}	
}	

function selectall(pObj)
{
	for (var iCount=0; iCount < pObj.length; iCount++)
		pObj[ iCount ].selected = true;
}

function ValidInteger(pObj)
{
	if (!pObj) return false;
	if (pObj.value != "") 
	{
		if (isNaN(pObj.value)) return false;
		if (parseInt(pObj.value) < 0 || parseInt(pObj.value) > 100)  return false;
		var i = pObj.value.indexOf(".");
        if (i>0) return false;
	}
	return true;
}

function isValidEmail (emailStr)
{

	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) {
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
  			for (var i=1;i<=4;i++) {
    			if (IPArray[i]>255) {
				return false;
    			}
  		}
  		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
		return false;
	}

	if (len<2) {
		alert(errStr);
		return false;
	}
	return true;
}

function GetXmlHttpObject()
{
var xmlHttp=null;try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function popup2(pcontent)
{
	return overlib("<table width='100%' border='0' cellpadding='2' cellspacing='0' class='popupDateTable'><tr><td align='CENTER' class='popupDate'>" + pcontent);
}

function popupEvent(day, month, year, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	win = window.open("include/popup.php?day=" + day + "&month=" + month + "&year=" + year + "","Calendar","scrollbars=yes, status=yes, location=no, toolbar=no, menubar=no, directories=no, resizable=yes, width=" + w + ", height=" + h + ", top=" + wint + ", left=" + winl + "");
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}
