function popup(URL, pWidth, pHeight)

{

	var iHandle = window.open(URL,'_blank','width=' + pWidth + ',height=' + pHeight + ',toolbar=yes,top=100,left=100,location=no,directories=no,status=yes,menubar=yes,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(chosen)

{ 

    var selObj = document.getElementById(chosen);

    for (var i = 0; i < selObj.options.length; i++)

    {

        selObj.options[i].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;

}

var xmlRequest;

function createRequestObject() 

{

    var xmlRequest;

    try 

    {

        xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");

    } 

    catch (error1) 

    {

        try 

        {

            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");

        } 

        catch (error2) 

        {

            if (typeof XMLHttpRequest != 'undefined') 

            {

                xmlRequest = new XMLHttpRequest();

            }

        }

    }

    return xmlRequest;

}



function trim(s)

{

    return s.replace(/^\s+|\s+$/g, '');

}   



function popup2(pcontent)

{

    return overlib("<table width='100%' border='0' cellpadding='2' cellspacing='0' class='popupDateTable'><tr><td align='CENTER' class='popupDate'>" + pcontent);

}



function auto_currency(id){   

	var charCode = (document.getElementById(id).which)? document.getElementById(id).which : event.keyCode;

	//alert(charCode);

	if (charCode != 11) {

    var variable = document.getElementById(id);   

    var new_value =  variable.value.replace(/\,/g,"");   

	variable.style.textAlign = "right";   

    variable.value = digit_grouping(new_value);   

	}

}  



function digit_grouping(nStr){

	nStr += '';

	x = nStr.split('.');

	x1 = x[0];

	x2 = x.length > 1 ? '.' + x[1] : '';

	var rgx = /(\d+)(\d{3})/;

	while (rgx.test(x1)) {

		x1 = x1.replace(rgx, '$1' + ',' + '$2');

	}

	return x1 + x2;

}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) {
		alert("Email address seems incorrect (check @ and .'s)")
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	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;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
		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) {   
		alert("The address must end in a three-letter domain, or two letter country.");
		return false;
	}

	if (len<2) {
		var errStr="This address is missing a hostname!";
		alert(errStr);
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}
