/*******************************************/
/*  Copyright 2006 - Jon Dunfee, jdkd.com  */
/*  last updated: August 10, 2006          */
/*  Permission granted for unlimited use   */
/*  so far as the copyright notice above   */
/*  remains intact.                        */
/*******************************************/

/****************************************** Image Manipulation */
function newImage(theImgLoc)
{
    if (document.images)
    {
        var theNewImg = new Image();
        theNewImg.src = theImgLoc;
        return theNewImg;
    }
}

function swapImg(theImg, theSrc)
{
	if(theImg)
	{
		if(theImg.src)
		{
			theImg.src = (theSrc.src)?theSrc.src:eval(theSrc+".src");
		}
		else
		{
            document.getElementById(theImg).src = (theSrc.src)?theSrc.src:eval(theSrc+".src");
		}
	}
}

/****************************************** DHTML Common Scripts */
function divStyle(theDiv)
{
    if (document.getElementById) { return document.getElementById(theDiv).style; }
    return eval("document."+((document.all)?"all."+theDiv+".style":theDiv));
}
function moveDiv(thisDiv,L,T,Z)
{
    if(L != "relative") {(document.all)?divStyle(thisDiv).pixelLeft = L:divStyle(thisDiv).left = parseInt(L) + "px";}
    if(T != "relative") {(document.all)?divStyle(thisDiv).pixelTop = T:divStyle(thisDiv).top = parseInt(T) + "px";}
    if(Z) { divStyle(thisDiv).zIndex = Z; }
}

function clipDiv(thisDiv,cT,cR,cB,cL)
{
    if (document.all || document.getElementById) { divStyle(thisDiv).clip = "rect("+cT+" "+cR+" "+cB+" "+cL+")"; }
    else
    {
        divStyle(thisDiv).clip.top = parseInt(cT) + "px";
        divStyle(thisDiv).clip.bottom = parseInt(cB) + "px";
        divStyle(thisDiv).clip.left = parseInt(cL) + "px";
        divStyle(thisDiv).clip.right = parseInt(cR) + "px";
    }
}

function showDiv()
{ 
    for(var sDi=0;sDi<showDiv.arguments.length;sDi++)
    {
        if (document.getElementById) { node = document.getElementById(showDiv.arguments[sDi]).style.visibility='visible'; }
        else divStyle(showDiv.arguments[sDi]).visibility = "visible";
    }
}

function hideDiv()
{
    for(var hDi=0;hDi<hideDiv.arguments.length;hDi++)
    {
        if (document.getElementById) { node = document.getElementById(hideDiv.arguments[hDi]).style.visibility='hidden'; }
        else divStyle(hideDiv.arguments[hDi]).visibility=(document.all)?"hidden":"hide";
    }
}

/****************************************** Random Number Generator */
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd()
{
    rnd.seed = (rnd.seed*9301+49297) % 233280;
    return rnd.seed/(233280.0);
}
function rand(number,over)
{
    over = (over)?over:0; return (Math.ceil(rnd()*(number-over))+over);
}

/****************************************** Simple String Validation */
function isValid(string,vstring)  
{
         if(vstring == "alpha") { var regex = /^([a-z])+$/; }
    else if(vstring == "ALPHA") { var regex = /^([A-Z])+$/; }
    else if(vstring == "Alpha") { var regex = /^([a-zA-Z])+$/; }
    else if(vstring == "ANum")  { var regex = /^([a-zA-Z0-9])+$/; }
    else if(vstring == "num")   { var regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; }
    else if(vstring == "int")   { var regex = /^-?\d+$/; }
    else if(vstring == "$")     { var regex = /(^((\$-)|(-\$)|(\$?-?))\d+\.?\d{0,2}$)|(^((\$-)|(-\$)|(\$?-?))\d*\.?\d{1,2}$)|(^((\$-)|(-\$)|(\$?-?))[1-9]\d{0,2}(,\d{3})*(\.\d{0,2})?$)|(^((\$\()|(\(\$)|\()\d+(\.\d{0,2})?\)$)|(^((\$\()|(\(\$)|\()\d*(\.\d{1,2})\)$)|(^((\$\()|(\(\$)|\()[1-9]\d{0,2}(,\d{3})*(\.\d{0,2})?\)$)/; }
    else if(vstring == "email") { var regex = /^([\w\.\-])+\@(([\w\-])+\.)+([a-zA-Z0-9]{2,4})+$/; }
    else if(vstring == "phone") { var regex = /^\(?\d{3}\)?(\-| |\.)?\d{3}(\-| |\.)?\d{4}$/; }
    else if(vstring == "ssn")   { var regex = /^\d{3}\-?\d{2}\-?\d{4}$/; }
    else if(vstring == "url")   { var regex = /^http:\/\/([\w\.\-])+\.+([\w\.\-])/; }
    else if(vstring == "zip")   { var regex = /^(\d{5})(-(\d{4}))?$/; }
    else var regex = vstring;
    return regex.test(string);
}

/****************************************** Added Global Functions */
function cs(obj,cls)
{
	if(obj) obj.className = (cls)?cls:"";
}

function Trim(sValue) {
	var objRegExp = /^(\s*)$/;
	if(objRegExp.test(sValue)) {
		sValue = sValue.replace(objRegExp, '');
		if(sValue.length == 0) {
			return sValue;
		}
	}
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(sValue)) {
		sValue = sValue.replace(objRegExp, '$2');
	}
	return sValue;
}
