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 hoverCursor(element) {
	element.style.cursor = "pointer";
}

function normalCursor(element) {
	element.style.cursor = "auto";
}

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 getWindowHeight() {
  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;
  }
  return myHeight;
}

function getWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
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;
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function checkEmail(inputvalue){
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false; 
    }
}

function checkZip(inputvalue){
    var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
    return zipCodePattern.test(inputvalue);
}

function checkPhone(inputvalue){
    var phonePattern = /^\d{10}$/;;
    return phonePattern.test(inputvalue);
}

function checkEnter(event,submit_function){ 
	var keynum;
	if(window.event) { // IE
		keynum = event.keyCode;
	} else if(event.which) { // Netscape/Firefox/Opera
		keynum = event.which;
	}

	if(keynum == 13){ //if generated character code is equal to ascii 13 (if enter key)
		submit_function(); //submit the form
	}
}

function checkFormSubmitEnter(event, form_id) {
	checkEnter(event, function(){$(form_id).submit();})
}

function verticallyCenterElement(element_id, element_height) {
	var window_height = getWindowHeight();
	var element_offset = ((window_height / 2) - (element_height/2));
	$$(element_id).top = (parseInt(element_offset) + "px");
}

function centerElement(element_id, element_width, element_height) {
	var window_height = getWindowHeight();
	var window_width = getWindowWidth();
	var element_offset_height = ((window_height / 2) - (element_height/2));
	var element_offset_width = ((window_width / 2) - (element_width/2));
	$$(element_id).top = (parseInt(element_offset_height) + "px");
	$$(element_id).left = (parseInt(element_offset_width) + "px");
}



YAHOO.util.Event.onDOMReady(init);
