var imageDir = "../images/"
var noImageFilePrefix = "choose"
var noImageFileExtension = ".jpg"
var defaultImage = imageDir + "choose.png";
var imageFileExtension = ".png";
var imageThumbFileAbbrev = "_thumb";

var imageValues = new Array("20060824","20060826","20060829","20060905","20060907","20060909","20060914","20060916","20060919","20060921","20060923","20060926","20060930","20061003","20061005","20061010","20061012","20061014","20061019","20061021","20061026","20061028","20061105","20061107","20061109","20061111","20061114","20061116","20061118","20061128","20061205","20061207","20061209","20061214","20061216","20061221","20061223","20061226","20061228","20070102","20070104","20070109","20070111","20070116","20070118","20070120","20070123","20070125","20070127","20070130","20070201","20070203","20070213","20070215","20070217","20070220","20070222","20070224","20070308","20070310","20070315","20070317","20070322","20070329","20070331","20070403","20070405","20070407","20070410","20070414","20070417","20070419","20070424","20070426","20070428");
var imageTitles = new Array("Zombie","Scotland","PAX","Caffeine","Caffeine Continued","Return of Caffeine","Disgusting, In C Minor","Dan is Cheap","America Hates Burnie","America Still Hates Burnie","America Hates Burnie Most","Try This At Home","Truce","Pie Vs Cake","Feed Me","Fight the Power","Trust","Trust, Continued","Hunger Pangs","Woman Scorned","Beyond The Veil","World Series","Come Here Often","Intervention","Intervention, pt 2","Intervention, pt 3","The Most Divisive Issue...","Viva Pinata","Blood Money","New Tv","Back in the Saddle","Infectious Disease","A Thriving Competition","Bah Humbug 2","Bah Humbug 3","Candy Coated","Secret Santa","Man's Best Friend","The News","Resolution","Sportsmanship","Outsourced","I'm Also A Member","Custody Battle","Heartstrings","The Root of the Problem","Sick Day","New School","Gayest Office Ever","Macho Man","Those Things Are Permanent","Can I Speak To Your...","Matt the Mooch","Matt the Mooch 2","Matt the Mooch 3","Brave New World","Brave New World 2","Brave New World 3","I Just Saved A Bunch Of...","Geoff Is Horribly...","Extended Family","Extended Family 2","Aim Low","Killer Strategy, The Next Step","Killer Strategy: Payback Time","Say Cheese","Centennial","On Strike","Tonight We Dine In Hell","A Cry For Help","Vote For The Worst","Chicks Dig It","For A Good Cause","Celebrity Pass","Superpower");
var monthOptions = new Array("January2009","February2009","March2009","April2009","May2009","June2009","July2009","August2009","September2009","October2009","November2009","December2009");

var shortDates = new Array("20070923","20070930","20071223","20071224","20071230","20071231","20080323","20080324","20080330","20080331");
	
var imageValuesHash = new Hashtable();
var imageFilesHash = new Hashtable();
var imageThumbFilesHash = new Hashtable();
var imageTitlesHash = new Hashtable();

var optionList = '';

var datecount=0;
var dateholder;
var datevalues = new Array();
var datefields = new Array();


for (i=0;i<imageValues.length;i++)
{
	optionList += "<option value='" + imageValues[i] +"'>"+ imageTitles[i] +"</option>";
	
	imageValuesHash.put( imageValues[i], imageValues[i] );
	imageFilesHash.put( imageValues[i], imageValues[i] + imageFileExtension );
	imageThumbFilesHash.put( imageValues[i], imageValues[i] + imageThumbFileAbbrev + imageFileExtension );
	imageTitlesHash.put ( imageValues[i], imageTitles[i] );
	
}


Array.prototype.inArray = function (value) 
{
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};


function assignDesignToMonth(month, design)
{
	document.getElementById(month).value = design;
	selection = design;
	
	if (selection === '') {
		imageThumbFilePath = imageDir + "choose" + (Math.round(11*Math.random()) + 1) + ".jpg";
	} else {
		imageThumbFilePath = imageDir + imageThumbFilesHash.get( selection );
	}

	if (document.images)
	{
		var imageName = month + "Image";
		document.getElementById(imageName).src = imageThumbFilePath;
	}
}


function setMonthImage( month )
{
	selection = document.getElementById(month).value;

	if (selection === '') {
		imageThumbFilePath = imageDir + "choose" + (Math.round(11*Math.random()) + 1) + ".jpg";
	} else {
		imageThumbFilePath = imageDir + imageThumbFilesHash.get( selection );
		imageFilePath = imageDir + imageFilesHash.get( selection );
		imageTitle = imageTitlesHash.get( selection );
	}

	if (document.images)
	{
		var imageName = month + "Image";
		var imageLinkName = month + "ImageLink";
		document.getElementById(imageName).src = imageThumbFilePath;
		document.getElementById(imageName).title = imageTitle;
	}
}

function viewImage( month )
{
	selection = document.getElementById(month).value;
	
	if (selection !== '') {
		imageFilePath = imageDir + imageFilesHash.get( selection );
	}

	MyWindow=window.open(imageFilePath,'FullImage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=560,height=560');
	return false;
}

function checkData()
{
	errorCount = 0;
	errorText = '';
	
	for (i=0; i < monthOptions.length; i++) 
	{
		
		if (document.getElementById(monthOptions[i]).value === '') {
			errorCount++;
			errorText = errorText + "You did not choose a design for "+monthOptions[i]+"!\n";
		}
	}
	
	if (document.getElementById('CreatedBy').value === '') {
		errorCount++;
		errorText = errorText + "You did not enter your name at Step 3!\n";
	}
	
	errorText = errorText + "------------------------------------------------------\n";
		errorText = errorText + "Please correct these issues to continue, \n";
		errorText = errorText + "or call us at 512-684-5980\n";
	
	if (errorCount > 0) {
		alert(errorText);
		return false;
	}
}

function addDate()
{

	for (i=0;i<datefields.length;i++)
	{
		datevalues[i] = document.getElementById(datefields[i]).value;
	}
	var newdateid = document.getElementById("date").value.replace(/-/g,"");

	if ( datefields.length > 0 )
	{
		for (i=0;i<datefields.length;i++)
		{
			if (newdateid == datefields[i])
			{
				alert("This date has already been selected");
				return;
			}
		}
	}

	dateid=document.getElementById("date").value;

	datefield= dateid.replace(/-/g,"");
	chosenDate = datefield;
	
	defaultMaxLength = 130;
	shortMaxLength = 40;
	
	inscriptionMaxLength = defaultMaxLength;
	

	if (shortDates.inArray(chosenDate)) 
	{
		inscriptionMaxLength = shortMaxLength;		
	}
		

	inscription = getInscription(datefield);

	if (inscription == "invalid")
	{
		alert("This is not a valid date. Please try entering your date again. Make sure you enter the date in the following format: yyyy-mm-dd");
		return;
	}

	if (document.getElementById("datetext").innerHTML == "You currently have no dates personalized. Click a date to the left to add a personalized date.")
	{
		document.getElementById("datetext").innerHTML="<span id=span_"+datefield+"><b></b> "+dateid+" Text: <input type=text id="+datefield+" name="+inscription+" value='' maxlength="+inscriptionMaxLength+" size=50 /> [<a href=javascript:delDate('span_"+datefield+"')>Remove</a>]<br><br></span>";
	}
	else
	{
		document.getElementById("datetext").innerHTML+="<span id=span_"+datefield+"><b></b> "+dateid+" Text: <input type=text id="+datefield+" name="+inscription+" value='' maxlength="+inscriptionMaxLength+" size=50 /> [<a href=javascript:delDate('span_"+datefield+"')>Remove</a>]<br><br></span>";
	}
	for (i=0;i<datefields.length;i++)
	{
		rksField = datefields[i];
		rksValue = datevalues[i];

		document.getElementById(datefields[i]).value=datevalues[i];
	}
	document.getElementById("date").value="";

	datevalues.push(document.getElementById(datefield).value);
	datefields.push(datefield);

}

function getValue(){
alert(document.getElementById("vw-inscription-3230303730373037").value);
}

function delDate(delid)
{
	theHtml = document.getElementById(delid).innerHTML;

	document.getElementById(delid).innerHTML="";

	theHtml = document.getElementById(delid).innerHTML;

	deldate = delid.substring(5, delid.length);

	for ( i=0; i<datefields.length; i++ )
	{
		if ( datefields[i] == deldate )
		{
			datefields.splice(i,1);
			datevalues.splice(i,1);

			debug = datevalues.length;

			break;
		}
	}

}