/*----------------------------------------------------
functions.js

Functions used in the operation of woodlandsartsfestival.com
Written by Chuck Campbell, Websoft Publishing Company.
10/18/2010
----------------------------------------------------*/

// ************************************************************************************************************************
// GLOBAL FUNCTIONS *******************************************************************************************************

function displayMailLink(AccountName,Domain,Subject,LinkText) {
	document.write("<a href=" + "mail" + "to:" + AccountName + "@" + Domain + "?subject=" + Subject + ">" + LinkText + "</a>") ;
}

function openWindow(w,h,x,y,url) {
	var openString = "scrollbars=yes,width=" + w + ",height=" + h + ",top=" + y + ",left=" + x;
	var programs = window.open("","programs",openString);
	programs.location.href = url;
		if (programs.opener == null) programs.opener = window;
	programs.opener.name = "opener";
}

function displayData(html) {
	var section = document.getElementById(html);
	if (section.style.display == "none") {
		section.style.display = "block";
	}
	else {
		section.style.display = "none";
	}
}

function showContent(showThis,hideThis)	{
	document.getElementById(hideThis).style.display = "none";
	document.getElementById(showThis).style.display = "block";
}

function setStyle(id,param,value) {
	var el = document.getElementById(id);
	eval("el.style." + param + " = '" + value + "'");

}

function setHTML(id,str) {
	document.getElementById(id).innerHTML = str;

}

function printIt() {
	print();
}

function displayFlash(URL,codebase,width,height) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n');
	if (codebase == 'true') {
		document.write('codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"\n');
	}
	document.write('width="' + width + '" height="' + height + '" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="' + URL + '" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="bgcolor" value="#ffffff" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	if (codebase == 'true') {
		document.write('<embed src="' + URL + '" quality="high" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	}
	else {
		document.write('<embed src="' + URL + '" quality="high" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" />\n');
	}
	document.write('</object>\n');
}

function isDate(mm,dd,yyyy) {
   var d = new Date(mm + "/" + dd + "/" + yyyy);
   return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function FormatDateTime(datetime, FormatType)
/*
	 FormatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
*/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}

	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";

	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 2; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 3; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 4; }
	if (Month == "May") { Month = "May"; MonthNumber = 5; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 6; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 7; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 8; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 9; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 10; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 11; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 12; }

	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (MonthDay.charAt(1) == " ") {
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}

	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));

	var yearArray = strDate.split(" ");
	var x;
	for (var i=0;i<yearArray.length;i++) {
		x = yearArray[i];
		if (x.length == 4) {
			var Year = x;
			break;
		}
	}
	//var Year = new String(strDate.substring(strDate.length - 4, strDate.length));		THIS DOESNT WORK IN FIREFOX

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}

// END OF GLOBAL FUNCTIONS ************************************************************************************************
// ************************************************************************************************************************

// NAVIGATION FUNCTIONS ***************************************************************************************************
// ************************************************************************************************************************
function hideMenu(cold) {
	if (document.getElementById(cold)) {
		document.getElementById(cold).style.visibility = "hidden";
		navlinks.currentLink = "";
	}
	var linkhref = eval(document.getElementById(cold + "Link"));
	if (linkhref) {
		if ((cold == "artists") || (cold == "visitors") || (cold == "sponsors")) {
			linkhref.style.backgroundPosition = "0px -30px";
		}
		else {
			linkhref.style.backgroundImage = "";
		}
	}
}

function expandMenu(hot) {
	// HIDE ALL MENUS
	for (var i=0;i<=linkArray.length;i++) {
		hideMenu(linkArray[i]);
	}

	// SET CURRENTLY SELECTED LINK TO NULL
	eval("navlinks.currentLink = ''");
	if ((hot != "") && (hot != undefined)) {
		eval("navlinks." + hot + " = true");
		var linkhref = eval(document.getElementById(hot + "Link"));
		if (linkhref) {
			if ((hot == "artists") || (hot == "visitors") || (hot == "sponsors")) {
				linkhref.style.backgroundPosition = "0px 0px";			
			}
			else {
				linkhref.style.backgroundRepeat = "no-repeat";
				linkhref.style.backgroundImage = "url(/images/background.nav.png)";
				linkhref.style.backgroundPosition = "10px 1px";
			}
			if (document.getElementById(hot)) {
				document.getElementById(hot).style.visibility = "visible";
			}
			eval("navlinks.currentLink = '" + hot + "'");
		}
	}
}

function visitSponsor(url) {
	window.open(url,'sponsorWindow','');
}
// END OF NAVIGATION FUNCTIONS ********************************************************************************************
// ************************************************************************************************************************

