// JavaScript Functions

// Load multiple functions on window onload and onresize
// Source: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent (func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


// Populates label text into an input field (i.e. search box)
function populateSearchFieldText (field_id, label) {
    if (!document.getElementById) return false;
    
    // On startup copy label text to field
    var field = document.getElementById(field_id);
	if (field.value == '')
	{
		field.value = label;
	}
    
    // On focus blank out field if label text is value
    field.onfocus = function () {
        if (this.value == label) {
            this.value = '';
        }
    }
    
    // On blur copy label text if value is blank
    field.onblur = function () {
        if (this.value == '') {
            this.value = label;
        }
    }   
}

// Load functions at startup
addLoadEvent(function(){
    populateSearchFieldText('search-input', 'Search...');
})



function langSelect() {
     if (!document.getElementById) return
     var iselect = document.getElementById("country-select");
	 function language() {
     	var url = iselect.options[iselect.selectedIndex].value;
		location.href = url;
     }
     if (iselect) {
         iselect.onchange = language;
     }
}

addLoadEvent(langSelect);



