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

function reportError(request){
	alert('Sorry. There was an error.');
}

function DO_AJAX(container, URL){
	var params = 'someParameter=ABC';

	var myAjax = new Ajax.Updater({success: container, failure:container}, URL,
		{
			method: 'get',
			//parameters: params,
			evalScripts: true
			//onFailure: reportError
		});
}





////////////////////////////////////////////////////////////////
///
///   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 toggleElement (element, number) {

	div = document.getElementById(element);
	img = document.getElementById('BTN_arrow_' + number);
	
	if(div.style.display == 'block'){
		div.style.display = 'none';
		img.src = 'images/BTN_arrow_right_01.png';
		img.oversrc = 'images/BTN_arrow_right_02.png';
		
	}else{
		div.style.display = 'block';
		img.src = 'images/BTN_arrow_down_01.png';
		img.oversrc = 'images/BTN_arrow_down_02.png';
	}
	
}

function toggleSource (element, source_01, source_02) {
	img = document.getElementById(element);
	if(img.src == source_01){
		img.src = source_02;
	}else{
		img.src = source_01;
	}
	
}



//////////////////////////////////////////////////////////////
///
///	Center an element in the window
///
///////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////
///
///   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 "";
}

