/* 
/////////////////////////////////////////////////////////////////////////////////////
/// CODE FOR DATE AND TIME
/////////////////////////////////////////////////////////////////////////////////////
*/
d = new Date();
day = d.getDate();
month = d.getMonth()+1;
year = d.getFullYear();
full = month + "." + day + "." + year;

/*
/////////////////////////////////////////////////////////////////////////////////////
CLCP v2.1 Clear Links to Current Page
Jonathan Snook
This code is offered unto the public domain
http://www.snook.ca/jonathan/
/////////////////////////////////////////////////////////////////////////////////////
*/

function clearCurrentLink(){
    var a = document.getElementsByTagName("A");
	var aText = "";
    for(var i=0;i<a.length;i++) {
		aText += a[i].parentNode.nodeName.toLowerCase() + "\n";
        if(a[i].href == window.location.href.split("#")[0]) {
		a[i].className += " on"; //removeNode(a[i]);
		//a[i].parentNode.className = "on";
		}
		/*
		// USE THIS IF YOU HAVE A SPECIFIC PAGE OR IF THE LINK IS IN A SPECIFIC ELEMENT
		if(a[i].href.indexOf('somepage.cfm') > 0 && window.location.href.indexOf('somepage') > 0 && a[i].parentNode.nodeName.toLowerCase() == "div" && a[i].parentNode.parentNode.nodeName.toLowerCase() == "li") {
			a[i].className = "on";
		}
		*/
	}	
}

function removeNode(n){
    if(n.hasChildNodes())
        for(var i=0;i<n.childNodes.length;i++)
            n.parentNode.insertBefore(n.childNodes[i].cloneNode(true),n);
    n.parentNode.removeChild(n);
}

/*
/////////////////////////////////////////////////////////////////////////////////////
/// POP-UP WINDOW
/////////////////////////////////////////////////////////////////////////////////////
*/

function swarmCMSWin(url,w,h,s) {
	var aw = window.screen.availWidth;
	var ah = window.screen.availHeight;
	if (!w) { w = "500" }
	if (!h) { h = "500" }
	if (!s) { s = "no" }
	var awpos = (aw / 2) - (w / 2); 
	var ahpos = (ah / 2) - (h / 2);
	var features = "toolbar=no,location=no,status=no,menubar=no,resizable=no";
	features += ",width=" + w + ",left=" + awpos;
	features += ",height=" + h + ",top=" + ahpos;
	features += ",scrollbars="+s;
	winOpen = window.open(url,'swarmCMSWin',features);
}

/*
/////////////////////////////////////////////////////////////////////////////////////
/// FORM FIELD AREA
/////////////////////////////////////////////////////////////////////////////////////
*/

// Javascript that sets the on/off function for all form elements
function classIt(ele) {
	ele.className = "off";
	ele.onfocus = function(){ this.className = "on" }
	ele.onblur = function() { this.className = "off" }
}

//Javascript that limits the number of characters in the message field
function limitText(limitField,limitNum,eleID) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		if ($(eleID)) {
			$(eleID).innerHTML = limitNum - limitField.value.length;
		}
	}
}

function styleFields() {
	var inputs = document.getElementsByTagName("input");
	for (i=0;i<inputs.length;i++) {
		if ((inputs[i].getAttributeNode("rel") && inputs[i].getAttributeNode("rel").value != 'noscript') || !inputs[i].getAttributeNode("rel")) {
			if (!inputs[i].getAttributeNode("type")) {
				classIt(inputs[i]);
			} else if (inputs[i].getAttributeNode("type").value == "text" || inputs[i].getAttributeNode("type").value == "password") {
				classIt(inputs[i]);
			} else if (inputs[i].getAttributeNode("type").value == "submit" || inputs[i].getAttributeNode("type").value == "button") {
				inputs[i].className = "submit";
			}
		}
	}
	var buttons = document.getElementsByTagName("button");
	for (i=0;i<buttons.length;i++) {
		if ((buttons[i].getAttributeNode("rel") && buttons[i].getAttributeNode("rel").value != 'noscript') || !buttons[i].getAttributeNode("rel"))
			buttons[i].className = "submit";
	}
	var textareas = document.getElementsByTagName("textarea");
	for (i=0;i<textareas.length;i++) {
		if ((textareas[i].getAttributeNode("rel") && textareas[i].getAttributeNode("rel").value != 'noscript') || !textareas[i].getAttributeNode("rel"))
			classIt(textareas[i]);
		/*
		//THIS IS FOR SETTING THE LIMITS OF A FIELD TO A CERTAIN AMOUNT - CALLS limitText()
		if (textareas[i].getAttributeNode("name").value == "fieldName") {
			var charCount = 250;
			var msgElementID = "text-replace";
			textareas[i].onkeydown = function() { limitText(this.form.fieldName,charCount,msgElementID);  }
			textareas[i].onkeyup = function() { limitText(this.form.fieldName,charCount,msgElementID); }
		}
		*/
	}
	if (!window.attachEvent) {
		var selects = document.getElementsByTagName("select");
		for (i=0;i<selects.length;i++) {
			if ((selects[i].getAttributeNode("rel") && selects[i].getAttributeNode("rel").value != 'noscript') || !selects[i].getAttributeNode("rel"))
				classIt(selects[i]);
		}
	}
}


/*
/// GENERAL CONFIRM FUNCTION
*/

// From Kevin Sargent 
// url = full url to send to after confirming 
// warning = string, first warning text to display in confirmation box 
// confirmation = string, OPTONAL. if used, a second warning will display to confirm the action 
function confirmaction (url,warning,confirmation) { 
	var conf1 = confirm(warning); 
	if (conf1) { 
		if(confirmation.length != 0){ 
			var conf2 = confirm(confirmation); 
			if (conf2){ 
				window.location = url; 
			} else { 
				return false; 
			} 
		} 
	} else { 
		return false; 
	} 
}

/*
/////////////////////////////////////////////////////////////////////////////////////
/// WINDOW ONLOAD FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////
*/

addLoadEvent(styleFields);
addLoadEvent(clearCurrentLink);
