/*******************************************/
/*  Copyright 2005 - Jon Dunfee, jdkd.com  */
/*  last updated: November 01, 2005        */
/*  Permission granted for unlimited use   */
/*  so far as the copyright notice above   */
/*  remains intact.                        */
/*******************************************/

/****************************************** 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{1,3}(\,\d{3})+\.?\d{0,2}$)|((^\$\(?-?\d*\.?\d{0,2}\)$)|(^\$?\(-?\d{1,3}(\,\d{3})+\.?\d{0,2}\)$))/; } // CR04428143
    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);
}

/****************************************** 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");
		}
	}
}

/****************************************** Additional Image Manipulation */
function transImg(thisImg,img,dur,trans,div)
{
    var div = (div)?div:false;
    var navApp = navigator.appVersion;
    if(navApp.substring(navApp.indexOf("MSIE")+5,navApp.indexOf("MSIE")+8) >= 5.5 && trans)
    {
        var theImg = document.getElementById(thisImg);
        if(theImg.filters && trans < 24 && trans > 0)
        {
            theImg.filters.revealTrans.Transition=((trans)?trans:23);
            theImg.filters.revealTrans.Duration=dur;
            theImg.filters.revealTrans.stop();
            theImg.filters.revealTrans.apply();
            swapImg(thisImg,img,div);
            theImg.filters.revealTrans.play();
        }
        else if(theImg.filters && trans == 24)
        {
            theImg.filters.blendTrans.Duration=dur;
            theImg.filters.blendTrans.stop();
            theImg.filters.blendTrans.apply();
            swapImg(thisImg,img,div);
            theImg.filters.blendTrans.play();
        }
        else
        {
            swapImg(thisImg,img,div);
        }
    }
    else
    {
        swapImg(thisImg,img,div);
    }
}

/****************************************** 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";
    }
}

/****************************************** DHTML Additional Scripts */
function transStyle(dur,trans)
{
    var navApp = navigator.appVersion;
    if(navApp.substring(navApp.indexOf("MSIE")+5,navApp.indexOf("MSIE")+8) >= 5.5 && dur)
    {
        if(trans < 24)
        {
            return "filter:revealTrans(duration="+dur+",transition="+trans+");";
        }
        else
        {
            return "filter:blendTrans(duration="+dur+");";
        }
    }
    return "";
}

function transDiv(thisDiv,dur,trans)
{
    var navApp = navigator.appVersion;
    if(navApp.substring(navApp.indexOf("MSIE")+5,navApp.indexOf("MSIE")+8) >= 5.5 && trans)
    {
        var theDiv = document.getElementById(thisDiv);
        hideDiv(thisDiv);
        if(theDiv.filters && trans == 24)
        {
            theDiv.filters.blendTrans.Duration=dur;
            theDiv.filters.blendTrans.stop();
            theDiv.filters.blendTrans.apply();
            showDiv(thisDiv);
            theDiv.filters.blendTrans.play();        
        }
        else if (theDiv.filters && trans < 24 && trans > 0)
        {
            theDiv.filters.revealTrans.Transition=((trans)?trans:23);
            theDiv.filters.revealTrans.Duration=dur;
            theDiv.filters.revealTrans.stop();
            theDiv.filters.revealTrans.apply();
            showDiv(thisDiv);
            theDiv.filters.revealTrans.play();        
        }
        else
        {
            showDiv(thisDiv);
        }
    }
    else
    {
        showDiv(thisDiv);
    }
}

function fadeDiv(theDiv,speed,show,alpha)
{
    var alpha = (alpha)?alpha+10:10;
    hideDiv(theDiv);
    if(document.all)
    {
        document.getElementById(theDiv).style.filter = "alpha(opacity="+((show)?alpha:100-alpha)+")";
    }
    showDiv(theDiv);
    if(alpha < 100)
    {
        setTimeout("fadeDiv('"+theDiv+"',"+speed+","+show+","+alpha+")",speed);
    }
    else if(!show)
    {
        hideDiv(theDiv);
    }
}

/****************************************** Object Attributes */
function findObj(item)
{
	if(document.all) return(document.all[item]);
	if(document.getElementById) return(document.getElementById(item));
    if(document.images[item]) return document.images[item];
    if(document.links[item]) return document.links[item];
	return(false);
}

function getBrowserVersion()
{
    var ieVers = parseFloat(navigator.appVersion);
    if(navigator.appName != 'Microsoft Internet Explorer') return ieVers;
    var tempVers = navigator.appVersion;
    var i = tempVers.indexOf('MSIE ');
    if(i >= 0)
    {
        tempVers = tempVers.substring(i+5);
        ieVers = parseFloat(tempVers); 
    }
    return ieVers;
}

function getObjX (x, obj)
{
    if (!document.layers)
    {
        var onWindows = (navigator.platform)?(navigator.platform == "Win32"):false;
        var macIE45 = (document.all && !onWindows && getBrowserVersion() == 4.5);
        var par = obj;
        var lastOffset = 0;
        while(par)
        {
            if(par.leftMargin && ! onWindows) x += parseInt(par.leftMargin);
            if((par.offsetLeft != lastOffset) && par.offsetLeft) x += parseInt(par.offsetLeft);
            if(par.offsetLeft != 0) lastOffset = par.offsetLeft;
            par = (macIE45)?par.parentElement:par.offsetParent;
        }
    } else if (obj.x) x += obj.x;
    return x;
}

function getObjY(y,obj)
{
    if(!document.layers)
    {
        var onWindows = (navigator.platform)?(navigator.platform == "Win32"):false;
        var macIE45 = (document.all && !onWindows && getBrowserVersion() == 4.5);
        var par = obj;
        var lastOffset = 0;
        while(par)
        {
            if(par.topMargin && !onWindows) y += parseInt(par.topMargin);
            if((par.offsetTop != lastOffset) && par.offsetTop) y += parseInt(par.offsetTop);
            if(par.offsetTop != 0) lastOffset = par.offsetTop;
            par = (macIE45)?par.parentElement:par.offsetParent;
        }
    } else if (obj.y >= 0) y += obj.y;
    return y;
}

function getObjZ(z,obj)
{ 
    if (!document.layers)
    {
        var par = findObj(obj);
        if(!par) return 0;
        if(par.style)
        {
            return (par.style.zIndex)?(z + par.style.zIndex):z;
        }
        else
        {
            return (par.zIndex)?(z + par.zIndex):z;
        }
    }
    else if(obj.z) { z += obj.z; }
    return z;
}
/****************************************** Simplified Document.Write */
function w(theText)
{
    window.document.open("text/html");
    window.document.write(theText);
    window.document.close();
}

function wl(theText)
{
    window.document.open("text/html");
    window.document.writeln(theText);
    window.document.close();
}

/****************************************** Credit Card Validation */
function isValidCC(card,num,element,dashes)
{
    if(!num) return false;
    var regex = /^/; var ccform = "";
    var ccn = ""; var nums = "0123456789";
    for(var i=0;i<num.length;i++)
    {
        if(nums.indexOf(num.substring(i,i+1)) != -1) ccn += num.substring(i,i+1);
    }
    if(card == "AX") { regex = /^3[4,7]\d{13}$/; ccform = "xxxx-xxxxxx-xxxxx" }
    else if(card == "CB") { regex = /^389\d{11}$/; ccform = "xxxx-xxxxxx-xxxx" }
    else if(card == "DC") { regex = /(^38[0-8]\d{11})|(^3[0,6]\d{12})$/; ccform = "xxxx-xxxxxx-xxxx" }
    else if(card == "DI") { regex = /^6011\d{12}$/; ccform = "xxxx-xxxx-xxxx-xxxx" }
    else if(card == "JC") { regex = /^3((5[3-8][0-9][0-9][0-9])|(33[7-9][0-9][0-9])|(34[0-9][0-9][0-9])|(528[0-9][0-9])|(15[8,9][0-9][0-9])|(11[2-9][0-9][0-9])|(120[0-9][0-9])|(10[0-2][0-9][0-9])|(09[6-9][0-9][0-9])|(09[0-4][0-9][0-9])|(08[8-9][0-9][0-9]))\d{10}$/; ccform = "xxxx-xxxx-xxxx-xxxx" }
    else if(card == "MC") { regex = /^5[1-5]\d{14}$/; ccform = "xxxx-xxxx-xxxx-xxxx" }
    else if(card == "VI") { regex = /^4\d{12}|\d{15}$/; ccform = "visa" }
	else return false;
	if(!regex.test(ccn)) return false;
    var checksum = 0;
    for(var i=(2-(ccn.length % 2)); i<=ccn.length; i+=2) { checksum += parseInt(ccn.charAt(i-1)); }
    for(var i=(ccn.length % 2) + 1; i<ccn.length; i+=2)
    {
        var digit = parseInt(ccn.charAt(i-1)) * 2;
        checksum += (digit < 10)?digit:(digit-9);
    }
    if((checksum % 10) != 0) return false;
	if(element) element.value = ccn;
    if(element && dashes)
    {
        if(ccform == "visa") ccform = (ccn.length == 13)?"xxxx-xxxxx-xxxx":"xxxx-xxxx-xxxx-xxxx";
        var ccnform = ""; var count = 0;
        for(var i=0;i<ccform.length;i++)
        {
            if(ccform.charAt(i) == "x")
            {
                ccnform += ("" + ccn.charAt(count));
                count++;
            }
            else
            {
                ccnform += ("" + ccform.charAt(i));
            }
        }
        element.value = ccnform;
    }
    return true;
}

/****************************************** Added Global Functions */
function cs(obj,cls)
{
	if(obj) obj.className = (cls)?cls:"";
}

function makeButton(btn,oimg,himg,w,h,alt,onclk)
{
	var buildBtn = '<input type="image" id="'+btn+'" name="'+btn+'" ';
	buildBtn += 'src="images/buttons/'+oimg+'" height="'+h+'" width="'+w+'" class="inputimg" align="absmiddle" ';
	if(alt) buildBtn += 'alt="' + alt + '"';
	if(onclk) buildBtn += 'onclick="' + onclk + '"';
	buildBtn += 'onmouseover="this.over();" onmouseout="this.out();" />';
	wl(buildBtn);
	d = document.getElementById(btn);
	d.out  = function() { this.src = this.imgout.src; }
	d.over = function() { this.src = this.imgover.src; }
	d.imgout = newImage("images/buttons/"+oimg);
	d.imgover = newImage("images/buttons/"+himg);
}

var viewLargeOpen = false;
function showLarge(title,img)
{
	if(viewLargeOpen) viewLargeWin.close();
	var lpos = (screen.width)?(screen.width-500)/2:0; if(lpos < 0) lpos = 0;
	var tpos = (screen.height)?(screen.height-350)/2:0; if(tpos < 0) tpos = 0;
	viewLargeWin = window.open("large.asp?title=" + title + "&img=" + img,"LargeWin","width=500,height=400,toolbar=no,location=no,scrollbars=auto,status=no,menubar=no,resizable,directories=no,dependent,top="+tpos+",left="+lpos);
	viewLargeWin.focus();
	viewLargeOpen = true;
}
function closeLarge()
{
	if(viewLargeOpen) viewLargeWin.close();
}

var viewDtlsOpen = false;
function showDtls(title,img)
{
	if(viewDtlsOpen) viewDtlsWin.close();
	var lpos = (screen.width)?(screen.width-500)/2:0; if(lpos < 0) lpos = 0;
	var tpos = (screen.height)?(screen.height-350)/2:0; if(tpos < 0) tpos = 0;
	viewDtlsWin = window.open("product_details.asp?pid=" + pid,"DtlsWin","width=500,height=400,toolbar=no,location=no,scrollbars=auto,status=no,menubar=no,resizable,directories=no,dependent,top="+tpos+",left="+lpos);
	viewDtlsWin.focus();
	viewDtlsOpen = true;
}
function closeDtls()
{
	if(viewDtlsOpen) viewDtlsWin.close();
}

var viewTermsOpen = false;
function showTerms() {
	if(viewTermsOpen) viewTermsWin.close();
	var lpos = (screen.width)?(screen.width-550)/2:0; if(lpos < 0) lpos = 0;
	var tpos = (screen.height)?(screen.height-450)/2:0; if(tpos < 0) tpos = 0;
	viewTermsWin = window.open("termsNConds.asp","termsNConds","width=550,height=500,toolbar=no,location=no,scrollbars=auto,status=no,menubar=no,resizable,directories=no,dependent,top="+tpos+",left="+lpos);
	viewTermsWin.focus();
	viewTermsOpen = true;
}
function closeTerms() {
	if(viewTermsOpen) viewTermsWin.close();
}

var viewCSCWinOpen = false;
function viewCSCInfo() {
	if(viewCSCWinOpen) viewCSCWin.close();
	var lpos = (screen.width)?(screen.width-500)/2:0; if(lpos < 0) lpos = 0;
	var tpos = (screen.height)?(screen.height-450)/2:0; if(tpos < 0) tpos = 0;
	viewCSCWin = window.open("cscinfo.asp","CSCInfo","width=500,height=500,toolbar=no,location=no,scrollbars=no,status=no,menubar=no,resizable,directories=no,dependent,top="+tpos+",left="+lpos);
	viewCSCWin.focus();
	viewCSCWinOpen = true;
}
function closeCSC() {
	if(viewCSCWinOpen) viewCSCWin.close();
}

function showLarge(pid)
{
	viewDetails(pid);
}

function showDetails(pid)
{
//	window.scrollTo(0,0);
	hideDiv("details");
	var topoff = 220 + (Math.floor(getPageYOffset()/182)*182);
	moveDiv("details",210,topoff);
	transDiv("details",.5,12);
	document.getElementById("detailsFrame").src = "details.asp?pid=" + pid;
}

function viewSpecs(sURL) {
	viewWin = window.open(sURL,"ViewSpecWin","resizable,dependent");
	viewWin.focus();
}


// Retrieve page offset for vertical scrolling
function getPageYOffset()
{
	if(window.pageYOffset) return parseInt(window.pageYOffset);
	if(document.body.scrollTop) return parseInt(document.body.scrollTop);
	if(document.documentElement.scrollTop) return parseInt(document.documentElement.scrollTop);
	return 0;
}

// Retrieve page offset for horizontal scrolling
function getPageXOffset()
{
	if(window.pageXOffset) return parseInt(window.pageXOffset);
	if(document.body.scrollLeft) return parseInt(document.body.scrollLeft);
	if(document.documentElement.scrollLeft) return parseInt(document.documentElement.scrollLeft);
	return 0;
}
