// JavaScript Document

//<!--
// Courtesy of SimplytheBest.net (http://simplythebest.net/info/dhtml_scripts.html)

var gSlideshowInteval;
var gImages;
var gAlts;
var gNumberOfImages;
var gImageCapableBrowser;
var gCurrentImage;

function doStuff() {

initRollovers();

gSlideshowInterval = 6;
gImages = document.homepageForm.slideshow.value.split(",");
gAlts = document.homepageForm.slideshow_alts.value.split("_");
gNumberOfImages = gImages.length;

//gImages[0] = "images/homepage/photo0.jpg";
//gImages[1] = "images/homepage/photo1.jpg";
//gImages[2] = "images/homepage/photo2.jpg";

gImageCapableBrowser = canManipulateImages();
gCurrentImage = 0;
setInterval("nextSlide()",gSlideshowInterval * 1000);

}
function canManipulateImages() {
	if (document.images) {
		return true;
		}
	else {
		return false;
		}
}
function loadSlide(imageURL, imageAlt) {
	if (gImageCapableBrowser) {
		document.slide.src = imageURL;
		document.slide.alt = imageAlt;
		return false;
	}
	else {
		return true;
	}
}
function nextSlide() {
	gCurrentImage = (gCurrentImage + 1) % gNumberOfImages;
	loadSlide(gImages[gCurrentImage], gAlts[gCurrentImage]);
}
// -->



function image_selector_popup(x, width) {
newwindow = window.open(x,'outside','titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=' + width);
}

function imageset_selector_popup(x) {
newwindow = window.open(x,'outside','titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=300');
}

function linkset_selector_popup(x) {
newwindow = window.open(x,'outside','titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600');
}

function document_selector_popup(x) {
newwindow = window.open(x,'outside','titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=300');
}

function form_selector_popup(x) {
newwindow = window.open(x,'outside','titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=300');
}

function image_preview_popup(x,height,width)  {
			height = height + 10;
			width = width + 10;
			params = 'titlebar=no,toolbar=no,resizable=no,scrollbars=no,height=' + height + ',width=' + width;
 			window.open(x,'outside',params);
}

function imageset_view_popup(x,height,width)  {
			height = height + 200;
			width = width + 100;
			params = 'titlebar=no,toolbar=no,resizable=no,scrollbrs=no,height=' + height + ',width=' + width;
 			window.open(x,'outside',params);
}


function onSearchFocus(e, s) {
	if (e.value == s)
		e.value = "";
}

function onSearchBlur(e, s) {
	if (e.value.length < 1)
		e.value = s;
}
	











/* get elements by class name.... */
function myGetElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}
 
// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

/*
function fgetAllDataTables() {
	if (!document.getElementsByTagName) return false;
	var eleTables = document.getElementsByTagName("table");
	for (var i=0; i < eleTables.length; i++) {
		// if (eleTables[i].className == "datatable")
		// {
		fStripes(eleTables[i]);
		// }
	}
}

function fStripes(eleTable) {
	var eleTableRows = eleTable.getElementsByTagName("tr");
	for (var i=1; i < eleTableRows.length; i++) {
		eleTableRows[i].className = "trgrey";
		i++;
	}
}

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

addLoadEvent(fgetAllDataTables);

*/


function changeLanguage() {
    var dd = document.getElementById("countries-dropdown");
    var url = dd.value;
    window.location = url;
}