var img = new Image().src = "thumbnails/youmustchoose.gif"
var noChoiceImg = "thumbnails/youmustchoose.gif";
var imgarr = new Array("achievement.gif","adversity.gif","agony.gif","ambition.gif","apathy.gif","arrogance.gif","beauty.gif","bitterness.gif","blame.gif","burnout.gif","challenges.gif","changewinds.gif","cluelessness.gif","compromise.gif","conformity.gif","consistency.gif","consulting.gif","customercare.gif","customerdisservice.gif","daretoslack.gif","defeat.gif","delusions.gif","demotivation.gif","despair.gif","destiny.gif","discovery.gif","disloyalty.gif","disservice.gif","doitlater.gif","doubt.gif","dreams.gif","dysfunction.gif","effort.gif","elitism.gif","failure.gif","fear.gif","flattery.gif","futility.gif","gettowork.gif","giveup.gif","goals.gif","government.gif","hazards.gif","hope.gif","humiliation.gif","idiocy.gif","ignorance.gif","incompetence.gif","indifference.gif","individuality.gif","ineptitude.gif","insanity.gif","inspiration.gif","intimidation.gif","irresponsibility.gif","laziness.gif","leaders.gif","limitations.gif","loneliness.gif","losing.gif","madness.gif","mediocrity.gif","meetings.gif","misfortune.gif","mistakes.gif","motivation.gif","nepotism.gif","overconfidence.gif","persistence.gif","pessimism.gif","planning.gif","possibilities.gif","potential.gif","power.gif","pressure.gif","pretension.gif","priorities.gif","problems.gif","procrastination.gif","propaganda.gif","quality.gif","regret.gif","retirement.gif","risks.gif","sacrifice.gif","sacrificetemple.gif","sanity.gif","strife.gif","stupidity.gif","success.gif","teamwork.gif","tradition.gif","trouble.gif","underachievement.gif","vision.gif","wishes.gif","worth.gif");
var titlearr = new Array("Achievement","Adversity","Agony","Ambition","Apathy","Arrogance","Beauty","Bitterness","Blame","Burnout","Challenges","ChangeWinds","Cluelessness","Compromise","Conformity","Consistency","Consulting","CustomerCare","CustomerDisservice","DareToSlack","Defeat","Delusions","Demotivation","Despair","Destiny","Discovery","Disloyalty","Disservice","DoItLater","Doubt","Dreams","Dysfunction","Effort","Elitism","Failure","Fear","Flattery","Futility","GetToWork","GiveUp","Goals","Government","Hazards","Hope","Humiliation","Idiocy","Ignorance","Incompetence","Indifference","Individuality","Ineptitude","Insanity","Inspiration","Intimidation","Irresponsibility","Laziness","Leaders","Limitations","Loneliness","Losing","Madness","Mediocrity","Meetings","Misfortune","Mistakes","Motivation","Nepotism","Overconfidence","Persistence","Pessimism","Planning","Possibilities","Potential","Power","Pressure","Pretension","Priorities","Problems","Procrastination","Propaganda","Quality","Regret","Retirement","Risks","Sacrifice","SacrificeTemple","Sanity","Strife","Stupidity","Success","Teamwork","Tradition","Trouble","Underachievement","Vision","Wishes","Worth");
var monthOptions = new Array("MiniPoster1","MiniPoster2","MiniPoster3","MiniPoster4","July2008","August2008","September2008","October2008","November2008","December2008","January2009","February2009","March2009","April2009","May2009","June2009");
var optionList = '';
var datecount=0;
var dateholder;
var datevalues = new Array();
var datefields = new Array();
var myHash = new Hashtable();

for (i=0;i<titlearr.length;i++)
{
	optionList += "<option value='" + titlearr[i] +"'>"+ titlearr[i] +"</option>";
	myHash.put( titlearr[i], imgarr[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 === '') {
		imgsrc = noChoiceImg;
	} else {
		imgsrc = "thumbnails/" + myHash.get( selection );
	}

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


}




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";
		}
	}
	
	errorText = errorText + "------------------------------------------------------\n";
		errorText = errorText + "Please correct these issues to continue, \n";
		errorText = errorText + "or call us at 1-877-DESPAIR\n";
	
	if (errorCount > 0) {
		alert(errorText);
		return false;
	}
}

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

	if (selection === '') {
		imgsrc = noChoiceImg;
	} else {
		imgsrc = "thumbnails/" + myHash.get( selection );
	}

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

}

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;
	
	var shortDates = new Array("20061224","20061231","20070923","20070930","20071224","20071231","20080323","20080324","20080330","20080331","20080824","20080831","20081123","20081130","20090524","20090531");
		
	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+" Personalize: <input type=text id="+datefield+" name="+inscription+" value='' maxlength="+inscriptionMaxLength+" size=50 /> [<a href=javascript:delDate('span_"+datefield+"')>Delete</a>]<br><br></span>";
	}
	else
	{
		document.getElementById("datetext").innerHTML+="<span id=span_"+datefield+"><b></b> "+dateid+" Personalize: <input type=text id="+datefield+" name="+inscription+" value='' maxlength="+inscriptionMaxLength+" size=50 /> [<a href=javascript:delDate('span_"+datefield+"')>Delete</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;
		}
	}

}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}