wkdays = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
WEEK_STR = new Array("SUN","MON","TUE","WED","THU","FRI","SAT");
MONTH_STR = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
weeks = 3;
shipping_type = "standard";
draw_table_only = false;

Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */

	dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
	var newYear = new Date(this.getFullYear(),0,1);
	var day = newYear.getDay() - dowOffset; //the day of week the year begins on
	day = (day >= 0 ? day : day + 7);
	var daynum = Math.floor((this.getTime() - newYear.getTime() - 
	(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
	var weeknum;
	//if the year starts before the middle of a week
	/*
	if(day < 4) {
		weeknum = Math.floor((daynum+day-1)/7) + 1;
		if(weeknum > 52) {
			nYear = new Date(this.getFullYear() + 1,0,1);
			nday = nYear.getDay() - dowOffset;
			nday = nday >= 0 ? nday : nday + 7;
			weeknum = nday < 4 ? 1 : 53;
		}
	}
	else {
		weeknum = Math.floor((daynum+day-1)/7);
	}
	*/
	weeknum = Math.floor((daynum+day-1)/7) + 1;
	return weeknum;
};


function $(name){
	return document.getElementById(name);
}

/* Function drawCalendar2 on Get-It-Fast.html */
function drawCalendar2(ele, shipping_type){
	if( shipping_type != 'standard' && shipping_type != 'express' )	return false;
	element = $(ele);
	
	/* draw tabs */
	div_Tabs 	= newEle("div");
	div_Tabs.id = 'div_tabs';
	div_std 	= newEle("div");
	div_std.id = 'std_calendar_tab';
	div_std.className = 'calendar_tab';
	div_exp 	= newEle("div");
	div_exp.id = 'exp_calendar_tab';
	div_exp.className = 'calendar_tab';
	div_std.appendChild( newText("Standard") );
	div_exp.appendChild( newText("Express") );
	div_std.onclick = function() { chgCalendar2('info_calendar','standard'); };
	div_exp.onclick = function() { chgCalendar2('info_calendar','express'); };
	if( shipping_type == 'standard') {
		element.className = "info_standard";
	}
	else {
		element.className = "info_express";
	}
	div_Tabs.appendChild( div_std );
	div_Tabs.appendChild( div_exp );
	
	/* draw shipping content*/
	div_Table 	= newEle("div");
	div_Table.id = "div_table";
	table 	= newEle("table");
	table.id = "tbl_content";
	tbody	= newEle("tbody");
	row1 	= newEle("tr");
	table.appendChild(tbody);
	div_Table.appendChild(table);
	tbody.appendChild(row1);
	
	for(i=0;i<wkdays.length;i++){
		wkday = newEle("th");
		wkday.appendChild(newText(wkdays[i]));
		row1.appendChild(wkday);
	}
	
	//alert(ref_date);
	today 	= new Date();
	proof_date 		= getNextNBizDayFromDate(today,1);
	prd_date 		= getNextNBizDayFromDate(today,2);
	shipped_date	= getNextNBizDayFromDate(today,3);
	fedex_begin_date		= getNextNBizDayFromDate(today,4);
	fedex_end_date			= getNextNBizDayFromDate(today,5);
	delivered_date	= getNextNBizDayFromDate(today,6);
	sunday 	= getThisSunday(today);
	if(today.getDay() < 3)	sunday.setDate(sunday.getDate()-7);

	satday 	= getDateLater(sunday, 7 * weeks -1);
	old_mth = sunday.getMonth() + 1;
		
	for(i=0;i<weeks;i++){
		row = newEle("tr");
		tbody.appendChild(row);
		for(j=0;j<7;j++){
			day 	= newEle("td");
			div1	= newEle("div");
			div1.className = "day_title";
			div2	= newEle("div");
			div2.className = "day_content";
			row.appendChild(day);
			day.appendChild(div1);
			day.appendChild(div2);
			date 	= new Date();
			date.setTime(sunday.getTime());
			date.setDate(date.getDate()+j+i*7);
			label 	= ( date.getMonth()+1 != old_mth && date.getDate() == 1)?months[date.getMonth()]:"";
			label	= label + " " + date.getDate();
			//if( i==0 && j==0 )	label = months[date.getMonth()] + " " + date.getDate();
			div1.appendChild(newText(label));
			if( j==0 ){
				wknum = newEle("div");
				wknum.className = "weeknum";
				wknum.appendChild( newText( date.getWeek(0) ) );
				//wknum.style.cssText = " width: 26px; text-align: center; font-size: 10px; font-weight: bold; position: absolute; top: 0px; left: 1px; color: white; background: url(../images/landing/Calendar/wknum_bg.png); margin-top: 1px";
				div1.appendChild(wknum);
			}
			//day.style.cssText 	= "padding: 0px; width: 65px; overflow: hidden; " + ((j==0)?"":"border-left: 1px solid #c3d9ff;");
			//div1.style.cssText	= "overflow:hidden; width: 64px; text-align: right; background-color: #e8eef7; position: relative";
			//div2.style.cssText	= "overflow: hidden; width: 64px; height: 64px; font-size: 10px; line-height: 26px; text-align: center; background: " + (( sameDate(date,today) )?"#ffffcc":"#ffffff");
			if( shipping_type == "standard" ){
				if( sameDate(date,today) ){
					image_file = "order_received";
					image_alt = "Order Placed";
				}
				else if( sameDate(date, proof_date)){
					image_file = "proof_review";
					image_alt = "Proof Review/Approval";
				}
				else if( sameDate(date, prd_date)){
					image_file = "production";
					image_alt = "Award Production";
				}
				else if( sameDate(date, shipped_date)){
					image_file = "order_shipped";
					image_alt = "Order Shipped";
				}
				else if( sameDate(date, delivered_date)){
					image_file = "order_delivered";
					image_alt = "Order Delivered";
				}
				else if( (betweenDates(date, fedex_begin_date, fedex_end_date) == true) && (date.getDay() != 0) && (date.getDay() != 6) ){
					image_file = "shipping";
					image_alt = "Shipping";
				}
				else if( date.getDay() == 0 || date.getDay() == 6){
					day.className = "day_weekend";
					continue;
				}
				else{
					continue;
				}
			}
			else if( shipping_type == "express" ){
				if( sameDate(date,today) ){
					image_file = "order_received";
					image_alt = "Order Placed";
				}
				else if( sameDate(date, proof_date)){
					image_file = "order_express";
					image_alt = "Proof Review/Approval";
				}
				else if( sameDate(date, prd_date)){
					image_file = "order_express_shipped";
					image_alt = "Production/Order Shipped";
				}
				else if( sameDate(date, shipped_date)){
					image_file = "order_delivered";
					image_alt = "Order Delivered";
				}
				else if( date.getDay() == 0 || date.getDay() == 6){
					day.className = "day_weekend";
					continue;
				}
				else{
					continue;
				}
			}
			px = document.all?"":"px";
			img = newEle("img");
			img.src = "../images/landing/Calendar/" + image_file + ".jpg";
			img.style.cssText = "width: 40px; height: 40px; margin-top: 12px;";
			img.alt = img.title = image_alt;
			div2.appendChild(img);
		}
	}
	
	element.innerHTML = "";
	
	element.appendChild(div_Tabs);
	element.appendChild(div_Table);
	draw_table_only = true;
}
/* Function drawCalendar2 End */


function chgCalendar2(ele,type){
	if( type != 'standard' && type != 'express' )	return false;
	drawCalendar2(ele, type);
}


/* Function drawCalendar Start: Draw Calendar on specific element */
function drawCalendar(ele, shipping_type, no_reference){
	if( shipping_type != 'standard' && shipping_type != 'express' )	return false;
	element = $(ele);
	div_left 	= newEle("div");
	div_B 	= newEle("div");
	table 	= newEle("table");
	tbody	= newEle("tbody");
	row1 	= newEle("tr");
	table.appendChild(tbody);
	div_B.appendChild(table);
	tbody.appendChild(row1);
	if( document.all )
		table.style.cssText = "border: 5px solid #c3d9ff; border-collapse: collapse; width: 100%;";
	else
		table.style.cssText = "border: 5px solid #c3d9ff; border-collapse: separate; width: 100%;";
	
	for(i=0;i<wkdays.length;i++){
		wkday = newEle("td");
		wkday.appendChild(newText(wkdays[i]));
		wkday.style.cssText = "background-color: #c3d9ff; text-align: center; color: blue; padding: 0px; height: 18px";
		row1.appendChild(wkday);
	}
	
	//alert(ref_date);
	today 	= new Date();
	proof_date 		= getNextNBizDayFromDate(today,1);
	prd_date 		= getNextNBizDayFromDate(today,2);
	shipped_date	= getNextNBizDayFromDate(today,3);
	fedex_begin_date		= getNextNBizDayFromDate(today,4);
	fedex_end_date			= getNextNBizDayFromDate(today,5);
	delivered_date	= getNextNBizDayFromDate(today,6);
	sunday 	= getThisSunday(today);
	if(today.getDay() < 3)	sunday.setDate(sunday.getDate()-7);

	satday 	= getDateLater(sunday, 7 * weeks -1);
	old_mth = sunday.getMonth() + 1;
		
	for(i=0;i<weeks;i++){
		row = newEle("tr");
		if(i!=0)	row.style.cssText = "border-top: 1px solid #c3d9ff;";
		tbody.appendChild(row);
		for(j=0;j<7;j++){
			day 	= newEle("td");
			div1	= newEle("div");
			div2	= newEle("div");
			row.appendChild(day);
			day.appendChild(div1);
			day.appendChild(div2);
			date 	= new Date();
			date.setTime(sunday.getTime());
			date.setDate(date.getDate()+j+i*7);
			label 	= ( date.getMonth()+1 != old_mth && date.getDate() == 1)?months[date.getMonth()]:"";
			label	= label + " " + date.getDate();
			//if( i==0 && j==0 )	label = months[date.getMonth()] + " " + date.getDate();
			div1.appendChild(newText(label));
			if( j==0 ){
				wknum = newEle("div");
				wknum.appendChild( newText( date.getWeek(0) ) );
				wknum.style.cssText = " width: 26px; text-align: center; font-size: 10px; font-weight: bold; position: absolute; top: 0px; left: 1px; color: white; background: url(../images/landing/Calendar/wknum_bg.png); margin-top: 1px";
				div1.appendChild(wknum);
			}
			day.style.cssText 	= "padding: 0px; width: 65px; overflow: hidden; " + ((j==0)?"":"border-left: 1px solid #c3d9ff;");
			div1.style.cssText	= "overflow:hidden; width: 64px; text-align: right; background-color: #e8eef7; position: relative";
			div2.style.cssText	= "overflow: hidden; width: 64px; height: 64px; font-size: 10px; line-height: 26px; text-align: center; background: " + (( sameDate(date,today) )?"#ffffcc":"#ffffff");
			if( shipping_type == "standard" ){
				if( sameDate(date,today) ){
					image_file = "order_received";
					image_alt = "Order Placed";
				}
				else if( sameDate(date, proof_date)){
					image_file = "proof_review";
					image_alt = "Proof Review/Approval";
				}
				else if( sameDate(date, prd_date)){
					image_file = "production";
					image_alt = "Award Production";
				}
				else if( sameDate(date, shipped_date)){
					image_file = "order_shipped";
					image_alt = "Order Shipped";
				}
				else if( sameDate(date, delivered_date)){
					image_file = "order_delivered";
					image_alt = "Order Delivered";
				}
				else if( (betweenDates(date, fedex_begin_date, fedex_end_date) == true) && (date.getDay() != 0) && (date.getDay() != 6) ){
					image_file = "shipping";
					image_alt = "Shipping";
				}
				else if( date.getDay() == 0 || date.getDay() == 6){
					div2.style.backgroundColor = "#aaaaaa";
					continue;
				}
				else{
					continue;
				}
			}
			else if( shipping_type == "express" ){
				if( sameDate(date,today) ){
					image_file = "order_received";
					image_alt = "Order Placed";
				}
				else if( sameDate(date, proof_date)){
					image_file = "order_express";
					image_alt = "Proof Review/Approval";
				}
				else if( sameDate(date, prd_date)){
					image_file = "order_express_shipped";
					image_alt = "Production/Order Shipped";
				}
				else if( sameDate(date, shipped_date)){
					image_file = "order_delivered";
					image_alt = "	Order Delivered";
				}
				else if( date.getDay() == 0 || date.getDay() == 6){
					div2.style.backgroundColor = "#aaaaaa";
					continue;
				}
				else{
					continue;
				}
			}
			px = document.all?"":"px";
			img = newEle("img");
			img.src = "../images/landing/Calendar/" + image_file + ".jpg";
			img.style.cssText = "width: 40px; height: 40px; margin-top: 12px;";
			img.alt = img.title = image_alt;
			div2.appendChild(img);
		}
	}
	div_A 		= newEle("div");
	div_std 	= newEle("div");
	div_exp 	= newEle("div");
	a_std		= newEle("a");
	a_exp		= newEle("a");
	a_std.appendChild( newText("Standard") );
	a_exp.appendChild( newText("Express") );
	a_std.href = "javascript: chgCalendar('" + ele + "','standard')";
	a_exp.href = "javascript: chgCalendar('" + ele + "','express')";
	a_std.onclick = "return false;";
	div_std.appendChild( a_std );
	div_exp.appendChild( a_exp );
	div_std.id = 'std_calendar_tab';
	div_exp.id = 'exp_calendar_tab';
	div_A.style.cssText = "width: 100%; height: 31px;";
	div_std.style.cssText = "width: 100px; height: 30px; background-color: #c3d9ff; font-weight: bold; float: left; text-align: center; line-height: 30px; border: 1px solid #c3d9ff; border-bottom: 0px;";
	div_exp.style.cssText = "width: 100px; height: 30px; background-color: #ffffcc; font-weight: bold; float: left; text-align: center; line-height: 30px; border: 1px solid #c3d9ff; border-bottom: 0px; ";
	
	div_A.appendChild( div_std );
	div_A.appendChild( div_exp );
	
	element.innerHTML = "";
	
	div_left.appendChild(div_A);
	div_left.appendChild(div_B);
	
	draw_table_only = no_reference;
	if(!draw_table_only) div_left.style.cssText = "float: left; width: 475px;";
	else div_left.style.cssText = "float: left; width: 475px;";
	
	element.appendChild(div_left);
	if(!draw_table_only) drawReference(ele, shipping_type);
}
/* Function drawCalendar End */


function drawReference(ele, type){
	if( type != 'standard' && type != 'express' )	return false;
	std_ref = new Array( {text: "Order Placed", image: "order_received_ref.jpg"}, {text: "Proof Review/Approval", image: "proof_review.jpg"}, {text: "Award Production", image: "production.jpg"}, {text: "Order Shipped", image: "order_shipped.jpg"}, {text: "Shipping", image: "shipping.jpg"}, {text: "Order Delivered", image: "order_delivered.jpg"});
	exp_ref = new Array( {text: "Order Placed", image: "order_received_ref.jpg"}, {text: "Proof Review/Approval", image: "order_express.jpg"}, {text: "Production/Order Shipped", image: "order_express_shipped.jpg"}, {text: "Order Delivered", image: "order_delivered.jpg"});
	ref_per_row = 1;
	width = 650;
	
	element = $(ele);
	div_C = newEle("div");
	table = newEle("table");
	tbody = newEle("tbody");
	if( type == 'standard' )	refs = std_ref;
	else						refs = exp_ref;
	
	var row;
	for(i=0;i<refs.length;i++){
		if(i % ref_per_row == 0){
			row = newEle("tr");
			tbody.appendChild(row);
		}
		td1 = newEle("td");
		td2 = newEle("td");
		img = newEle("img");
		img.src = "../images/landing/Calendar/" + refs[i].image;
		px = (document.all?"":"px");
		img.style.cssText = "width: 40px; height: 40px; margin-top: 5px";
		td1.style.cssText = "text-align: left; height: 30px; width: 50px;"
		td2.style.cssText = "text-align: left; width: 165px; line-height: 34px;"
		td1.appendChild(img);
		td2.appendChild( newText(refs[i].text) );
		row.appendChild(td1);
		row.appendChild(td2);
	}
	left = - refs.length % ref_per_row;
	for(i=0;i>left*2;i--){
		row.appendChild( newEle("td") );
	}
	
	div_C.style.cssText = "margin-top: 25px; float: right;"
	table.appendChild(tbody);
	div_C.appendChild(table);
	element.appendChild(div_C);
}


function chgCalendar(ele,type){
	if( type != 'standard' && type != 'express' )	return false;
	drawCalendar(ele, type, draw_table_only);
	
	if( type == 'standard' ){
		$('std_calendar_tab').style.backgroundColor = "#c3d9ff";
		$('exp_calendar_tab').style.backgroundColor = "#ffffcc";
	}
	else if(type == 'express'){
		$('std_calendar_tab').style.backgroundColor = "#ffffcc";
		$('exp_calendar_tab').style.backgroundColor = "#c3d9ff";
	}
	
}


/* Function getThisSunday Start: Get the first day of this week */
function getThisSunday(tday){
	sun = new Date();
	sun.setTime(tday.getTime());
	sun.setDate(sun.getDate() - sun.getDay());
	return sun;
}

/* Function getthisSunday End */

/* Function getDateLater Start: Get the date <period> days after <day> */
function getDateLater(day, period){
	sat = new Date();
	sat.setTime(day.getTime());
	sat.setDate(sat.getDate() + period);
	return sat;
}
/* Function getDateLater End */

/* Function checkHoliday Start: Check whether <date> is a holiday */
function checkHoliday(date){

}
/* Function checkHoliday End */

/* Function getBgColor Start: Get the cell BG color according to <type> */
function getBgColor(type){

}
/* Function getBgColor End */

/* Function getStatusImage Start: Get the cell Status Image according to <type> */
function getStatusImage(type){

}
/* Function getStatusImage End */ 


function newEle(type){
	return document.createElement(type);
}

function newText(text){
	return document.createTextNode(text);
}

function sameDate(date1, date2){
	if( date1.toDateString() == date2.toDateString() ){
		return true;
	}
	else{
		return false;
	}
}

function betweenDates(dateX, dateFrom, dateTo){
	if( (dateX.getTime() >= dateFrom.getTime()) && (dateX.getTime() <= dateTo.getTime()) ){
		return true;
	}
	else{
		return false;
	}	
}

function getNextNBizDayFromDate(today, nDay) {
	var now = new Date();
	now.setTime(today.getTime());

	if (nDay <= 0) 
		return now;
	else {
		while (nDay > 0) {
			now.setDate(now.getDate()+1);
			var day = now.getDay();

			if (day != 6 && day != 0 && !check_holiday_part(now))
				nDay--;
		}
		return now;
	}
}

// US Holiday, only part of holidays
function check_holiday_part (dt_date) {
	// check simple dates (month/date - no leading zeroes)
	var n_date = dt_date.getDate(),
		n_month = dt_date.getMonth() + 1;
	var s_date1 = n_month + '/' + n_date;
		
	if (   s_date1 == '1/1'   // New Year's Day
		|| s_date1 == '7/4'   // Independence Day
		//|| s_date1 == '11/26' // Thanks Giving Day
		|| s_date1 == '9/6'
		|| s_date1 == '12/25' // Christmas Day
		|| ( s_date1 == '12/26' && dt_date.getFullYear() == 2008 )
	) return true;
	
	// weekday from beginning of the month (month/num/day)
	var n_wday = dt_date.getDay(),
		n_wnum = Math.floor((n_date - 1) / 7) + 1;
	var s_date2 = n_month + '/' + n_wnum + '/' + n_wday;
	if( s_date2 == '11/4/4' )  // ThanksGiving Day, 4th Thursday in Nov. 
		return true;

	var dt_temp = new Date (dt_date);
	dt_temp.setDate(1);
	dt_temp.setMonth(dt_temp.getMonth() + 1);
	dt_temp.setDate(dt_temp.getDate() - 1);
	n_wnum = Math.floor((dt_temp.getDate() - n_date - 1) / 7) + 1;
	var s_date3 = n_month + '/' + n_wnum + '/' + n_wday;
	
	if (   s_date3 == '5/1/1' ) // Memorial Day, last Monday in May 
		return true;
	
	return false;
}

