﻿/**\
 **		/scripts/main.js
\**/
var debug = true;
//disable debugging features for IE.
if(navigator.appName.indexOf('icrosoft') > 0) { debug = false; }
if(typeof(console) == 'undefined') { debug = false; }

//DOM adjustments

//CSS3 Selector Classification
//Note: Prototype Driven
function cssSelectors() {
	var firstLIs =	$$('ul > li:first-child, ol > li:first-child');
	var lastLIs = $$('ul > li:last-child, ol > li:last-child');
	
	firstLIs.each(function(liFirst) {
		liFirst.addClassName('first');
	});
		
	lastLIs.each(function(liLast) {
		liLast.addClassName('last');
	});
	
	var secondChildren = $$('ul li:first-child + li');
	secondChildren.each(function(secondChild){
		secondChild.addClassName('second');
	});
	
	var firstLABELs =	$$('fieldset legend + label');
	firstLABELs.each(function(labelFirst) {
		labelFirst.addClassName('first');
	});
	
	var secondLABELs = $$('fieldset legend + label + label');
	secondLABELs.each(function(secondLABEL){
		secondLABEL.addClassName('second');
	});
	
	var secondHighlights = $$('div.highlight:first-child + div.highlight, div.contentGroup + div.contentGroup');
	secondHighlights.each(function(secondHighlight){
		secondHighlight.addClassName('second');
	});
	
	var columnSiblings = $$('#contentMain div.column + div.column');
	
	columnSiblings.each(function(columnSibling){
		columnSibling.addClassName('sibling');
	});
}

//List Item Height Adjuster
//Makes heights of even and odd list items
//relative to one another
//Note: Prototype Driven
function listItemHeights(listToSize){
	var listItems = $$(listToSize + ' li:nth-child(2n)');
	
	listItems.each(function(listItem){
		previousListItem = listItem.previous('li');
		heightToSet = $R(listItem.getHeight(), previousListItem.getHeight()).max();
		previousListItem.setStyle({
			height: heightToSet + 'px'
		});
		listItem.setStyle({
			height: heightToSet + 'px'
		});
	});
}

//cookie monster
//write cookie
function setCookie(name,value,days) { 
	if (days) { 
		var date = new Date(); 
		date.setTime(date.getTime()+(days*24*60*60*1000)); 
		var expires = ";expires="+date.toGMTString(); 
	} else { 
		expires = ""; 
	} 
	document.cookie = name+"="+value+expires+";"; 
}

// Read the cookie 
function readCookie(name) { 
	var needle = name + "="; 
	var cookieArray = document.cookie.split(';'); 
	for(var i=0;i < cookieArray.length;i++) { 
		var pair = cookieArray[i]; 
		while (pair.charAt(0)==' ') { 
			pair = pair.substring(1, pair.length); 
		} 
		if (pair.indexOf(needle) == 0) { 
			return pair.substring(needle.length, pair.length); 
		} 
	} 
	return null; 
}

//Replacement for Window Onload - Loads before images, cross-browser
document.observe("dom:loaded", function(event) {
	debug = false;
	//init functions here
	if(debug) {
		console.clear();
		console.log('page dom:loaded');
	}
	cssSelectors();
	//ie corrections
	if(navigator.appName.indexOf('icrosoft') > 0) { 
		$$("td input, td textarea").each(
			function(elem) {
				elem.setStyle("width:99%; height:99%;");
				elem.up().setStyle("background-color:" + elem.getStyle("background-color") + ";");
			}
		);
	}
	populateLocation_dds();
});

