﻿if (typeof jQuery != 'undefined') {
    $(function() {
        try {
            for (var i = 0; i < document.styleSheets.length; i++){
                var cssDoc = document.styleSheets[i];
                var myRules = new Array();
                if (cssDoc.cssRules) { myRules = cssDoc.cssRules; }
                else { myRules = cssDoc.rules; }

                for (var r = 0; r < myRules.length; r++) {
                    var cssRule = myRules[r];
                    if (cssRule.style.opacity) {
                        var opacity = parseFloat(cssRule.style.opacity);
                        var filter = "alpha(opacity = " + opacity * 100 + ")";
                        cssRule.style.filter = filter;
                        cssRule.style.zoom = "1";
                    }                
                }
            }
        } catch(e) { }
    });
}

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 var 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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function isDefined(variable) {
    return (typeof(variable) != 'undefined');
}

function URLEncode(clearString) {
  var output = '';
  
  if (isDefined(clearString) && clearString != "") {
      var x = 0;
      clearString = clearString.toString();
      var regex = /(^[a-zA-Z0-9_.]*)/;
      while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
    	    output += match[1];
          x += match[1].length;
        } else {
          if (clearString[x] == ' ')
            output += '+';
          else {
            var charCode = clearString.charCodeAt(x);
            var hexVal = charCode.toString(16);
            output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
          }
          x++;
        }
      }
  }
  return output;
}

function swfEmbedAltContent(id, w, h) {
    try {
        var el = $("#" + id);
        el.css("width", w + "px");
        el.css("height", h + "px");
        var newHtml = '<p style="width: ' + (w - 20) + 'px; padding:10px; text-align:center" class="content_flashAltTextThis page requires Flash, please download it here: (insert URL">This page requires Flash.  Please download it <a href="http://get.adobe.com/flashplayer" target="_blank">here</a>.</p>';
        el.html(newHtml);
    } catch(e) { }
}

