/* 
SHOW SUBMENUS - Created By Shawn Her (shawn.her@gmail.com) 
List setup
*/
function show(box){
	if(document.getElementById(box).parentNode.getElementsByTagName("ul")[0].style.display == 'block'){
		var hidesub;
	}
	m = document.getElementById(box).parentNode.parentNode.getElementsByTagName('ul');
	for(i=0;i<m.length;i++){
		m[i].style.display = "none";
	}
	if(!hidesub){
		document.getElementById(box).parentNode.getElementsByTagName("ul")[0].style.display = 'block';
		clearTimeout(document.getElementById(box).tto);
	}
	clearTimeout(document.getElementById(box).tto);
}
function hide(eID){
	eID.parentNode.getElementsByTagName("ul")[0].style.display = "none";
}
function timeout(tohide){
	tohide.tto = setTimeout(function(){tohide.parentNode.getElementsByTagName("ul")[0].style.display = "none"}, 500);
}
function menu(menuID){
	if (document.getElementById(menuID))
	{	
		m = document.getElementById(menuID).getElementsByTagName('ul');
		for(i=0;i<m.length;i++){
			s = m[i].parentNode.getElementsByTagName('a')[0];
			s.onmouseover = function(){if(typeof show == 'function'){show(this.id);}};
			s.onmouseout = function(){if(typeof timeout == 'function'){timeout(this);}}
			m[i].onmouseover = function(){clearTimeout(this.parentNode.getElementsByTagName('a')[0].tto);}
			m[i].onmouseout = function(){if(typeof timeout == 'function'){timeout(this.parentNode.getElementsByTagName('a')[0]);}}
		}
	}
}
/*
Multi Purpose Tabs - Created by Shawn Her shawn.her@gmail.com 
Easy Setup using Lists
*/
function tabs(tabID){
	var p, l, id;
	p = document.getElementById(tabID).getElementsByTagName("li"); //get all list item(li) tags in specified element
	for(i=0; i<p.length; i++){ //loop through list items
		if(p[i].title == ""){ //if list items has no title attribute then do nothing
			//do nothing
		}else{ // if list items contains a title...
			l = p[i].getElementsByTagName("a")[0]; //get all first anchor(a) tags in list items
			l.onclick = function(){ //when link is clicked...
				var active;
				//false - will keep current sub-element active unless different tab is clicked
				//true - will allow to hide sub-element by clicking on it again
				if(this.parentNode.className == "active"){active = true;}
				//id = this.parentNode.title; //set parent list item title attributes as id
				for(i=0; i<p.length; i++){ //loop through list items 
					if(p[i].title == ""){ ////if list items has no title attribute then do nothing
						//do nothing
					}else{ //if list item tag contains a <title> attribute...
						//selects parent list item <title> attribute as the ID and displays the corresponding element of that ID
						p[i].getElementsByTagName("ul")[0].style.display = "none"; // set display style for sub <ul>
						p[i].className = "inactive"; //replace all parent list item classes
					}
				}// end for loop
				
				if(!active){
					if(this.parentNode.title == ""){
						//nothing
					}else{
						this.parentNode.getElementsByTagName("ul")[0].style.display = "block";
						this.parentNode.className = "active";
					}
				}
			}//end onclick
		}// end if
	}//end for loop
	return false;
}

//FORM VALIDATION
function validation(field, alerttxt, efield){
	with(field){
		var apos = value.indexOf("@");
		var dotpos = value.lastIndexOf(".");
		if(value == null || value == ""){
			alert(alerttxt);
			return false;
		}else if(apos<1 && efield == true || dotpos-apos<2 && efield == true){
			alert(alerttxt);
			return false;
		}else{
			return true;
		}
	}
}
function validate_email(field, alerttxt){
	with (field){
		var apos = value.indexOf("@");
		var dotpos = value.lastIndexOf(".");
		if (apos<1 || dotpos-apos<2){
			alert(alerttxt);
			return false;
		}else{
			return true;
		}
	}
}


function bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}
