﻿// Common Page Functions
function C_popup(pURL, pName, pHeight, pWidth, pScroll)
{
    NewWindow = window.open
    (
        pURL,
        pName,
        "toolbar=no,scrollbars=" + pScroll + ",height=" + pHeight + ",width=" + pWidth + ",directories=no,status=no,resizable=no,menubar=no"
    );
}


function C_popupFull(pURL, pName, pHeight, pWidth)
{
    NewWindow = window.open
    (
        pURL,
        pName,
        "height=" + pHeight + ",width=" + pWidth + ",toolbar=yes,scrollbars=yes,directories=yes,status=yes,resizable=yes,menubar=yes,location=yes"
    );
}


function C_isValidEmail(pValue)
{
    var re = /^([A-Za-z0-9_.]+)\@([A-Za-z0-9_.-]+)\.(\w{2,})$/;
    
    return re.test(pValue);
}


function C_isNumeric(pValue)
{
    var re = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

    return re.test(pValue);
}

function C_isTextOfLength(pValue,pLength)
{
    var re = /^[A-Za-z,\s]+$/;
    if(re.test(pValue))
    {
        if(pValue.length <= pLength)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

function C_isAlphaNumericOfLength(pValue, pLength)
{
    var re = /^[A-Za-z0-9.\s]+$/;
    if(re.test(pValue))
    {
        if(pValue.length <= pLength)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

}

function C_isZipCode(pValue)
{
    var re = /\d{5}$/;
	
	return re.test(pValue);
}

function C_isPhoneNumber(pValue)
{

    var re = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
	
	return re.test(pValue);
}




function C_TrimAll(pValue) 
{
    pValue = new String(pValue);

    while (pValue.substring(0,1) == ' ')
    {
        pValue = pValue.substring(1, pValue.length);
    }
    
    while (pValue.substring(pValue.length-1, pValue.length) == ' ')
    {
        pValue = pValue.substring(0,pValue.length-1);
    }
    
    return pValue;
}



function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}