function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function setVideo(section_id) {
    var script = '';
    if (section_id == 200) {
        script = '"location_url=localhost/ENJOYPR_SEPARADO/home.aspx&html_ad_num=1000000101_2&html_auto_play=';
    }
    else {
        var video_id = Math.round(Math.random());

        switch (video_id) {
            case 0:
                script = 'location_url=localhost/ENJOYPR_SEPARADO/home.aspx&html_ad_num=1000000101_2&html_auto_play=';
                break;

            case 1:
                script = 'src="location_url=localhost/ENJOYPR_SEPARADO/home.aspx&html_ad_num=1000000101_2&html_auto_play=';
                break;
        }
    }

    $('#mainimg_banner').find('embed').attr('flashvars',script);

}

function get_video_id(p_section_id) {
    var video_id = 0;
    var video_num = '';
    if (p_section_id == 200) {
        video_num = '1000000101_2';
    }
    else {
        video_id = Math.round(Math.random());
        switch (video_id) {
            case 0:
                video_num = '1000000102_1';
                break;

            case 1:
                video_num = '1000000101_2';
                break;
        }
    }

    return video_num;
}

function setVideoToDiv(p_section_id ) {

    var v_div_id = 'mainimg_banner';
    var v_video_id = get_video_id(p_section_id);
    var dmc_so = new SWFObject("http://dmcflash.digitalmediacommunications.com/410/svp_300x260_ej.swf?8", "dmc-flash-object", "300", "260", "8", "#FFFFFF");
    dmc_so.addParam("allowScriptAccess", "always");
    dmc_so.addParam("wmode", "transparent");
    dmc_so.addVariable("location_url", escape(location.hostname + location.pathname));
    dmc_so.addVariable("html_ad_num", v_video_id);
    dmc_so.addVariable("html_auto_play", "");
    dmc_so.write(v_div_id);

    //so.write(p_div_id);
}

