﻿
function popImage(imageURL, imageTitle) {
    //really not important (the first two should be small for Opera's sake)
    PositionX = 5;
    PositionY = 5;
    defaultWidth = 200;
    defaultHeight = 200;
    //kinda important
    var AutoClose = true;
    var imgWin = window.open(imageURL, '_blank', 'scrollbars=yes,resizable=1,width=' + defaultWidth + ',height=' + defaultHeight + ',left=' + PositionX + ',top=' + PositionY);
    if (!imgWin) { //popup blockers should not cause errors
        return true;
    }
    imgWin.document.write('<html>\n' +
  	'<head>\n' +
	'	<title>' + imageTitle + '<\/title>\n' +
	'	<style type="text\/css">\n' +
	'		#images{visibility: hidden;}\n' +
	'	<\/style>\n' +
	'	<script language="javascript">\n' +
	'		function showImages(divId){\n' +
	'   		document.getElementById(divId).style.visibility = "visible";\n' +
	'		}\n' +
	'	<\/script>\n' +
	'	<script type="text\/javascript">\n' +
    '		function resizeWinTo() {\n' +
    '			if( !document.images.length ) { \n' +
	'				document.images[0] = document.layers[0].images[0]; \n' +
	'			} \n' +
    '			var oH = document.images[0].height; \n' +
	'			var oW = document.images[0].width; \n' +
    '			if( !oH || window.doneAlready ) { \n' + //in case images are disabled
	'				return; \n' +
	'			}\n' +
    '			window.doneAlready = true;\n' + //for Safari and Opera
    '			var x = window; \n' +
	'			x.resizeTo( oW + 200, oH + 200 );\n' +
    '			var myW = 0;\n' +
	'			var myH = 0;\n' +
	'			var d = x.document.documentElement;\n' +
	'			var b = x.document.body;\n' +
    '			if( x.innerWidth ) { \n' +
	'				myW = x.innerWidth; \n' +
	'				myH = x.innerHeight; \n' +
	'			} else if( d && d.clientWidth ) { \n' +
	'				myW = d.clientWidth; \n' +
	'				myH = d.clientHeight; \n' +
	'			} else if( b && b.clientWidth ) { \n' +
	'				myW = b.clientWidth; \n' +
	'				myH = b.clientHeight; \n' +
	'			}\n' +
    '			if( window.opera && !document.childNodes ) { \n' +
	'				myW += 16; \n' +
	'			}\n' +
    '			x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 205 ) - myH ) );\n' +
    '			var scW = screen.availWidth ? screen.availWidth : screen.width;\n' +
    '			var scH = screen.availHeight ? screen.availHeight : screen.height;\n' +
    '			if( !window.opera ) { \n' +
	'				x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); \n' +
	'			}\n' +
    '		}\n' +
    '	<\/script>\n' +
    '<\/head>\n' +
	'<body bgcolor="#171717" onload="resizeWinTo();"' + (AutoClose ? '' : '') + '>' +
    (document.layers ? ('<layer left="0" top="0">') : ('\n' +
	'	<div style="position:absolute;left:0px;top:0px;display:table;background: white url(images/screenshot_images/loadingimage.gif) no-repeat scroll top left;">\n')) +
	'		<div id="images">' +
	'			<img src="' + imageURL + '" alt="Loading image ..." title="" onload="showImages(\'images\');resizeWinTo();">' +
	'		<\/div>\n' +
    (document.layers ? '<\/layer>' : '	<\/div>\n') + '<\/body>\n<\/html>');
    imgWin.document.close();
    imgWin.focus();
}
function sideimage(sidedepartment) {
    var deptimages = new Array();
    if (sidedepartment == "techsupport") {
        deptimages[1] = Array('tech_support_01.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
        deptimages[2] = Array('tech_support_02.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
        deptimages[3] = Array('tech_support_03.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
        deptimages[4] = Array('tech_support_04.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
        deptimages[5] = Array('tech_support_05.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
        deptimages[6] = Array('tech_support_06.jpg', 'Tech Support<br>9am - 5:45pm CST M-F', "Tech Support");
    } else if (sidedepartment == "sales") {
        deptimages[1] = Array('f_sales_01.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
        deptimages[2] = Array('f_sales_02.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
        deptimages[3] = Array('f_sales_03.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
        deptimages[4] = Array('f_sales_04.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
        deptimages[5] = Array('f_sales_05.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
        deptimages[6] = Array('f_sales_04.jpg', 'TanTrack Sales<br>8am - 5pm CST M-F', "Sales");
    }
    var randomnumber = Math.ceil(6 * Math.random());
    document.write("<img src='images/sidebar_images/" + deptimages[randomnumber][0] + "' width='150px' style='border:Solid 2px #000000;' title='TanTrack " + deptimages[randomnumber][2] + "' alt='TanTrack " + deptimages[randomnumber][2] + "'><br />" + deptimages[randomnumber][1] + "<hr />");
    var day = "";
    var month = "";
    var myweekday = "";
    var year = "";
    newdate = new Date();
    mydate = new Date();
    dston = new Date('April 4, 1999 2:59:59');
    dstoff = new Date('october 31, 1999 2:59:59');
    var myzone = newdate.getTimezoneOffset();
    newtime = newdate.getTime();

    var zone = 6;  // references your time zone

    if (newdate > dston && newdate < dstoff) {
        zonea = zone - 1;
        dst = "  Pacific Daylight Savings Time";
    }
    else {
        zonea = zone; dst = "  Pacific Standard Time";
    }
    var newzone = (zonea * 60 * 60 * 1000);
    newtimea = newtime + (myzone * 60 * 1000) - newzone;
    mydate.setTime(newtimea);
    myday = mydate.getDay();
    mymonth = mydate.getMonth();
    myweekday = mydate.getDate();
    myyear = mydate.getYear();
    year = myyear;

    if (year < 2000)
        year = year + 1900;
    myhours = mydate.getHours();
    if (myhours >= 12) {
        myhours = (myhours == 12) ? 12 : myhours - 12; mm = " PM";
    }
    else {
        myhours = (myhours == 0) ? 12 : myhours; mm = " AM";
    }
    myminutes = mydate.getMinutes();
    if (myminutes < 10) {
        mytime = ":0" + myminutes;
    }
    else {
        mytime = ":" + myminutes;
    };
    arday = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat")
    armonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec")
    armonthnumber = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
    ardate = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
    
    // rename locale as needed.

    var time = ("<font color='#000000'>Current " + deptimages[randomnumber][2] + " Time Is:<br />" + myhours + mytime + mm + ", " + arday[myday] + ", " + armonth[mymonth] + " " + ardate[myweekday] + ", " + year + "</font>");
    //alert(myhours + mytime + mm + ", " + arday[myday] + ", " + armonth[mymonth] + " " + ardate[myweekday] + ", " + year);
    var isholiday = holiday(armonthnumber[mymonth], ardate[myweekday], year, arday[myday], myhours, mytime, mm, "techsupport");
    if (isholiday != "normalday") {
        document.write("<strong>" + deptimages[randomnumber][2] + " is : Closed</strong><br />" + holiday(armonthnumber[mymonth], ardate[myweekday], year, arday[myday], myhours, mytime, mm, "techsupport"));
    } else if (arday[myday] == "Sunday") {
        document.write("<strong>" + deptimages[randomnumber][2] + " is : Closed</strong>");
    } else if (arday[myday] == "Saturday") {
        document.write("<strong>" + deptimages[randomnumber][2] + " is : Closed</strong>");
    } else if (mm == " PM") {
        if ((myhours >= 6) && (myhours != 12)){
            document.write("<strong>" + deptimages[randomnumber][2] + " is : Closed</strong>");
        } else {
            document.write(time);
        }
    } else if (mm == " AM") {
        if (myhours < 9) {
            document.write("<strong>" + deptimages[randomnumber][2] + " is : Closed</strong>");
        } else {
            document.write(time);
        }
    }
}
function holiday(cmonth, cday, cyear, cdayofweek, cmyhours, cmytime, cmm, department) {
    //alert(cmonth + "/" + cday + "/" + cyear + "-" + cdayofweek + cmyhours +  cmytime + "" + cmm);
    day = cdayofweek;
    month = cmonth - 1;
    date = cday;
    year = cyear;
    if (year < 1000)
        year += 1900
    cent = parseInt(year / 100);
    g = year % 19;
    k = parseInt((cent - 17) / 25);
    i = (cent - parseInt(cent / 4) - parseInt((cent - k) / 3) + 19 * g + 15) % 30;
    i = i - parseInt(i / 28) * (1 - parseInt(i / 28) * parseInt(29 / (i + 1)) * parseInt((21 - g) / 11));
    j = (year + parseInt(year / 4) + i + 2 - cent + parseInt(cent / 4)) % 7;
    l = i - j;
    emonth = 3 + parseInt((l + 40) / 44);
    edate = l + 28 - 31 * parseInt((emonth / 4));
    emonth--;
    var dayname = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    var monthname = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    if ((month == 0) && (date == 1)) document.write("Happy Holidays");                                                                          // New Years Day
    if ((month == 4) && (day == 1) && (date > 24)) { var output = "Happy Holidays"; return output; }                                            // Memorial Day
    if ((month == 6) && (date == 4)) { var output = "Happy Holidays"; return output; }                                                          // Independence Day
    if ((month == 8) && (day == 1) && (date > 0) && (date < 8)) { var output = "Happy Holidays"; return output; }                               // Labor Day
    if ((month == 10) && (day == 4) && (date > 23) && (date < 30)) { var output = "Happy Holidays"; return output; }                            // Thanksgiving
    if ((month == 10) && (date == 30) && (day == 4)) { var output = "Happy Holidays"; return output; }                                          // Thanksgiving
    if ((month == 11) && (date == 25)) { var output = "Happy Holidays"; return output; }                                                        // Christmas
    if (department == "techsupport") {
        if ((month == 11) && (date == 24) && (cmm == "PM") && (cmyhours >= 12) && (cmytime > 45)) { var output = "Happy Holidays"; return output; } // Christmas Eve 1/2 day
        if ((month == 11) && (date == 31) && (cmm == "PM") && (cmyhours >= 12) && (cmytime > 45)) { var output = "Happy Holidays"; return output; } // New Years Eve 1/2 day
    } else if (department == "sales") {
        if ((month == 11) && (date == 24) && (cmm == "AM") && (cmyhours >= 11) && (cmytime > 45)) { var output = "Happy Holidays"; return output; } // Christmas Eve 1/2 day
        if ((month == 11) && (date == 31) && (cmm == "AM") && (cmyhours >= 11) && (cmytime > 45)) { var output = "Happy Holidays"; return output; } // New Years Eve 1/2 day
    }
    return "normalday";
}
