/* Gustavo Jose Morales Carpio
   gustavo.morales@gmail.com
   Adobe Dreamweaver 8 Developer Certified */

function setActiveStyleSheet(title) {
   var index, active, main, logo;
	//var homesitio="http://localhost/ourwave/";
   var homesitio="http://www.ourwave.com/";
   for(index=0; (active = document.getElementsByTagName("link")[index]); index++) {
     if(active.getAttribute("rel").indexOf("style") != -1 && active.getAttribute("title")) {
       active.disabled = true;
       if(active.getAttribute("title") == title){
				 active.disabled = false;
			 }
     }
   }
	logo = document.getElementById("header_img");
	if(title == "Blue Wave"){
		logo.src=homesitio + "images/logo-blue.gif";
	}else{
		logo.src=homesitio + "images/logo-red.gif";
	}
}

function getActiveStyleSheet() {
  var index, active;
  for(index=0; (active = document.getElementsByTagName("link")[index]); index++) {
    if(active.getAttribute("rel").indexOf("style") != -1 && active.getAttribute("title") && !active.disabled){
			return active.getAttribute("title");
		}
  }
  return "Red Electric";
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else{
		expires = "";
	}
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {	
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
	  var c = ca[i];
  	while (c.charAt(0)==' '){
			c = c.substring(1,c.length);
		}
  	if (c.indexOf(nameEQ) == 0){
			return c.substring(nameEQ.length,c.length);
		}		
  }
  return "Red Electric";
}

function getPreferredStyleSheet() {
  var index, active;
  for(index=0; (active = document.getElementsByTagName("link")[index]); index++) {
    if(active.getAttribute("rel").indexOf("style") != -1 && active.getAttribute("rel").indexOf("alt") == -1 && active.getAttribute("title") ){
			return active.getAttribute("title");
		}
  }
  return "Red Electric";
}

window.onload = function(e) {
  var cookie = readCookie("ourwave_style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("ourwave_style", title, 365);
}

function popUp(archivo, nombre, opciones, ancho, alto){
	var winl = (screen.width - ancho) / 2;
	var wint = (screen.height - alto) / 2;
	opciones+=', width='+ancho+', height='+alto+', left='+winl+', top='+wint;
	return window.open(archivo, nombre, opciones);
}
