/*
	Date Format 1.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT license
	With code by Scott Trenda (Z and o flags, and enhanced brevity)
*/

/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);
		
		cy = function(yr){
			yr = parseInt(yr);
			if (yr <= 2000)
			{yr=yr + 100}
			else
			{yr=yr}
			return yr;
		};
		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: cy(y),
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}


// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();
// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject()
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// if running Internet Explorer
if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlHttp = false;
}
}
// if running Mozilla or other browsers
else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}
// return the created object or display an error message
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}
// make asynchronous HTTP request using the XMLHttpRequest object
function process()
{
// proceed only if the xmlHttp object isn't busy
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
// retrieve the name typed by the user on the form
tplValue = encodeURIComponent(document.getElementById("r1").value);
dsnValue = encodeURIComponent(document.getElementById("r2").value);
if(dsnValue == "1"){
	document.getElementById("varLink").href = "javascript: openWindowF1('samples1.html#http://www.propointgraphics.com/director/albums/album-137/cache/CSD5650_1.jpg_431_306_0_80_1_50_50.jpg');";
	document.getElementById("varLink2").href = "javascript: openWindowF1('samples1.html#http://www.propointgraphics.com/director/albums/album-137/cache/CSD5650_1.jpg_431_306_0_80_1_50_50.jpg');";
}
else if(dsnValue == "2"){
document.getElementById("varLink").href = "javascript: openWindowF1('samples3.html#http://www.propointgraphics.com/director/albums/album-156/cache/ACR10128_1.jpg_431_306_0_80_1_50_50.jpg');";
document.getElementById("varLink2").href = "javascript: openWindowF1('samples3.html#http://www.propointgraphics.com/director/albums/album-156/cache/ACR10128_1.jpg_431_306_0_80_1_50_50.jpg');";
}
if(document.getElementById("popup_container").value != "MM/DD/YY"){
dayValue = encodeURIComponent(dateFormat(document.getElementById("popup_container").value,"mm/dd/yyyy"));}
else
dayValue = dateFormat("01/01/08","mm/dd/yyyy");
slideCount = encodeURIComponent(document.getElementById("sC").options[document.getElementById("sC").selectedIndex].text);
// execute the quickstart.php page from the server
xmlHttp.open("GET", "quickstart.php?tV=" + tplValue +  "&sC=" + slideCount + "&dV=" + dsnValue+ "&dDay=" + dayValue, true);
// define the method to handle server responses
xmlHttp.onreadystatechange = handleServerResponse;
// make the server request
xmlHttp.send(null);
}
else
// if the connection is busy, try again after one second
setTimeout('process()', 100);
}
// executed automatically when a message is received from the server
function handleServerResponse()
{
// move forward only if the transaction has completed
if (xmlHttp.readyState == 4)
{
// status of 200 indicates the transaction completed successfully
if (xmlHttp.status == 200)
{
// extract the XML retrieved from the server
xmlResponse = xmlHttp.responseXML;
// obtain the document element (the root element) of the XML structure
xmlDocumentElement = xmlResponse.documentElement;
// get the text message, which is in the first child of
// the the document element
//tplCost = xmlDocumentElement.getElementsByTagName('tC');
// update the client display using the data received from the server
//document.getElementById("divtC").innerHTML =
//tplCost[0].firstChild.nodeValue;
//sCost = xmlDocumentElement.getElementsByTagName('sC');
// update the client display using the data received from the server
//document.getElementById("divsC").innerHTML =
//sCost[0].firstChild.nodeValue;
sT = xmlDocumentElement.getElementsByTagName('tot');
// update the client display using the data received from the server
document.getElementById("sTot").innerHTML =
sT[0].firstChild.nodeValue;
// update the client display using the data received from the server
spC = xmlDocumentElement.getElementsByTagName('spCmt');
if(spC[0].firstChild.nodeValue != "-"){
document.getElementById("spCmt").innerHTML =
spC[0].firstChild.nodeValue;}
else{
document.getElementById("spCmt").innerHTML = "<img src='images/1X1.gif' border='0'/>";	
}
dDay = xmlDocumentElement.getElementsByTagName('dD');
document.getElementById("dDate").innerHTML =
dDay[0].firstChild.nodeValue;
altone = xmlDocumentElement.getElementsByTagName('alt1');
document.getElementById("alt_1").href =
altone[0].firstChild.nodeValue;
altone_1 = xmlDocumentElement.getElementsByTagName('alt1_1');
if(altone_1[0].firstChild.nodeValue != "-"){
document.getElementById("alt_1").innerHTML =
altone_1[0].firstChild.nodeValue;}
else{
document.getElementById("alt_1").innerHTML = "<img src='images/1X1.gif' border='0'/>";	
}
alttwo = xmlDocumentElement.getElementsByTagName('alt2');
document.getElementById("alt_2").href =
alttwo[0].firstChild.nodeValue;
alttwo_1 = xmlDocumentElement.getElementsByTagName('alt2_1');
if(alttwo_1[0].firstChild.nodeValue != "-"){
document.getElementById("alt_2").innerHTML =
alttwo_1[0].firstChild.nodeValue;}
else{
document.getElementById("alt_2").innerHTML = "<img src='images/1X1.gif' border='0'/>";	
}
altthree = xmlDocumentElement.getElementsByTagName('alt3');
document.getElementById("alt_3").href =
altthree[0].firstChild.nodeValue;
altthree_1 = xmlDocumentElement.getElementsByTagName('alt3_1');
if(altthree_1[0].firstChild.nodeValue != "-"){
document.getElementById("alt_3").innerHTML =
altthree_1[0].firstChild.nodeValue;}
else{
document.getElementById("alt_3").innerHTML = "<img src='images/1X1.gif' border='0'/>";	
}

subcost = xmlDocumentElement.getElementsByTagName('sub');
document.getElementById("subt").innerHTML =
subcost[0].firstChild.nodeValue;
prcost = xmlDocumentElement.getElementsByTagName('pc');
document.getElementById("pcost").innerHTML =
prcost[0].firstChild.nodeValue;
decost = xmlDocumentElement.getElementsByTagName('dc');
document.getElementById("dcost").innerHTML =
decost[0].firstChild.nodeValue;
tecost = xmlDocumentElement.getElementsByTagName('tC');
document.getElementById("tcost").innerHTML =
tecost[0].firstChild.nodeValue;
totalcost = xmlDocumentElement.getElementsByTagName('tot');
document.getElementById("total").value =
totalcost[0].firstChild.nodeValue;
// restart sequence
//setTimeout('process()', 100);
}
// a HTTP status different than 200 signals an error
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}