﻿// Phone Book Online
// Developed By: Arsalan Tamiz (iam_mak[at]hotmail.com)
// ------------------------------------------------------------------

function createXHR() { 
	var xmlHttp = null;
	if (xmlHttp == null) {
		try  {  // Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();   
		} 
		catch (e) {  // Internet Explorer  
			try  {   
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			} 
			catch (e) {
				try   {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
				} 
				catch (e)   {    
					alert("Your browser does not support AJAX!");
					return false;   
				}  
			} 
		} 
	}
	return xmlHttp;
}

// fillcombo function
// This function fills the combo by reading XML file
// XML file must be like this
// <ComboItems>
//		<ComboItem>
//			<Display>Item #1</Display>
//			<ID>1</ID>
//		</ComboItem>
// </ComboItems>
function fillcombo(comboid, xmlfiletouse, loadingelement) {
	var x;
	x = createXHR();
	x.onreadystatechange = function () 	{
										if (x.readyState == 4)
											if (x.status == 200) {
												var comboitems = x.responseXML.getElementsByTagName("ComboItem");
												var i;
												var o;
												o = document.getElementById(comboid);				
												for(i = 0; i < comboitems.length; i++) {
													var textvalue;
													var textid;
													textvalue = comboitems[i].getElementsByTagName("Display")[0].firstChild.nodeValue;
													textid = comboitems[i].getElementsByTagName("ID")[0].firstChild.nodeValue;
													
													var opt;
													opt = document.createElement("option");
													opt.setAttribute("value", textid);
													opt.innerHTML = textvalue;
													o.appendChild(opt, null);
												}
												document.getElementById(loadingelement).style.display = "none";												
											}
										};
	document.getElementById(loadingelement).style.display = "block";
	x.open("GET", xmlfiletouse, true);
	x.send(null);
}

function clearcombo(comboid) {
	var cmbToClear;
	cmbToClear = document.getElementById(comboid);
	while(cmbToClear.length > 0)
		cmbToClear.remove(0);
}

function getE(sID) { return document.getElementById(sID); }

function GetScrollY() {
    return document.body.scrollTop
	        ? document.body.scrollTop
	        : (window.pageYOffset
	            ? window.pageYOffset
	            : (document.body.parentElement
	                ? document.body.parentElement.scrollTop
	                : 0
	            )
	        )
}

function GetAvailableContentHeight() {
    var oh = document.body.offsetHeight; 
    var sh = window.innerHeight;
	
    if (sh == null)
	    sh = document.documentElement.clientHeight;
	
    if (sh == null)
	    sh = document.body.clientHeight;
		
    return sh;
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;		
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function ToggleDisplay(obj) {
    if (obj.style.display == "none")
        obj.style.display = "";
    else
        obj.style.display = "none";
}
