function ToggleMenu(aElem) {
	
	ULs = aElem.parentNode.getElementsByTagName("UL");
	
	if(ULs[0].className == "collapsed") ULs[0].className = "expanded";
	else ULs[0].className = "collapsed";
	
}



function focusField(elem) {
	
	if(elem.className.indexOf('blurred') > -1) {
		elem.className = elem.className.replace('blurred','focused');
	} else elem.className += ' focused';
	
}

function blurField(elem) {
	
	if(elem.className.indexOf('focused') > -1) {
		elem.className = elem.className.replace('focused','blurred');
	} else elem.className += ' blurred';
	
}


function validateEmail(elem) {

	if(CheckEmail(elem.value)) elem.parentNode.firstChild.className = "ok";
	else elem.parentNode.firstChild.className = "reqd";

}

function checkLength(elem) {
	
	if(elem.value.length > 0) elem.parentNode.firstChild.className = "ok";
	else elem.parentNode.firstChild.className = "reqd";
	
}


function validate(formElem) {

	labels = formElem.getElementsByTagName("LABEL");
	flag = false;
	
	for(i=0;i<labels.length;i++) {
		if(labels[i].className=="reqd") flag = true;
	}
	
	if(flag) {
		window.alert("Please complete all required fields.");
		return false;
	} else {
		return true;
	}
}


function CheckEmail(str) {
	
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1){ return false; }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
	if (str.indexOf(at,(lat+1))!=-1){ return false; }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
	if (str.indexOf(dot,(lat+2))==-1){ return false; }	
	if (str.indexOf(" ")!=-1){ return false; }

	return true;			
}


function previewWindow(url) {
	window.open(url,'photoviewer','left=100,top=100,width=600,height=440,toolbar=0,location=0,status=0,menubar=0,resizeable=1');
}


function processClientSelect(selectElem) {

	// New Client
	if(selectElem.value==0) {
		newClientName = document.createElement("INPUT");
		newClientName.className="textbox";
		newClientName.name="clientname";
		newClientName.id="newClientName";
		newClientName.type="text";
		newClientName.value = "Client Name";
		newClientName.onfocus = function() {
			if(this.value=='Client Name') { this.value=''; }
		}
		newClientName.onblur = function() {
			if(this.value=='' || !this.value) { this.value='Client Name';  }
		}
		
		newClientShortName = document.createElement("INPUT");
		newClientShortName.className="textbox";
		newClientShortName.name="clientshortname";
		newClientShortName.id="newClientShortName";
		newClientShortName.type="text";
		newClientShortName.value = "clientuniquename";
		newClientShortName.onfocus = function() {
			if(this.value=='clientuniquename') { this.value=''; }
		}
		newClientShortName.onblur = function() {
			if(this.value=='' || !this.value) { this.value='clientuniquename';  }
		}		
		
		newClientUrl = document.createElement("INPUT");
		newClientUrl.className="textbox";
		newClientUrl.name="clienturl";
		newClientUrl.id="newClientUrl";
		newClientUrl.type="text";
		newClientUrl.value = "Client URL";
		newClientUrl.onfocus = function() {
			if(this.value=='Client URL') { this.value=''; }
		}
		
		newClientIconLabel = document.createElement("LABEL");
		newClientIconLabel.id="newClientIconLabel";
		newClientIconLabel.setAttribute("for","icon");
		newClientIconLabel.innerHTML = "Client Icon";
		
		
		newClientIcon = document.createElement("INPUT");
		newClientIcon.className="textbox";
		newClientIcon.name="icon";
		newClientIcon.id="newClientIcon";
		newClientIcon.type="file";
		

		selectElem.name="old_clientid";
		
		selectElem.parentNode.appendChild(newClientName);
		selectElem.parentNode.appendChild(newClientShortName);
		selectElem.parentNode.appendChild(newClientUrl);
		selectElem.parentNode.appendChild(newClientIconLabel);
		selectElem.parentNode.appendChild(newClientIcon);
		
		
	
	} else {
	
		if(document.getElementById('newClientName')) {
		
			newClientName = document.getElementById('newClientName');
			newClientShortName = document.getElementById('newClientShortName');
			newClientUrl = document.getElementById('newClientUrl');
			newClientIconLabel = document.getElementById('newClientIconLabel');
			newClientIcon = document.getElementById('newClientIcon');
			
			selectElem.parentNode.removeChild(newClientName);
			selectElem.parentNode.removeChild(newClientShortName);
			selectElem.parentNode.removeChild(newClientUrl);
			selectElem.parentNode.removeChild(newClientIconLabel);
			selectElem.parentNode.removeChild(newClientIcon);
			
			selectElem.name="clientid";
		
		}
	
	}

}









function processGCatSelect(selectElem) {

	// New Client
	if(selectElem.value==0) {
		newCategory = document.createElement("INPUT");
		newCategory.className="textbox";
		newCategory.name="category";
		newCategory.id="newCategory";
		newCategory.type="text";
		newCategory.value = "New Category";
		newCategory.onfocus = function() {
			if(this.value=='New Category') { this.value=''; }
		}
		newCategory.onblur = function() {
			if(this.value=='' || !this.value) { this.value='New Category';  }
		}
		
		selectElem.name="old_category";
		
		selectElem.parentNode.appendChild(newCategory);
	
	} else {
	
		if(document.getElementById('newCategory')) {
		
			newCategory = document.getElementById('newCategory');
			selectElem.parentNode.removeChild(newCategory);
			
			selectElem.name="category";
		
		}
	
	}

}


startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		
		if(!navRoot) return true;
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			if(navRoot.childNodes[i].nodeName=="UL") {
				navRootUl = navRoot.childNodes[i];
				break;
			}
		}
		
		for (i=0; i<navRootUl.childNodes.length; i++) {
			node = navRootUl.childNodes[i];
			
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className +=" over";
				}
			
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
};






var splashbox;
window.onload = function() {

	// run ie hack
	startList();


	if(document.getElementById('photocontainer')) {
		var container = document.getElementById('photocontainer');
		var scroller = document.getElementById('photo');
		var imagewrapper = container.getElementsByTagName("UL");
		var rawphotoimages = container.getElementsByTagName("LI");
		var photoimages = Array();
		var totalImages;
		var containerWidth = container.offsetWidth;
		
		for(var i=0;i<rawphotoimages.length;i++) {
			if(rawphotoimages[i].className=="page") {
				photoimages.push(rawphotoimages[i]);
			}
		}
		
		totalImages = photoimages.length;
		
		if(totalImages > 1) {
		
			controls = document.createElement("DIV");
			controls.id = "photocontrols";
			
			control_status = document.createElement("P");
			control_status.id = "photostatus";
			control_status.innerHTML = "Photo 1 of " + (totalImages);
			
			control_buttons = document.createElement("P");
			control_buttons.id = "photonextprev";
			
			control_prev = document.createElement("A");
			control_prev.id = "photo-prev";
			control_prev.className = "inactive";
			control_prev.innerHTML = "previous page";
			
			control_next = document.createElement("A");
			control_next.id = "photo-next";
			control_next.className = "active";
			control_next.innerHTML = "next page";
			
			
			container.appendChild(controls);
			controls.appendChild(control_status);
			controls.appendChild(control_buttons);
			control_buttons.appendChild(control_prev);
			control_buttons.appendChild(control_next);
			
			photobox = new animator(scroller,control_next,control_prev,control_status,containerWidth,totalImages);
		
			function nextSlide() { photobox.next(); }
			function prevSlide() { photobox.prev(); }
			
	
					
			control_prev.onclick = prevSlide;
			control_next.onclick = nextSlide;
		}
	}
};


function elemSetAttribute(elemId,attr,val) {
	var elem = document.getElementById(elemId);
	
	if(navigator.appName.indexOf("Explorer") > -1) { elem.parentNode.scrollLeft = val; }
	else elem.setAttribute(attr,"left: -"+val+"px;");
}



		animator = function(initElem,initNextElem,initPrevElem,initStatusElem,initRegionWidth,initMaxRegions) {
		
			this.elem = initElem;
			this.nextElem = initNextElem;
			this.prevElem = initPrevElem;
			this.statusElem = initStatusElem;
			this.regionWidth = initRegionWidth;
		
			this._natural_w = this.elem.offsetWidth;
			this._natural_h = this.elem.offsetHeight;	

			this.totalFrames = 10;
			this.ticker = 0;
			this.frameRate = 1000/18;
			
			this.currentRegion = 0;
			this.maxRegions = initMaxRegions-1;

			this.origin_x = 0;
		
		};
		
		animator.prototype.attachElement = function(initElem) {
			this.elem = initElem;
			this._natural_w = this.elem.offsetWidth;
			this._natural_h = this.elem.offsetHeight;	
		};
		
		

		animator.prototype.setPosition = function(newx) {
			
			
			this.distance_x = newx - this.origin_x;
			
		};

		animator.prototype.next = function() {
						
			if(this.currentRegion != this.maxRegions) {
	
				this.currentRegion++;
				
				this.setPosition(this.currentRegion * this.regionWidth);
				this.tween();
		
				
				this.statusElem.innerHTML = "Page " + (this.currentRegion+1) + " of " + (this.maxRegions+1);
				
				if(this.currentRegion==this.maxRegions) {
					this.prevElem.className = "active";
					this.nextElem.className = "inactive";
				} else {
					this.nextElem.className = "active";
					this.prevElem.className = "active";
				}
				
			}
		
		};
		
		animator.prototype.prev = function() {
	
			if(this.currentRegion != 0) {
				
				this.currentRegion--;
				
				this.setPosition(this.currentRegion * this.regionWidth);
				this.tween();
				
				this.statusElem.innerHTML = "Page " + (this.currentRegion+1) + " of " + (this.maxRegions+1);
			
				if(this.currentRegion==0) {
					this.prevElem.className = "inactive";
					this.nextElem.className = "active";
				} else {
					this.nextElem.className = "active";
					this.prevElem.className = "active";
				}
				
			}
		
		};		
		
		animator.prototype.tween = function() {
			
			var slope;
			var newpos;
			
			for(var i=1;i<this.totalFrames;i++) {
			
				slope = -1 * Math.pow(i / this.totalFrames - 1,2) + 1;
			
				// Set Position
				newpos =  Math.floor(this.origin_x + (this.distance_x * slope));
			
				setTimeout("elemSetAttribute('photos','style','"+newpos+"')",(this.frameRate * i));
			
		
			}
			setTimeout("elemSetAttribute('photos','style','left: -"+(this.currentRegion * this.regionWidth)+"px;')",(this.frameRate * this.totalFrames));
			setTimeout("elemSetAttribute('photos','style','"+(this.currentRegion * this.regionWidth)+"')",(this.frameRate * this.totalFrames));
			this.origin_x = this.currentRegion * this.regionWidth
		};



