function placeImage(choice) {
var mChoice = $(choice).parentNode.parentNode.parentNode.parentNode;
var month = $(mChoice).id;
var newSource = $(choice).src;
var image = newSource.substring(newSource.lastIndexOf('/')+1,newSource.length);
var design = image.substring(0,image.lastIndexOf('.'));
$(mChoice.id+'_t').setAttribute("src",choice.src);
$(month.replace("_","")).setAttribute("value",design);
return hs.close(choice);
}

function checkData(calendar)
{
	errorCount = 0;
	errorText = '';
	
	for (i=0; i < MonthsOnPage.length; i++) 
	{
		if (document.getElementById(MonthsOnPage[i]).value === '') {
			errorCount++;
			errorText = errorText + "You did not choose a design for "+MonthsOnPage[i]+"!\n";
		}
	}
	
	errorText = errorText + "------------------------------------------------------\n";
		errorText = errorText + "Please correct these issues to continue \n";
	
	if (errorCount > 0) {
		alert(errorText);
	} else {
	$('ysForm').submit();
/*
	var mC = "";
	var response = '';
	var x = 1;
	if (! $('month_options').childNodes[x].id){x = 0;} //address differences between IE and other children
	while (x<$('month_options').childNodes.length){
		var values = $('month_options');
		mC= mC+values.childNodes[x].value+';';
		x = x+2;
		}
	if ( ! readCookie(calendar)){
	new Ajax.Request('/calendar/setCInfo.php',{method:'post',onFailure: function(){$('ysForm').submit();},onComplete: function(xhrResponse){
		response = xhrResponse.responseText;createCookie(calendar,response,1);
		new Ajax.Request('/calendar/postChoices.php',{method:'post',onComplete: function(){
			$('ysForm').submit();
		},parameters: {mC:mC, response:response}});
	}});
	} else {
	response = readCookie(calendar);
	new Ajax.Request('/calendar/postChoices.php',{method:'post',onFailure: function(){$('ysForm').submit();},onComplete: function(xhrResponse){
			$('ysForm').submit();	
		},parameters: {mC:mC, response:response}});
	}*/
	}

}

function setChoices(calendar){
	if (readCookie(calendar)){
		var response = '';
		response = readCookie(calendar);
		new Ajax.Request('/calendar/loadChoices.php',{method:'post',onComplete: 
			function(xhrResponse){
				var returnData = xhrResponse.responseText; 
				var returnMC = returnData;
				var returnedMonths = returnMC.split(";");
				var x=0;
				while (x<returnedMonths.length){
					var presentValue = returnedMonths[x];
					var monthPlace = presentValue.slice(presentValue.indexOf("-")+1,presentValue.length);
					var monthC = presentValue.slice(0,presentValue.indexOf("-"));
					cImages[monthPlace] = monthC;
					x++;
					}
				iPosted = true;
				if (! iPlaced){placeChoices()};
			}, parameters:{response:response}});
	}

}

function clearAll(){
	var x = 1;
	if (! $('month_options').childNodes[x].id){x = 0;} //address differences between IE and other children
	var y = 0;
	while (x<$('month_options').childNodes.length){
		$('month_options').childNodes[x].removeAttribute("value");
		$('month_options').childNodes[x].setAttribute("value","");

		var imageUpdate = $('month_options').childNodes[x].id;
		imageUpdate = imageUpdate.replace(/20/,"_20")+"_image";
			$(imageUpdate).removeAttribute("src");
			$(imageUpdate).setAttribute("src","/calendar/t/select.jpg");
		x = x+2;
		y++;
		}
	
}

function placeChoices(){
	var x = 1;
	if (! $('month_options').childNodes[x].id){x = 0;} //address differences between IE and other children
	var y = 0;
	while (x<$('month_options').childNodes.length){
		$('month_options').childNodes[x].removeAttribute("value");
		$('month_options').childNodes[x].setAttribute("value",cImages[y]);

		var imageUpdate = $('month_options').childNodes[x].id;
		imageUpdate = imageUpdate.replace(/20/,"_20")+"_image";
		if ((cImages[y]!="") && (cImages[y]!="undefined")){	
			$(imageUpdate).removeAttribute("src");
			$(imageUpdate).setAttribute("src","/calendar/t/"+cImages[y].toLowerCase()+".jpg");
		}
		x = x+2;
		y++;
		}
	x = 0;

		iPlaced = true;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setStartMonth(startMonth){
	startm=startMonth.replace(" ","");
	$('calLoader').style.visibility='visible';
	if ($('calLoader').href != ''){$('calLoader').setAttribute("href","http://site.glennz.com/calendar/DT"+startm);}
}

