// JavaScript Document
/* UDOH Main Website Javascript Library
	Written By: Ari Aryazand
	Date: July 9, 2008
*/

/*****************************************************************/
//	a2z List Creator
/*****************************************************************/
function ie_a2z( obj ){
	var a2zContainer = document.getElementById('AZlist-container');
	
	if( a2zContainer == null ) {
		a2zContainer = document.createElement("div");
		a2zContainer.id = "AZlist-container";
		
		a2zContainer.onmouseover = function() {mcancelclosetime(); return false;};
		a2zContainer.onmouseout  = function() {mclosetime(); return false;};
	}
	
	orderedList = document.createElement("ol");
	orderedList.className = 'AZlist';
	
	for( x=65; x<91; x++ ) {
		var char = String.fromCharCode(x);
		var listItem =document.createElement("li");	
		var newlink = document.createElement("a");

		newlink.className = 'a2z';
		newlink.href = 'AAA.HTML';
		//newlink.setAttribute('href', 'XYZ.HTML');
		
		var linkText = document.createTextNode( char );
		newlink.appendChild(linkText);
		
		listItem.appendChild(newlink);
		orderedList.appendChild (listItem);		

	}
	a2zContainer.appendChild(orderedList);
	document.body.appendChild(a2zContainer);
}



function createList( char, url, orderedList, ajax, objID ) {

	var listItem =document.createElement("li");	
	var newlink = document.createElement("a");
	//newlink.setAttribute('class', 'a2z');
	newlink.className = 'a2z';
	newlink.setAttribute('href', url);
	if (ajax) {
		newlink.onclick = function() {getPage(objID,'include/a2z/', 'POST', 'id='+char.toLowerCase()); return false;};
		//newlink.onclick = function() {getPage(objID,'include/a2z/index.php?id='+char.toLowerCase(), 'GET', ''); return false;};
	}
	var linkText = document.createTextNode( char );
	newlink.appendChild(linkText);
	
	listItem.appendChild(newlink);
	orderedList.appendChild (listItem);		
	
	return orderedList;
}

function a2zList( ajax, objID ) {
	
	var a2zContainer = document.getElementById('AZlist-container');
	
	
	if( a2zContainer == null ) {
		a2zContainer = document.createElement("div");
		a2zContainer.id = "AZlist-container";
		a2zContainer.onmouseover = function() {mcancelclosetime(); return false;};
		a2zContainer.onmouseout  = function() {mclosetime(); return false;};
	}
	
	var parentTag = document.getElementById('AZlist-container').parentNode;
	
	orderedList = document.createElement("ol");
	orderedList.className = 'AZlist';
//	orderedList.setAttribute('class', 'AZlist');
	
	for( x=65; x<91; x++ ) {
		var char = String.fromCharCode(x);
		if( ajax )
			createList(char, "", orderedList, ajax, objID);
		else
			createList(char, 'include/a2z/?id='+char+'', orderedList, ajax, objID);

	}
	createList('#', '', orderedList, ajax, objID);
	a2zContainer.appendChild(orderedList);
	
	parentTag.appendChild(a2zContainer);
	//document.body.appendChild(a2zContainer);
	
	//window.onload = function() {
	//	document.body.appendChild(a2zContainer);	
	//}
}


//**********************************************************************
// Setup AJAX object.
//**********************************************************************
function getxmlhttp() {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");			//used in Newer IE
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	//Used in Older IE
		} catch(e) {
			xmlhttp = false;
		}
	}

	if( !xmlhttp && typeof XMLHttpRequest != "undefined" ) {
		xmlhttp = new XMLHttpRequest;
	}
	
	return xmlhttp;
}
function getPage( objID, serverPage, method, params ) {
	
	var xmlhttp=getxmlhttp();
	var rtnVal = null;
	
	var obj = document.getElementById( objID );
	
	xmlhttp.open(method, serverPage, true);
	
	if( (method == "POST") || (method == "post") ) {
		//Send the proper header information along with the request
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		rtnVal = params;
	}

	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200 && xmlhttp.responseText!= "") {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send(rtnVal);
}

function winOpen(){
	args = winOpen.arguments;
	
	for(i=0; i<args.length; i++) {
		objStyle1 = document.getElementById(args[i]).style;
		objStyle1.visibility = 'visible'; 
		objStyle1.display = 'block';
	}
}

function winClose(){
	args = winClose.arguments;
	
	for(i=0; i<args.length; i++) {
		objStyle1 = document.getElementById(args[i]).style;
		objStyle1.visibility = 'hidden'; 
		objStyle1.display = 'none';
	}
}
/***** End A2Z List Creator *****/





//*******************************************************************************************
// Simple Drop Down Menu...
//*******************************************************************************************
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// get coordinates of an object
function getCoords (obj) {		// Compatible with IE , FF and Safari
	var element = document.getElementById( obj );
	var coords = { x: 0, y: 0, width: element.offsetWidth, height: element.offsetHeight };
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	return coords;
}

// open hidden layer
function mopen(obj, id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem){ ddmenuitem.style.visibility = 'hidden'; ddmenuitem.style.display = 'none'; }

	// get new layer and coordinates
	ddmenuitem = document.getElementById(id);
	var coords = getCoords(obj);
	var xOffSet = -290;
	var yOffSet = 20; 
	// Show it
	ddmenuitem.style.left = coords.x + xOffSet + 'px';
	ddmenuitem.style.top  = coords.y + yOffSet + 'px';
	ddmenuitem.style.visibility = 'visible';
	ddmenuitem.style.display = 'block'; 
}
// close showed layer
function mclose()
{
	if(ddmenuitem) {ddmenuitem.style.visibility = 'hidden'; ddmenuitem.style.display = 'none'; }
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

//*******************************************************************************************
// End Simple Dropdown Menu
//*******************************************************************************************

