﻿// JScript File

function testcall(){
    alert('test call')
}

function swapImage(imgName, newSrc) {
    document.images(imgName).src = newSrc;
}

//sets up a url to get directions at Google Maps

function appendString(){
    var urlstr = 'http://maps.google.com?f=d&hl=en&saddr=' + frmDir.txtAddr.value + '+' + frmDir.txtCity.value + '+' + frmDir.lstState.value + '+' + frmDir.txtZip.value + '&daddr=' + frmDir.daddr.value
    window.open(urlstr)
}

function switch_div(div_id) {

    // hide all the divs
    document.getElementById('featured_overview').style.display = 'none';
    document.getElementById('featured_overview').style.visibility = 'hidden';
    
    // show the requested div
    document.getElementById(div_id).style.display = 'block';
    document.getElementById(div_id).style.visibility = 'visible';

}

function switch_back(div_id) {
    
    // hide all the divs
    document.getElementById('featured_features').style.display = 'none';
    document.getElementById('featured_features').style.visibility = 'hidden';
    
    // show the requested div
    document.getElementById(div_id).style.display = 'block';
    document.getElementById(div_id).style.visibility = 'visible';

}

function random_topic() {

    var randomnumber = Math.floor(Math.random()*3)

    switch (randomnumber){
        case 0:
            document.getElementById('featured_topic_1').style.display = 'block';
            document.getElementById('featured_topic_1').style.visibility = 'visible';

            document.getElementById('featured_topic_2').style.display = 'none';
            document.getElementById('featured_topic_2').style.visibility = 'hidden';


            document.getElementById('featured_topic_3').style.display = 'none';
            document.getElementById('featured_topic_3').style.visibility = 'hidden';
        break
        
        case 1:
            document.getElementById('featured_topic_1').style.display = 'none';
            document.getElementById('featured_topic_1').style.visibility = 'hidden';

            document.getElementById('featured_topic_2').style.display = 'block';
            document.getElementById('featured_topic_2').style.visibility = 'visible';


            document.getElementById('featured_topic_3').style.display = 'none';
            document.getElementById('featured_topic_3').style.visibility = 'hidden';
        break

        case 2:
            document.getElementById('featured_topic_1').style.display = 'none';
            document.getElementById('featured_topic_1').style.visibility = 'hidden';

            document.getElementById('featured_topic_2').style.display = 'none';
            document.getElementById('featured_topic_2').style.visibility = 'hidden';


            document.getElementById('featured_topic_3').style.display = 'block';
            document.getElementById('featured_topic_3').style.visibility = 'visible';
        break

    }
}

//AJAX Div Swap

var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function show(sw,obj) {
    // show/hide the divisions
    if (sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'visible';
    if (!sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'hidden';
    if (sw && ns4) document.layers[obj].visibility = 'visible';
    if (!sw && ns4) document.layers[obj].visibility = 'hidden';
}

function setDisplay(obj) {
    obj.styles.display = none
}

var zxcEvt=0
var zxcObj;
var zxcEvt=0;
var zxcOOPCnt=0;

function zxcMoveFramedClip(zxcid,zxcw,zxch,zxcspd){
    var zxcobj=zxcCkObject(zxcid);
    var zxcp=zxcobj.parentNode;
    zxcObj=zxcp;
    zxcp.frm=zxcobj;
    zxcp.w=zxcGetStyle(zxcp,'width');
    zxcp.h=zxcGetStyle(zxcp,'height');
    zxcp.cw=zxcGetStyle(zxcobj,'width');
    zxcp.ch=zxcGetStyle(zxcobj,'height');

    if (!zxcobj.oopclip){ 
        zxcobj.oopclip=new zxcOOPClip(zxcobj,zxcw,zxch); 
    }
    
    zxcobj.par=zxcp;
    zxcobj.w=zxcw||zxcobj.oopclip.w;
    zxcobj.h=zxch||zxcobj.oopclip.h;
    zxcobj.lim=[zxcGetStyle(zxcp,'width')-zxcGetStyle(zxcobj,'width'),zxcGetStyle(zxcp,'height')-zxcGetStyle(zxcobj,'height')];
    zxcClipPos(zxcobj);
}

function zxcOOPClip(zxcobj,zxcw,zxch){
    this.obj=zxcobj;
    this.cobj=zxcobj.getElementsByTagName('DIV')[0];
    this.obj.imgw=zxcGetStyle(this.cobj,'width')
    this.obj.imgh=zxcGetStyle(this.cobj,'height')
    this.os=[zxcGetStyle(this.cobj,'left'),zxcGetStyle(this.cobj,'top')];
    this.w=zxcw;
    this.h=zxch
    this.cnt=0;
    this.ref='zxcoopclip'+zxcOOPCnt++;
    window[this.ref]=this;
    this.to=null;
}

zxcOOPClip.prototype.clip=function(){
    this.x=this.x||0;
    this.y=this.y||0;
    zxcStyle(this.cobj,{left:(-this.x+this.os[0])+'px',top:(-this.y+this.os[1])+'px',clip:'rect('+this.y+'px,'+(this.x+this.w)+'px,'+(this.y+this.h)+'px,'+this.x+'px)'});
}

function zxcClipPos(zxcobj){
    zxcobj=zxcCkObject(zxcobj);
    zxcobj.oopclip.x=(zxcGetStyle(zxcobj,'left')*(zxcobj.imgw-zxcobj.w)/zxcobj.lim[0]);
    zxcobj.oopclip.y=(zxcGetStyle(zxcobj,'top')*(zxcobj.imgh-zxcobj.h)/zxcobj.lim[1]);
    zxcobj.oopclip.clip();
}

function zxcStyle(zxcele,zxcstyle,zxctxt){
    if (typeof(zxcele)=='string'){ 
        zxcele=document.createElement(zxcele);
    }
    
    for (key in zxcstyle){ 
        zxcele.style[key]=zxcstyle[key];
    }

    if (zxctxt){ 
        zxcele.appendChild(document.createTextNode(zxctxt));
    }
    
    return zxcele;
}

function zxcMse(zxce){
    if(!zxce) var zxce=window.zxce;
    if (document.all){ 
        return [zxce.clientX+zxcDocS()[0],zxce.clientY+zxcDocS()[1]];
    }

    else { 
        return[zxce.pageX,zxcMseY=zxce.pageY]; 
    }
}

function zxcDocS(){
    var zxcsx,zxcsy;
    if (!document.body.scrollTop){
        zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop;
    }

    else { 
        zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop;
    }
    
    return [zxcsx,zxcsy];
}

function zxcGetStyle(zxcel,zxcs){
    if (zxcel.style[zxcs]){ 
        return parseInt(zxcel.style[zxcs]); 
    }

    if (zxcel.currentStyle){
        return parseInt(zxcel.currentStyle[zxcs]);
    }
    
    if (window.getComputedStyle){ 
        return parseInt(document.defaultView.getComputedStyle(zxcel,null).getPropertyValue(zxcs));
    }
    
    return 'absolute';
}

function zxcEventAdd(zxco,zxct,zxcf){
    if (zxco.addEventListener){ 
        zxco.addEventListener(zxct, function(e){zxco[zxcf](e);}, false); 
    }

    else if (zxco.attachEvent){ 
        zxco.attachEvent('on'+zxct,function(e){ zxco[zxcf](e); }); 
    }
    
    else {
        var zxcPrev=zxco['on'+zxct];
        if (zxcPrev){ 
            zxco['on'+zxct]=function(e){zxcPrev(e); zxco[zxcf](e); }; 
        }
        
        else { 
            zxco['on'+zxct]=zxco[zxcf]; 
        }
    }
}

function zxcAddEvt(zxcobj,zxcfun,zxcevt){
    if (zxcobj[zxcevt+'add']){
        return;
    }
    
    zxcobj['zxcaddEvt'+zxcEvt]=window[zxcfun];
    zxcobj[zxcevt+'add']=true;
    zxcEventAdd(zxcobj,zxcevt,'zxcaddEvt'+zxcEvt);
    zxcEvt++;
}

function zxcCkObject(zxcid){
    var zxcp=zxcid;
    if (typeof(zxcp)=='string'){
        zxcp=document.getElementById(zxcp);
    }
    
    return zxcp;
}

function zxcDrag(zxce){
    if (zxcMse(zxce)[0]>zxcPos(zxcObj)[0]&&zxcMse(zxce)[0]<zxcPos(zxcObj)[0]+zxcObj.w&&zxcMse(zxce)[1]>zxcPos(zxcObj)[1]&&zxcMse(zxce)[1]<zxcPos(zxcObj)[1]+zxcObj.h){
        zxcObj.frm.oopclip.x=(zxcMse(zxce)[0]-zxcPos(zxcObj)[0])*zxcObj.w/zxcObj.frm.imgw*4.4;
        zxcObj.frm.oopclip.clip();
    }

}

function zxcPos(zxcobj){
    zxclft=zxcobj.offsetLeft;
    zxctop=zxcobj.offsetTop;

    while(zxcobj.offsetParent!=null){
        zxcpar=zxcobj.offsetParent;
        zxclft+=zxcpar.offsetLeft;
        zxctop+=zxcpar.offsetTop;
        zxcobj=zxcpar;
    }
    
    return [zxclft,zxctop];
}



// * * * * * * Popup Divs * * * * * *


addEvent(window, "resize", moveDiv)

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}


function moveDiv(){
    windowHeight = document.body.offsetHeight
    windowWidth = document.body.offsetWidth
    
    brwserleft = (windowWidth/2) - 200
    brwsertop =  (windowHeight/2) - 250
}


function setVisible(obj) {
    windowHeight = document.body.offsetHeight
    windowWidth = document.body.offsetWidth
    
    obj = document.getElementById(obj);
    obj.style.left = (windowWidth/2) - 200;
    obj.style.top = (windowHeight/2) - 250;
    obj.style.visibility = 'visible';
    obj.style.height = '372px';
}


function setInVisible(obj) {
    obj = document.getElementById(obj);
    obj.style.visibility = 'hidden';
}


function ajaxRequest(url){
    var httpRequest; 
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    http_request.open("POST", url, true); 
    http_request.onreadystatechange = function(){processRequest()}
    http_request.send(null);
}