function $(id){
	return document.getElementById(id);
	//return element
}

function $$(id){
	return document.getElementById(id).style;
	//return element style
}

function hover(element) {
	element.style.cursor = "pointer";
	element.style.color = "#EE4523";
}

function hover2(element) {
	element.style.cursor = "pointer";
	element.style.color = "#EE4523";
}

function normal(element) {
	element.style.cursor = "auto";
	element.style.color = "#6699cc";
}

function normal2(element) {
	element.style.cursor = "auto";
	element.style.color = "#111";
}

function hoverButton(element,height) {
	element.style.cursor = "pointer";
	element.style.backgroundPosition = ("0px -" + height + "px");
}

function normalButton(element) {
	element.style.cursor = "auto";
	element.style.backgroundPosition = "0px 0px";
}

function forceFullLength(minHeight) {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
    myHeight = document.body.clientHeight;
  }

	//alert(myHeight);
	if (myHeight > minHeight) $$('main_content').height = (myHeight - 146) + 'px';
}

function createXMLHttpRequestObject() {
  // xmlHttp will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // try to instantiate the native XMLHttpRequest object
  try
  {
    // create an XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
    }
    catch(e) { }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function loadExternalData(source_url,target_id,callbackfunction){
	var httpobject = createXMLHttpRequestObject();
	var url=source_url;
 	var params = "";

	httpobject.open("POST", url , true);
	httpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpobject.setRequestHeader("Content-length", params.length);
	httpobject.setRequestHeader("Connection", "close");

	httpobject.onreadystatechange = function() {//Call a function when the state changes.
		if((httpobject.readyState == 4 && httpobject.status == 200) || navigator.userAgent.indexOf('Safari') > 0) {
			$(target_id).innerHTML=httpobject.responseText;
			callbackfunction();
		}
	}

	httpobject.send(params);
	
}

function submitFormAJAX(form_id,source_url,target_id,callbackfunction){
	//$(target_id).innerHTML = "<img src=\"../img/loader21.gif\" border=\"0\"> saving data...";
	
	var httpobject = createXMLHttpRequestObject();
	var url=source_url;
 	var params = "form=main_form&";

	var myForm = $(form_id);
  	params += getParameters(myForm);
	httpobject.open("POST", url , true);
	httpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpobject.setRequestHeader("Content-length", params.length);
	httpobject.setRequestHeader("Connection", "close");
	httpobject.send(params);

	httpobject.onreadystatechange = function() {//Call a function when the state changes.
		if((httpobject.readyState == 4 && httpobject.status == 200) || navigator.userAgent.indexOf('Safari') > 0) {
			$(target_id).innerHTML=httpobject.responseText;
			callbackfunction();
		}
	}

}

function getParameters(obj) {
   var getstr = "";
   for (var i=0; i<obj.childNodes.length; i++) {
	  //alert(obj.childNodes[i].tagName);
      if (obj.childNodes[i].tagName == "TEXTAREA") {
         var sel = obj.childNodes[i];
         getstr += sel.name + "=" + obj.childNodes[i].value + "&";
      }
      if (obj.childNodes[i].tagName == "INPUT") {
         if (obj.childNodes[i].type == "text" || obj.childNodes[i].type == "hidden" || obj.childNodes[i].type == "password") {
            getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
         }
         if (obj.childNodes[i].type == "checkbox") {
            if (obj.childNodes[i].checked) {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            } else {
               getstr += obj.childNodes[i].name + "=&";
            }
         }
         if (obj.childNodes[i].type == "radio") {
            if (obj.childNodes[i].checked) {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
         }
      }   
      if (obj.childNodes[i].tagName == "SELECT") {
         var sel = obj.childNodes[i];
         getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
      }
      if (obj.childNodes[i].tagName == "DIV") {
         getstr += getParameters(obj.childNodes[i]);
      }
      
   }

   return getstr;
}


function getElementArrayById(baseIdentifier) {
    var allWantedElements = [];
    var idMod = 0;
    while($(baseIdentifier + '_' + (idMod + 1))) { // will stop when it can't find any more
        allWantedElements.push($(baseIdentifier + '_' + (idMod + 1)));
		idMod++;
    }
    return allWantedElements;
}

function getBaseName(raw_name) {
	u_pos = raw_name.lastIndexOf('_');
	base_name = raw_name.substring(0,u_pos);
	return base_name;
}

function changecss(theclass,element,value) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	} else if (document.getElementById) {
		cssRules = 'cssRules';
	}

	for (var S = 0; S < document.styleSheets.length; S++) {
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theclass) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}
}

function goToURL(url) {
	self.location = url;
}


function getContentFromIframe(iFrameID) {
	var content = "";
	var myIFrame = $(iFrameID);  
	content = myIFrame.contentWindow.document.body.innerHTML;  
	return content;
 }


YAHOO.util.Event.onDOMReady(init);
