/* MacMedia, Inc. 
 * 
 * General function for default theme
 * (C) 2008 MacMedia, Inc.
 * http://www.macmediainc.com
 *
 * updated: 02/10/2008 - Mike Elser
 */

var shingleTimer = null;

// Preload google map bubble if IE6 (locations.php)
var gImg_1 = new Image();
var gImg_2 = new Image();
gImg_1.src = "http://maps.google.com/intl/en_us/mapfiles/iw2.png";
gImg_2.src = "http://maps.google.com/intl/en_us/mapfiles/iws2.png";


function rand(number) {
    return Math.floor(Math.random() * (number - 1)) + 1;
}

function random_sidebarShingle(shingleCount) {
    //alert(rand(shingleCount));
    sidebarShingles.drawers[rand(shingleCount)].open(true);
}


function sidebarShinglesAutoLoader() {
    //alert('start');
    if (null !== shingleTimer) {
        clearInterval(shingleTimer);
    }

    shingleTimer = setInterval(function () {
        random_sidebarShingle(sidebarShinglesCount);
    }, 10000);
}

function slidedown(el) {
    Effect.SlideDown(el, {
        duration: 0.3
    });
}

function slideup(el) {
    Effect.SlideUp(el, {
        duration: 0.3
    });

}

function getElement(id) {
    return parent.document.getElementById(id);
}


function bcObjText(str) {
    obj = getElement('bcObjText');
    if (obj) {
        obj.innerHTML = "&nbsp;" + str;
    }
    return true;
}


function bcObjTextOut() {
    obj = getElement('bcObjText');
    if (obj) {
        obj.innerHTML = "&nbsp;&lt;&lt; Select ";
    }
    return true;
}

function bcObjLoad(url) {
    parent.location = url;
}



function rnd() {
    rnd.seed = (rnd.seed * 9301 + 49297) % 233280;
    return rnd.seed / (233280.0);
}

function rand_old(number) {
    return Math.ceil(rnd() * number);
}





/* validEmail(email string)
 *
 */

function validEmail(email) {

    invalidChars = " /:,;";

    if (email === "") {
        return false;
    }
    for (i = 0; i < invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar, 0) > -1) {
            return false;
        }
    }
    atPos = email.indexOf("@", 1);
    if (atPos == -1) {
        return false;
    }
    if (email.indexOf("@", atPos + 1) > -1) {
        return false;
    }
    periodPos = email.indexOf(".", atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos + 3 > email.length) {
        return false;
    }
    return true;
}

/* Start of AJAX functions
 *
 */
 
 function stateChangedinteral() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.responseText !== null) {
            //var html = xmlHttp.responseText.split("<!-- WEB_CAL -->");
            document.getElementById('content').innerHTML = xmlHttp.responseText;
        }
    }
}

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (err) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    return xmlHttp;
}

function ajaxPOSTinteral(url, parameters) {
    if (parameters.length === 0) {
        return "[AJAX] Error - parameters.length < 1";
    }

    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return false;
    }

    xmlHttp.onreadystatechange = stateChangedinteral;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
    return true;
}


function postContactForm(obj) {
    var url = "scripts/contactus_email.php";
    var emailObj = document.getElementById("email").value;
    //alert(emailObj);
    if (!validEmail(emailObj)) {
        document.getElementById("emailerror").innerHTML = "Invalid Email";
        return;
    }
    document.getElementById("emailerror").innerHTML = "";


    var poststr = "user_code= " + encodeURI(document.getElementById("user_code").value) + "&email= " + encodeURI(document.getElementById("email").value) + "&name= " + encodeURI(document.getElementById("name").value) + "&phone= " + encodeURI(document.getElementById("emailphone").value) + "&subject= " + encodeURI(document.getElementById("emailsubject").value) + "&message= " + encodeURI(document.getElementById("emailmessage").value) + "&storename= " + encodeURI(document.getElementById("storename").value) + "&storeservice= " + encodeURI(document.getElementById("storeservice").value) + "&user_agent= " + encodeURI(document.getElementById("user_agent").value) + "&remote_ip= " + encodeURI(document.getElementById("remote_ip").value);


    ajaxPOSTinteral(url, poststr);

}





function postJoinUsForm(obj) {

    var url = "scripts/joinus_email.php";
    var emailObj = document.getElementById("email").value;

    //if(parent.document.contactfrm.resumename.value != ""){
    //	MMLoaderFrame.document.fupload.submit();
    //}

    if (!validEmail(emailObj)) {
        document.getElementById("emailerror").innerHTML = "Invalid Email";
        return;
    }

    btnspan = '<span class="link_disabled" style="border-bottom:none;border-top:none;height:12px;width:50px;">Sending...</span>';

    document.getElementById("emailerror").innerHTML = "";
    document.getElementById("frmSubmit").innerHTML = btnspan;



    var poststr = "user_code= " + encodeURI(document.getElementById("user_code").value) + "&email= " + encodeURI(document.getElementById("email").value) + "&fname= " + encodeURI(document.getElementById("fname").value) + "&lname= " + encodeURI(document.getElementById("lname").value) + "&phone= " + encodeURI(document.getElementById("emailphone").value) + "&poi= " + encodeURI(document.getElementById("poi").value) + "&filename= " + encodeURI(document.getElementById("resumename").value) + "&message= " + encodeURI(document.getElementById("emailmessage").value) + "&user_agent= " + encodeURI(document.getElementById("user_agent").value) + "&remote_ip= " + encodeURI(document.getElementById("remote_ip").value);

    $('content').innerHTML = "Sending data...please wait";
    ajaxPOSTinteral(url, poststr);

}

function stateChanged() {
	if (xmlHttp.readyState == 4) {
		var obj = document.getElementById('newsletter');
		var openDiv = "<br><br><div style=\"width:520px;font-size:14px;\">";
		var closeDiv = "</div>";

		if (xmlHttp.responseText !== null) {
			if (xmlHttp.responseText !== false) {
				obj.innerHTML = "<br><br><div style=\"width:520px;font-size:14px;\">" + "<span style=\"font-size:26px;font-weight:bold;\">Completed!" + "</span><br><br>Email address added<br><br>Thank you for " + "signing up for our newsletter. If you have any question  " + "please feel free to contact us at sales @ macmediainc.com " + ".</div>";
			} else {
				obj.innerHTML = openDiv + "Error<br><br>" + xmlHttp.responseText + closeDiv;
			}
		} else {
			obj.innerHTML = openDiv + "[AJAX] Error" + closeDiv;
		}
	}
	return true;
}

function ajaxPOST(url, parameters) {
    if (parameters.length === 0) {
        return "[AJAX] Error - parameters.length < 1";
    }

    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return false;
    }

    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
    return true;
}

function postNewsLetter(obj) {
    var url = "scripts/postnewsletter.php";
    var emailObj = document.getElementById("email").value;
    if (!validEmail(emailObj)) {
        document.getElementById("fnok").innerHTML = "<div style=\"padding:4px;color:red;font-size:12px;\">&nbsp;&nbsp;Invalid Email</div>";
        return;
    }
    var poststr = "ppid=" + encodeURI(document.getElementById("ppid").value) + "&version =" + encodeURI(document.getElementById("version").value) + "&email=" + encodeURI(document.getElementById("email").value) + "&FirstName=" + encodeURI(document.getElementById("firstname").value) + "&LastName=" + encodeURI(document.getElementById("lastname").value) + "&mailtype=" + encodeURI(document.getElementById("mailtype").value) + "&interest_group=" + encodeURI(document.getElementById("interest_group").value);

    alert(poststr);
    var objj = document.getElementById('newsletter');
    objj.innerHTML = "<br><br><div style=\"width:530px;text-align: center;font-size:24px;\"><img src=\"themes/default/images/spinner-blue.gif\"><br>Submitting data...</div>";
    ajaxPOST(url, poststr);
}


function checkSecurityCode(str) {
	if (str.length === 0 || str.length < 5) {
		if (str.length === 0){
			document.getElementById('codecheck').innerHTML = "&nbsp;&nbsp; * Required to continue";
        }
		return false;
	}

    //Stop checking code
	document.getElementById('codecheck').innerHTML = "<img src=\"themes/default/images/checkok.png\">";
	document.getElementById('frmSubmit').innerHTML = "<a class=\"link\" style=\"height:13px;width:50px;\" href=\"javascript:MMLoaderFrame.document.	forms[0].submit();\">Send</a>";
	return true;
}

function codeReturn() {

    if (xmlHttp.readyState == 4) {
        if (xmlHttp.responseText !== null) {
            document.getElementById('codecheck').innerHTML = "&nbsp;&nbsp; * Required to continue (Invalid Code)";
            document.getElementById('frmSubmit').innerHTML = "<span class=\"link_disabled\" style=\"width:50px;\">Send</span>";
            if (xmlHttp.responseText == "Valid code entered") {
                if (document.forms[0].emailaddress) {
                    if (!validEmail(document.forms[0].emailaddress.value)){return;}
                }
                document.getElementById('codecheck').innerHTML = "<img src=\"themes/default/images/checkok.png\">";
                document.getElementById('frmSubmit').innerHTML = "<a class=\"link\" style=\"height:13px;width:50px;\" href=\"javascript:document.forms[0].submit();\">Send</a>";
                xmlHttp = null;
                delete xmlHttp;
                //xmlHttp.responseText = null;
            }
        }
    }
}


function checkCode(str) {

    if (str.length === 0 || str.length < 5) {
        return false;
    }

    xmlHttp = null;
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return false;
    }


    url = "captcha/captcha-validate.php";
    var parameters = "user_code=" + encodeURI(str);

    xmlHttp.onreadystatechange = codeReturn;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
    
    return true;

}


function GetXmlHttpObject2() {
    var xmlHttp2 = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp2 = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (err) {
            xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    return xmlHttp2;
}



/* windows effects */

function captchadialog() {
    Dialog.alert("<div align=\"left\">Your inventory level is to low to create a new order. Please contact your sales representative to place an order.<br><br></div>", {
        windowParameters: {
            className: "alphacube",
            title: "Security Images",
            width: 300,
            height: 110
        },
        okLabel: "close"
    });
}

function openHelpWindow() {
    Dialog.alert({
        url: "captcha/why.php"
    }, {
        title: "Security Code",
        width: 550,
        className: "mac_os_x",
        okLabel: "OK"
    });
}

// mStation funtions

function changeProduct(productID) {
    var o = document.getElementById('mOrb').style;
    var t = document.getElementById('mTower').style;

    var oi = document.getElementById('item_mOrb').style;
    var ti = document.getElementById('item_mTower').style;

    if (productID == "mOrb") {
        t.display = "none";
        o.display = "inline";

        ti.background = "none";
        oi.background = "url(themes/default/images/mstation_back.png)";

    } else {
        o.display = "none";
        t.display = "inline";

        oi.background = "none";
        ti.background = "url(themes/default/images/mstation_back.png)";
    }
}

var gmap = null;
var peoria_point = null;
var scotts_point = null;
var peoria_marker = null;
var scotts_marker = null;


function mapPanTo(newLocation, obj) {
    if (null !== obj) {
	   var effect = new Effect.Highlight(obj.parentNode, {
	        startcolor: '#fef874',
	        endcolor: '#d4d9e2'
	    });
	}

    var mapimages = $$('img.mapimage');
    mapimages.each(function (e) {
        e.removeClassName('on');
    });

    obj.children[0].addClassName("on");

    var peoria_az = "<table width='100%'><tr><td width='50%'>" + "<span class='maptitle'>MacMedia, Inc. Peoria [New Location]</span><br/>" + "15525 N 83rd Ave.<br/>" + "Suite 108<br>Peoria, AZ 85382<br/>" + "</td><td valign='top' width='50%'><span class=\"maptitle\">Store Hours</span><br/>" + "Mon-Thu 10am-7pm<br/>" + "Fri-Sat 10am-8pm<br/>" + "Sunday 12am-6pm" + "</td></tr></table>";


    var scottsdale_az = "<table width='100%'><tr><td width='50%'>" + "<span class=\"maptitle\">MacMedia, Inc. Scottsdale</span><br/>" + "6928 East Fifth Avenue.<br/>" + "Suite 1<br>Scottsdale, AZ 85251<br/>" + "</td><td valign='top' width='50%'><span class=\"maptitle\">Store Hours</span><br/>" + "Mon-Fri 9am-6pm<br/>" + "Saturday 10am-4pm<br/>" + "Sunday Closed [Peoria Open]" + "</td></tr></table>";


    //var locationA = "<span class=\"maptitle\">MacMedia, Inc. Peoria</span><br>8215 West Bell Road.<br>Suite 122<br>Peoria, AZ 85382";
    //var locationB = "<span class=\"maptitle\">MacMedia, Inc. Scottsdale</span><br>6928 East Fifth Avenue.<br>Suite 1<br>Scottsdale, AZ 85251";
    var addObj = document.getElementById('mapaddress');


    if (newLocation == "Peoria") {
        if (gmap){gmap.panTo(peoria_point);}
        addObj.innerHTML = peoria_az; //locationA;
    }

    if (newLocation == "Scottsdale") {
        if (gmap){gmap.panTo(scotts_point);}
        addObj.innerHTML = scottsdale_az; //locationB;
    }
}

function googleInfoWindow(titleline, descline, location) {
    if (gmap){gmap.openInfoWindowHtml(location, "<span class=\"title\">" + titleline + "</span><br><span class=\"desc\">" + descline + "</span>");}
}

function errorTrap(error) {
    alert(error);
}


function fitMap(map, bounds, points) {
    for (var i = 0; i < points.length; i++) {
        bounds.extend(points[i]);
    }
    gmap.fitBounds(bounds);
}

function createTabMarkers(image, point, infoHTML) {

    var markerImageBase = "/themes/default/images/";
    var infowindow = new google.maps.InfoWindow({
        content: infoHTML
    });
    var markerImage = new google.maps.MarkerImage(markerImageBase + image, new google.maps.Size(60, 34));
    var markerShadowImage = new google.maps.MarkerImage(markerImageBase + "shadow-" + image, new google.maps.Size(78, 34), new google.maps.Point(-8, 0));

    var marker = new google.maps.Marker({
        position: point,
        icon: markerImage,
        shadow: markerShadowImage,
        map: gmap
    });

    google.maps.event.addListener(marker, "mouseover", function () {
        infowindow.open(gmap, marker);
    });

}


function mapit() {
    var customer_point;
    peoria_point = new google.maps.LatLng(33.625972, -112.236881);
    scotts_point = new google.maps.LatLng(33.49635488813512, -111.93217232823372);

    var myOptions = {
        zoom: 10,
        center: scotts_point,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        },
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.SMALL
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    
    gmap = new google.maps.Map(document.getElementById("map"), myOptions);

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (position) {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            customer_point = new google.maps.LatLng(lat, lng);
            createTabMarkers("markerCustomer.png", customer_point, '<div class="bubble">Your location.</div>');
        }, errorTrap);
    }

    var points = [customer_point, peoria_point, scotts_point];

    google.maps.event.addListener(gmap, 'tilesloaded', function () {
        google.maps.event.clearListeners(gmap, 'tilesloaded');
        var bounds = gmap.getBounds();
        fitMap(gmap, bounds, points);
    });

    createTabMarkers("marker.png", peoria_point, '<div class="bubble"><table border="0"><tr><td valign="top">Location:</td><td>	15525 N 83rd Ave. #108<br />Peoria AZ 85382</td></tr><tr><td valign="top">Phone:</td><td>623-850-8000</td></tr><tr><td valign="top">Contact:</td><td>Mike Hernandez</td></tr><tr><td>Email:</td><td><a href="mailto:mhernandez@macmediainc.com">mhernandez@macmediainc.com</a></td></tr></table></div>');

    createTabMarkers("marker.png", scotts_point, '<div class="bubble"><table><tr><td valign="top">Location:</td><td>6928 E. Fifth Ave #1<br />Scottsdale AZ 85251</td></tr><tr><td valign="top">Phone:</td><td>480-964-6352</td></tr><tr><td valign="top">Contact:</td><td>John Grubb</td></tr><tr><td>Email:</td><td><a href="mailto:jgrubb@macmediainc.com">jgrubb@macmediainc.com</a></td></tr></table></div>');

}




//Check for valid address fields in schedule form


function checkAddress() {
    var frm = document.forms[0];
    if (frm.custadd1.value && frm.custcity.value && frm.custstate.value && frm.custzip.value) {
        var address = frm.custadd1.value + " " + frm.custcity.value + " " + frm.custstate.value + " " + frm.custzip.value;
        alert(address);
        validateAddress(address);
    }
}


function ajaxCancelEvent(email, id) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    var divElement = document.getElementById('directlink');
    if (document.getElementById("cancelDetails")){document.getElementById("cancelDetails").innerHTML = "";}
    url = "scripts/calendar_db.php";
    var parameters = "datestamp=" + id + "&process=" + "delete" + "&custemail=" + encodeURI(email);

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.responseText !== null) {
                divElement.innerHTML = xmlHttp.responseText;
            }
        }
    };

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
}


function ajaxCancelSchedule() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    var divElement = document.getElementById("cancelDetails");

    url = "scripts/calendar_db.php";
    var parameters = "datestamp=" + encodeURI(document.getElementById("datestamp").value) + "&process=" + encodeURI(document.getElementById("process").value) + "&custemail=" + encodeURI(document.getElementById("custemail").value);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.responseText !== null) {
                divElement.innerHTML = xmlHttp.responseText;
            }
        }
    };

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
}

function scheduleSearch(event) {
    if (event.keyCode == 13){ajaxCancelSchedule();}
}



function ajaxPostSchedule() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    var divElement = document.getElementById('schedule');
    url = "scripts/calendar_db.php";
    var parameters = "datestamp=" + encodeURI(document.getElementById("datestamp").value) + "&process=" + encodeURI(document.getElementById("process").value) + "&eventType=" + encodeURI(document.getElementById("eventType").value) + "&custname=" + encodeURI(document.getElementById("custname").value) + "&custemail=" + encodeURI(document.getElementById("custemail").value) + "&custphone=" + encodeURI(document.getElementById("custphone").value) + "&comments=" + encodeURI(document.getElementById("comments").value) + "&custadd1=" + encodeURI(document.getElementById("custadd1").value) + "&custadd2=" + encodeURI(document.getElementById("custadd2").value) + "&custadd3=" + encodeURI(document.getElementById("custadd3").value) + "&custcity=" + encodeURI(document.getElementById("custcity").value) + "&custzip=" + encodeURI(document.getElementById("custzip").value) + "&storename=" + encodeURI(document.getElementById("storename").value) + "&storenumber=" + encodeURI(document.getElementById("storenumber").value) + "&empname=" + encodeURI(document.getElementById("empname").value) + "&empemail=" + encodeURI(document.getElementById("empemail").value) + "&invnumber=" + encodeURI(document.getElementById("invnumber").value) + "&prodloc=" + encodeURI(document.getElementById("prodloc").value);

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.responseText !== null) {
                divElement.innerHTML = xmlHttp.responseText;
            }
        }
    };

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);

}

function ajaxGetCalendar(dateStamp, obj, style, opts) {
    if (opts){alert("The schedule portion of this web site is not active and only used for testing.");}
    var jsObj = document.getElementById(obj);
    if (!jsObj){return;}

    jsObj.innerHTML = "<div style=\"width:540px;padding-top:50px;padding-bottom:50px;\" align=\"center\" ><img border=\"0\" src=\"/themes/default/images/spinner-blue.gif\">&nbsp;Loading...</div>";

    //alert(this.className);	
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    url = "scripts/calendar.php";
    param = "?ds=" + dateStamp + "&o=" + obj + "&s=" + style + "&" + opts;

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.responseText !== null) {
                jsObj.innerHTML = xmlHttp.responseText;
            }
        }
    };

    xmlHttp.open("GET", url + param, true);
    xmlHttp.send(null);

}

var lastClicked;

function ajaxGetCalendarEvent(eid, objid, style) {

    //objid.style.backgroundcolor = "red";
    if (lastClicked){lastClicked.style.backgroundColor = null;}

    if (objid) {
        if (objid.className == 'current'){objid.style.backgroundColor = '#bdcbdd';}
        lastClicked = objid;
    }

    var jsObj = document.getElementById('details');

    jsObj.innerHTML = "<div style=\"border:1px solid #000;width:540px;padding-top:50px;padding-bottom:50px;background-color:#fff;\" align=\"center\" ><img border=\"0\" src=\"/themes/default/images/spinner-white.gif\">&nbsp;Loading...</div>";

    if (!jsObj){return;}

    xmlHttp2 = GetXmlHttpObject2();
    if (xmlHttp2 === null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    url = "scripts/calendarevents.php";
    param = "?d=" + eid + "&s=" + style;

    xmlHttp2.onreadystatechange = function () {
        if (xmlHttp2.readyState == 4) {
            if (xmlHttp2.responseText !== null) { /*jsObj.style.display="block"; */
                jsObj.innerHTML = xmlHttp2.responseText;
            }
        }
    };

    xmlHttp2.open("GET", url + param, true);	
    xmlHttp2.send(null);
}

function closeAjaxGetCalendarEvent(elementName) {
    var obj = elementName; //document.getElementById(elementName);
    if (!obj){return;}

    obj.style.display = "none";
}

function eventCheckEmail(eid, email) {
    document.forms[0].emailaddress.value = email;
    if (!validEmail(email)) {
        document.getElementById("emailerror").innerHTML = "Invalid email address.";
        return;
    }

    var err = "Address has already been submited.";
    if (email.length === 0) {
        document.getElementById("emailerror").innerHTML = "&nbsp;";
        return;
    }
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp === null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    var url = "rsvp/checkemail.php";
    url = url + "?q=" + email + "&event=" + eid;
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.responseText == "Email has already been submitted!") {
                document.getElementById("emailerror").innerHTML = err;
                document.forms[0].emailaddress.value = "";
            } else {
                document.getElementById("emailerror").innerHTML = "";
            }
            xmlHttp = null;
            checkCode(document.forms[0].user_code.value);
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function checkAvailable(val) {
    var msg = "Space is limited.";
    var xHow = (val == "Scottsdale" ? true : true);
    if (xHow){
		msg = "Sorry, the Adobe event is full or has ended for this location. You may still join us for a mixer afterwards in Scottsdale from 6-9.";
    }
	objElems = document.rsvp.elements;
    for (i = 0; i < objElems.length; i++) {
        objElems[i].disabled = xHow;
    }
    document.rsvp.location.disabled = false;
    document.getElementById("locationmsg").innerHTML = msg;
}


/* Browser */
/**
 * Same logic as before. Have removed some detection capabilities in an effort
 * to reduce reliance on browser detection in general.
 * 
 * If there is a particualr detection you feel you need please file a ticket
 * with the request or add the detection yourself with the exact reason you
 * need said detection. Hopefully we'll be able to keep the number of
 * detection utility functions to a minimum in favor of behavioral testing.
 * 
 * This may also be the place for very common behavioral functions.
 * 
 */

if (typeof(AC) == "undefined") {
    AC = {};
}

AC.Detector = {

    getAgent: function () {
        return navigator.userAgent.toLowerCase();
    },

    // detect platform
    isMac: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/mac/i);
    },

    isWin: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/win/i);
    },

    isWin2k: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return this.isWin(agent) && (agent.match(/nt\s*5/i));
    },

    isWinVista: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return this.isWin(agent) && (agent.match(/nt\s*6/i));
    },

    // detect browser
    isWebKit: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/AppleWebKit/i);
    },

    isOpera: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/opera/i);
    },

    isIE: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/msie/i);
    },

    isIEStrict: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/msie/i) && !this.isOpera(agent);
    },

    isFirefox: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/firefox/i);
    },

    isiPhone: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return agent.match(/iPhone/i);
    },

    // itunes compabibility
    isiTunesOK: function (userAgent) {
        var agent = userAgent || this.getAgent();
        return this.isMac(agent) || this.isWin2k(agent);
    },

    isQTInstalled: function () {

        var qtInstalled = false;

        if (navigator.plugins && navigator.plugins.length) {

            for (var i = 0; i < navigator.plugins.length; i++) {

                var plugin = navigator.plugins[i];

                if (plugin.name.indexOf("QuickTime") > -1) {
                    qtInstalled = true;
                }
            }
        } else {
            qtObj = false; //global variable written to by vbscript for ie
            execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))', 'VBScript');
            qtInstalled = qtObj;
        }

        return qtInstalled;
    },

    getQTVersion: function () {

        var version = "0";

        if (navigator.plugins && navigator.plugins.length) {
            for (var i = 0; i < navigator.plugins.length; i++) {

                var plugin = navigator.plugins[i];

                //Match: QuickTime Plugin X.Y.Z
                var match = plugin.name.match(/quicktime\D*([\.\d]*)/i);
                if (match && match[1]) {
                    version = match[1];
                }
            }
        } else {
            ieQTVersion = null; //global for vbscript to write to
            execScript('on error resume next: ieQTVersion = (Hex(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1").QuickTimeVersion)/1000000)', 'VBScript');

            if (ieQTVersion) {
                //only grab the major version:  7.xyz => 7
                version = (ieQTVersion + "").split(/\./)[0];
            }
        }

        return version;
    },

    isQTCompatible: function (required, actual) {

        function areCompatible(required, actual) {

            var requiredValue = parseInt(required[0],10);
            if (isNaN(requiredValue)) {
                requiredValue = 0;
            }

            var actualValue = parseInt(actual[0],10);
            if (isNaN(actualValue)) {
                actualValue = 0;
            }

            if (requiredValue == actualValue) {
                if (required.length > 1) {
                    return areCompatible(required.slice(1), actual.slice(1));
                } else {
                    return true;
                }
            } else if (requiredValue < actualValue) {
                return true;
            } else {
                return false;
            }
        }

        var expectedVersion = required.split(/\./);
        var actualVersion = actual ? actual.split(/\./) : this.getQTVersion().split(/\./);

        return areCompatible(expectedVersion, actualVersion);

    },

    isValidQTAvailable: function (required) {
        return this.isQTInstalled() && this.isQTCompatible(required);
    }

};


/* Drawer */


if (typeof(AC) == "undefined") {
    AC = {};
}

AC.Bureau = Class.create();
Object.extend(AC.Bureau.prototype, Event.Listener);
Object.extend(AC.Bureau.prototype, {

    drawers: null,
    container: null,

    triggerTimeout: null,

    initialize: function (container) {
        this.drawers = [];
        this.container = $(container);
    },

    addDrawer: function (newDrawer) {},

    getDrawerCount: function () {
        return this.drawers.length;
    },

    hasDrawers: function () {
        return (this.drawers.length > 0);
    },

    getFirstDrawer: function () {
        return this.drawers[0] || null;
    },

    getLastDrawer: function () {
        return this.drawers[this.drawers.length - 1] || null;
    },

    scheduleTrigger: function (onFire, delay) {
        this.triggerTimeout = setTimeout(onFire, delay);
    },

    clearTrigger: function () {
        clearTimeout(this.triggerTimeout);
    }

});

AC.Drawer = Class.create();
Object.extend(AC.Drawer.prototype, Event.Publisher);
Object.extend(AC.Drawer.prototype, {

    bureau: null,

    contentElement: null,
    handle: null,
    indicator: null,

    isOpen: true,

    beforeOpen: null,
    afterOpen: null,

    beforeClose: null,
    afterClose: null,

    transitionDuration: 0.3,
    triggerDelay: 0,





    initialize: function (contentElement, handleElement, bureau, options) {

        this.contentElement = contentElement;
        this.handle = handleElement;
        this.bureau = bureau;

        var triggerEvent = 'click';

        if (options !== null && typeof(options) != 'undefined') {
            this.beforeOpen = options.beforeOpen;
            this.afterOpen = options.afterOpen;
            this.beforeClose = options.beforeClose;
            this.afterClose = options.afterClose;


            if (typeof(options.triggerEvent) != 'undefined') {
                triggerEvent = options.triggerEvent;
            }

            if (typeof(options.triggerDelay) != 'undefined') {
                this.triggerDelay = options.triggerDelay;
            }

            if (typeof(options.transitionDuration) != 'undefined') {
                this.transitionDuration = options.transitionDuration;
            }
        }

        if (AC.Detector.isiPhone()) {
            this.transitionDuration = 0;
            triggerEvent = 'click';
        }

        Element.addClassName(this.contentElement, 'last');

        var fireTrigger = function (evt) {

            Event.stop(evt);

            if (this.triggerDelay > 0) {
                var onFire = this.trigger.bind(this);
                bureau.scheduleTrigger(onFire, this.triggerDelay);
            } else {
                this.trigger();
            }
        };

        Event.observe(this.handle, triggerEvent, fireTrigger.bind(this), false);
        Event.observe(this.handle, 'mouseout', bureau.clearTrigger.bind(bureau), false);

    },

    toggle: function () {},

    open: function () {},

    close: function () {}

});


AC.SlidingBureau = Class.create();
Object.extend(AC.SlidingBureau.prototype, AC.Bureau.prototype);

Object.extend(AC.SlidingBureau.prototype, {

    isLocked: false,

    addDrawer: function (newDrawer) {

        Element.addClassName(newDrawer.contentElement, 'last');
        Element.addClassName(newDrawer.handle, 'last');

        if (this.hasDrawers()) {

            var lastDrawer = this.getLastDrawer();

            lastDrawer.setNextDrawer(newDrawer);
            newDrawer.setPreviousDrawer(lastDrawer);
        } else {
            Element.addClassName(newDrawer.contentElement, 'first');
            Element.addClassName(newDrawer.handle, 'first');
        }

        this.listenForEvent(newDrawer, 'beforeOpen', false, function (evt) {
            var drawer = evt.event_data.data;
            this.open(drawer);
        });

        this.listenForEvent(newDrawer, 'afterOpen', false, function (evt) {
            var drawer = evt.event_data.data;
            this.acknowledgeOpened(drawer);
        });

        this.listenForEvent(newDrawer, 'beforeClose', false, function (evt) {
            var drawer = evt.event_data.data;
            this.close(drawer);
        });

        this.listenForEvent(newDrawer, 'afterClose', false, function (evt) {
            var drawer = evt.event_data.data;
            this.acknowledgeClosed(drawer);
        });


        if (!Element.hasClassName(newDrawer.contentElement, 'open')) {
            newDrawer.initiateClose();
        } else {
            this.currentDrawer = newDrawer;
        }

        this.drawers.push(newDrawer);
    },

    open: function (drawer) {
		var minHeight;
        if (this.isLocked) {
            return;
        }

        this.isLocked = true;
		
        if (Element.getStyle(this.container, 'position') == 'relative') {

            var dimensions = Element.getDimensions(this.container);
            Element.setStyle(this.container, {
                height: dimensions.height + "px"
            });

            this.wedgeDrawersAfter(drawer);

            minHeight = Element.getStyle(drawer.contentElement, 'min-height');

            if (minHeight) {
                Element.setStyle(drawer.contentElement, {
                    'min-height': '0px',
                    height: minHeight
                });
            }
        }


        if (this.currentDrawer) {
            this.currentDrawer.initiateClose();
        }

        drawer.open(minHeight);
    },

    acknowledgeOpened: function (drawer) {
        this.currentDrawer = drawer;

        if (Element.getStyle(this.container, 'position') == 'relative') {
            if (!AC.Detector.isIEStrict()) {
                Element.setStyle(this.container, {
                    height: "auto"
                });
            }
            this.unwedgeDrawers();
        }

        this.isLocked = false;
    },

    close: function (drawer) {
		var minHeight;
        if (Element.getStyle(this.container, 'position') == 'relative') {
            minHeight = Element.getStyle(drawer.contentElement, 'min-height');

            if (minHeight) {
                Element.setStyle(drawer.contentElement, {
                    height: minHeight,
                    'min-height': '0px'
                });
            }
        }

        drawer.close(minHeight);
    },

    acknowledgeClosed: function (drawer) {
        if (drawer == this.currentDrawer) {
            this.currentDrawer = null;
        }
    },

    wedgeDrawersAfter: function (drawerBeingOpened) {

        var wedgeDrawer = function (drawer, offset) {
            Element.setStyle(drawer.handle, {
                position: 'absolute',
                bottom: offset + 'px'
            });
        };

        var drawer = this.getLastDrawer();
        var offset = 0;

        while (drawer != this.currentDrawer && drawer != drawerBeingOpened) {
            wedgeDrawer(drawer, offset);
            offset += drawer.handle.getHeight();
            drawer = drawer.previousDrawer;
        }

    },

    unwedgeDrawers: function () {
        for (var i = this.drawers.length - 1; i >= 0; i--) {
            Element.setStyle(this.drawers[i].handle, {
                position: 'static'
            });
        }
    }


});

AC.SlidingDrawer = Class.create();
Object.extend(AC.SlidingDrawer.prototype, AC.Drawer.prototype);
Object.extend(AC.SlidingDrawer.prototype, {

    isOpen: true,
    isTransitioning: false,

    setNextDrawer: function (drawer) {
        this.nextDrawer = drawer;
        Element.removeClassName(this.contentElement, 'last');
        Element.removeClassName(this.handle, 'last');
    },

    setPreviousDrawer: function (drawer) {
        this.previousDrawer = drawer;
    },

    trigger: function () {
        this.toggle();
    },

    toggle: function () {

        if (!this.isOpen) {
            this.initiateOpen();
        }

    },

    initiateOpen: function () {

        if (this.isTransitioning || this.isOpen) {
            return;
        }

        this.dispatchEvent('beforeOpen', this);

    },

    open: function (minHeight) {

        this.isTransitioning = true;


        Element.addClassName(this.contentElement, 'open');
        Element.addClassName(this.handle, 'open');

        var afterFinish = function () {
            this.isOpen = true;
            if (minHeight) {
                Element.setStyle(this.contentElement, {
                    'min-height': minHeight
                });
                if (!AC.Detector.isIEStrict()) {
                    Element.setStyle(this.contentElement, {
                        'height': 'auto'
                    });
                }
            }
            this.dispatchEvent('afterOpen', this);
            this.isTransitioning = false;
        }.bind(this);

        if (AC.Detector.isiPhone()) {
            this.contentElement.show();
            afterFinish();
        } else {
            var effect = new Effect.BlindDown(this.contentElement, {
                duration: this.transitionDuration,
                afterFinish: afterFinish
            });
        }
    },

    initiateClose: function (force) {

        if (this.isTransitioning || !this.isOpen) {
            return;
        }

        this.dispatchEvent('beforeClose', this);
    },

    close: function (minHeight) {

        this.isTransitioning = true;

        var afterFinish = function () {
            this.isOpen = false;
            Element.removeClassName(this.contentElement, 'open');
            Element.removeClassName(this.handle, 'open');
            if (minHeight) {
                Element.setStyle(this.contentElement, {
                    'min-height': minHeight
                });
                if (!AC.Detector.isIEStrict()) {
                    Element.setStyle(this.contentElement, {
                        'height': 'auto'
                    });
                }
            }
            this.dispatchEvent('afterClose', this);
            this.isTransitioning = false;
        }.bind(this);

        if (AC.Detector.isiPhone()) {
            this.contentElement.hide();
            afterFinish();
        } else {
            var effect = new Effect.BlindUp(this.contentElement, {
                duration: this.transitionDuration,
                afterFinish: afterFinish
            });
        }


    }


});


AC.ShingleBureau = Class.create();
Object.extend(Object.extend(AC.ShingleBureau.prototype, AC.Bureau.prototype), {

    drawerDuration: 0.5,

    addDrawer: function (newDrawer) {


        if (this.hasDrawers()) {

            var lastDrawer = this.getLastDrawer();

            lastDrawer.setNextDrawer(newDrawer);
            newDrawer.setPreviousDrawer(lastDrawer);
            newDrawer.closedOffset = lastDrawer.closedOffset + lastDrawer.getHandleHeight() - 10;
        } else {
            Element.addClassName(newDrawer.contentElement, 'first');
            newDrawer.closedOffset = 0 - newDrawer.getHeight() + newDrawer.getHandleHeight() - 10;
            newDrawer.indicateVisible();
        }


        this.drawers.push(newDrawer);
    },

    getWidth: function () {
        return Element.getWidth(this.container);
    },

    getHeight: function () {
        return Element.getHeight(this.container);
    },

    moveDrawer: function (drawer, x, y) {
        var effect = new Effect.Move(drawer, {
            x: x,
            y: y,
            mode: 'absolute',
            transition: Effect.Transitions.sinoidal,
            duration: this.drawerDuration
        });
    }

});

AC.ShingleDrawer = Class.create();
Object.extend(Object.extend(AC.ShingleDrawer.prototype, AC.Drawer.prototype), {

    openedOffset: 0,
    closedOffset: 0,

    previousDrawer: null,
    nextDrawer: null,

    isVisible: false,

    trigger: function () {
        sidebarShinglesAutoLoader();
        if (!this.isVisible) {
            this.open(true);
            this.indicateVisible();
        }
    },

    toggle: function () {

        if (!this.isOpen) {
            this.open();
            this.indicateVisible();
        } else {
            this.close();
        }

    },

    open: function (force) {

        if (this.isOpen && !force) {
            return;
        }

        if (this.previousDrawer !== null) {
            this.previousDrawer.close();
            this.previousDrawer.indicateObscured();
        }

        if (this.nextDrawer !== null) {
            this.nextDrawer.open();
            this.nextDrawer.indicateObscured();
        }

        this.indicateVisible();
        this.isOpen = true;

        this.bureau.moveDrawer(this.contentElement, 0, this.openedOffset);
    },

    close: function (force) {

        if (!this.isOpen) {
            return;
        }

        if (this == this.bureau.getLastDrawer()) {
            return;
        }

        if (this.previousDrawer !== null) {
            this.previousDrawer.close();
        }

        this.bureau.moveDrawer(this.contentElement, 0, this.closedOffset);
        this.indicateObscured();
        this.isOpen = false;

    },

    setPreviousDrawer: function (drawer) {
        this.previousDrawer = drawer;

        this.indicateObscured();

        this.openedOffset = this.previousDrawer.openedOffset + this.previousDrawer.getHandleHeight() - 10;
        Element.setStyle(this.contentElement, {
            top: this.openedOffset + "px"
        });
    },

    setNextDrawer: function (drawer) {
        this.nextDrawer = drawer;

        Element.removeClassName(this.contentElement, 'last');

        if (this.previousDrawer !== null) {
            this.previousDrawer.setNextDrawer(this);
        }


        zIndex = parseInt(Element.getStyle(this.contentElement, 'zIndex'),10);
        Element.setStyle(this.contentElement, {
            'zIndex': zIndex + 1
        });
    },

    indicateObscured: function () {
        Element.addClassName(this.contentElement, 'obscured');
        this.isVisible = false;
    },

    indicateVisible: function () {
        this.isVisible = true;
        Element.removeClassName(this.contentElement, 'obscured');
    },

    getHandleWidth: function () {
        return Element.getWidth(this.handle);
    },

    getHandleHeight: function () {
        return Element.getHeight(this.handle);
    },

    getWidth: function () {
        return Element.getWidth(this.contentElement);
    },

    getHeight: function () {
        return Element.getHeight(this.contentElement);
    }


});

AC.SectionBureau = Class.create();
Object.extend(AC.SectionBureau.prototype, AC.Bureau.prototype);
Object.extend(AC.SectionBureau.prototype, {

    currentDrawer: null,
    locked: false,

    addDrawer: function (newDrawer) {
        this.drawers.push(newDrawer);
        newDrawer.handle.addClassName('obscured');
        Element.hide(newDrawer.contentElement);
    },

    openingDrawer: function (drawer) {
        if (this.currentDrawer !== null) {
            this.currentDrawer.close();
        }

        this.currentDrawer = drawer;
    }

});

AC.SectionDrawer = Class.create();
Object.extend(AC.SectionDrawer.prototype, AC.Drawer.prototype);
Object.extend(AC.SectionDrawer.prototype, {

    isOpen: false,

    trigger: function () {
        this.toggle();
    },

    toggle: function () {

        if (!this.isOpen) {
            this.open();
        }

    },

    open: function () {

        if (this.bureau.locked) {
            return;
        }

        var afterTransition = function () {
            Element.show(this.contentElement);
        }.bind(this);






        if (typeof(this.afterOpen) == 'function') {
            this.bureau.locked = true;
            afterTransition = this.afterOpen.bind(this);
        }

        this.bureau.openingDrawer(this);

        if (typeof(this.beforeOpen) == 'function') {
            this.beforeOpen();
        }

        this.isOpen = true;
        Element.removeClassName(this.handle, 'obscured');

        var effect = new Effect.Appear(this.contentElement, {
            afterFinish: afterTransition,
            duration: this.transitionDuration,
            queue: {
                scope: 'sectionalscope'
            }
        });


    },

    close: function () {

        if (typeof(this.beforeClose) == 'function') {
            this.beforeClose();
        }

        this.isOpen = false;
        Element.addClassName(this.handle, 'obscured');

        var afterTransition = function () {
            if (typeof(this.afterClose) == 'function') {
                this.afterClose();
            }

        }.bind(this);

        var effect = new Effect.Fade(this.contentElement, {
            afterFinish: afterTransition,
            duration: this.transitionDuration,
            queue: {
                scope: 'sectionalscope'
            }
        });

    },

    reportFinishedOpening: function () {
        this.bureau.locked = false;
    }

});