function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof window.onload != 'function'){
    window.onload = func;
  }
  else{
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

function $(strId){
	return document.getElementById(strId);
}

function getWindowSize(){
  windowWidth =  window.innerWidth;
  windowWidth = (windowWidth)? windowWidth : document.documentElement.clientWidth;
  windowWidth = (windowWidth)? windowWidth : document.body.clientWidth;
  windowHeight =  window.innerHeight;
  windowHeight = (windowHeight)? windowHeight: document.documentElement.clientHeight;
  windowHeight = (windowHeight)? windowHeight: document.body.clientHeight;  
  return {'width': windowWidth, 'height': windowHeight};
}

function getPageSize(){
  var windowSize = getWindowSize()
  var xScroll = document.body.scrollWidth;
	var yScroll = (window.innerHeight && window.scrollMaxY)? window.innerHeight + window.scrollMaxY : document.body.scrollHeight;
	var pageWidth = (xScroll < windowSize.width)? windowSize.width : xScroll;  
  var pageHeight = (yScroll < windowSize.height)? windowSize.height : yScroll;
  return {'width': pageWidth, 'height': pageHeight};
}

function getCursor(e) {
  e = e || window.event;
  return {'x': e.clientX, 'y': e.clientY};
}

function getScrollCursor(e){
  e = e || window.event;
	var curScrollX = (e.pageX)? e.pageX : e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	var curScrollY = (e.pageY)? e.pageY : e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  return {'x': curScrollX, 'y': curScrollY};
}

function openItem(context,item){
  var clean = item.id.replace("get_", "");
  var show = $(clean);
  changeClass(context,show);
  changeClass(context,item);
}

// The Change Class
function changeClass(context,el) {
  var tag = el.tagName;
  var clas = el.className; 
  var link = $(context).getElementsByTagName(tag);
  for (i=0; i<link.length; i++) {
    if (link[i].className == clas+'_on') link[i].className  = clas;
    el.className = clas+'_on';
  }
}

// hideSelect for ie
function hoverImages(context,extension){
  var img = $(context).getElementsByTagName('img');
  for (i = 0; i<img.length; i++) {
   
    var myimages=new Array()
    myimages[i]=new Image()
    myimages[i].src=img[i].src.replace('.'+extension,'_hover.'+extension);

    img[i].onmouseover = function(){
      this.src = (this.src.indexOf('_hover') == -1)? this.src.replace('.'+extension,'_hover.'+extension):this.src;     
    }
    img[i].onmouseout = function(){
      this.src = (this.src.indexOf('_hover') != -1)? this.src.replace('_hover.'+extension,'.'+extension):this.src;    
    }
  }
}

function ajaxRequest(url, variables, action){

  var objXhr = false;

  if (window.XMLHttpRequest){objXhr = new XMLHttpRequest();}
   
  else if (window.ActiveXObject) {
    var ieXHR = new Array(
    "Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0",
    "Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0",
    "MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
    for (var i=0; i<ieXHR.length; i++) {
			try{
				objXhr = new ActiveXObject(ieXHR[i]);
				break;
			}catch(e){}
		}
  } 
    
	if(objXhr) {
    
    if(variables==null){objXhr.open("GET",url,true);}

    if(variables!=null){	 
      objXhr.open("POST",url,true);
      objXhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');	
    }
    
    if(action){
		  objXhr.onreadystatechange = function () {
			  if (objXhr.readyState == 4) {
				  if (objXhr.status == 200) {
            action(objXhr.responseXML);
					}
				}
		  }
    }
    objXhr.send(variables);
	}else{return false}
}



