function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myWidth;
}

function download(prod, url){
    var link = 'http://www.softarama.com/Products/download/';
    var c = readCookie('aff');
    if (c == "rn") {link += 'rn/';}    
    if (prod == 'co') {var installer = link + 'captain-optimizer.exe';}
	else if (prod == 'cows') {var installer = 'captain-optimizer2011.exe';}
	else if (prod == 'rc') {var installer = link + 'registry-commander.exe';}
    else if (prod == 'ps') {var installer = link + 'privacy-sentinel.exe';}
	else if (prod == 'psrw') {var installer = link + 'rw/privacy-sentinel.exe';}
	else if (prod == 'rcrw') {var installer = link + 'rw/registry-commander.exe';}
	else if (prod == 'corw') {var installer = link + 'rw/captain-optimizer.exe';}
    window.open(installer,'dlnow','width=1,height=1,top=0,left=0');
    setTimeout(window.location = url, 500);
    return false;    
	};

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;
}

    
//SETTING UP OUR HELP EMERGENCY POPUP
//0 means disabled; 1 means enabled;
var EmergencyHelp = 0;

//loading popup with jQuery magic!
function loadEmergencyHelp(){
	//loads popup only if it is disabled
	if(EmergencyHelp==0){
		$("#backgroundPopupHelp").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupHelp").fadeIn("slow");
		$("#popupHelp").fadeIn("slow");
		EmergencyHelp = 1;
	}
}

//disabling popup with jQuery magic!
function disableEmergencyHelp(){
	//disables popup only if it is enabled
	if(EmergencyHelp==1){
		$("#backgroundPopupHelp").fadeOut("slow");
		$("#popupHelp").fadeOut("slow");
		EmergencyHelp = 0;
	}
}

//centering popup
function centerEmergencyHelp(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupHelp").height();
	var popupWidth = $("#popupHelp").width();
	//centering
	$("#popupHelp").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupHelp").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#EmergencyHelp").click(function(){
	    //misha tracker + GA
        $.ajax({url: "/help.php"});
		//centering with css
		centerEmergencyHelp();
		//load popup
		loadEmergencyHelp();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupHelpClose").click(function(){
		disableEmergencyHelp();
	});
	//Click out event!
	$("#backgroundPopupHelp").click(function(){
		disableEmergencyHelp();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && EmergencyHelp==1){
			disableEmergencyHelp();
		}
	});

});



/* --------------------------------------------------------------------- */
