////////////////////////////////////////////////////////////////
///
///   AJAX Functions
///
////////////////////////////////////////////////////////////////

var xmlHttp;

function GET_AJAX(doc, doFunc, divID){
    xmlHttp=GetXmlHttpObject();
    xmlHttp.onreadystatechange=function(){ 
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                doFunc(xmlHttp, divID);
			}
		}
    }
	
	//var doc=doc;
	//url=url+"?q="+;
	//url=url+"&sid="+Math.random();
    xmlHttp.open("GET",doc,true);
    xmlHttp.send(null);
}


function writeHTML(req, divID){
    //document.getElementById(divID).innerHTML = req.responseText;
	setAndExecute(divID, req.responseText);
}

//Add this extra step in case there's any Javascript in the response
function setAndExecute(divId, innerHTML){   
	var div = document.getElementById(divId);
	div.innerHTML = innerHTML;
	var x = div.getElementsByTagName("script");
	for(var i=0;i<x.length;i++){
		eval(x[i].text);
	}
}





////////////////////////////////////////////////////////////////
///
///   Show / Hide Element
///
////////////////////////////////////////////////////////////////

function mouseLeaves (element, evt) {
	if (typeof evt.toElement != 'undefined' && typeof element.contains != 'undefined') {
		return !element.contains(evt.toElement);
	}else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) {
		return !contains(element, evt.relatedTarget);
	}
}



function contains (container, containee) {
	while (containee) {
		if (container == containee) {
			return true;
		}
		
		containee = containee.parentNode;
	}
	return false;
}


function hideElement (element) {
	div = document.getElementById(element);
	div.style.display = 'none';
}
	

function showElement (element) {
	div = document.getElementById(element);
	div.style.display = 'block';
}


/*
function handleBorder(action) {
	if(action == "on"){
		document.getElementById('drop_box').style.border-bottom = '2px solid #CCCCCC';
	}else if(action == "off"){
		document.getElementById('drop_box').style.border-bottom = '0px';
	}
}
*/



////////////////////////////////////////////////////////////////
///
///   Find The Position of an Element
///
////////////////////////////////////////////////////////////////


function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}
  
function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}






////////////////////////////////////////////////////////////////
///
///   SimpleSwap
///
////////////////////////////////////////////////////////////////

// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 


function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}





////////////////////////////////////////////////////////////////
///
///   Cookie Functions
///
////////////////////////////////////////////////////////////////

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}
