//is being called on load / refresh only, not within navigation
function all_initialize() {
	htmlhistory_initialize();
	h = location.hash; //get index.php?(#.*)
	h = h.substring(1, h.length);
	htmlhistory_goto(h);
}
//htmlhistory
function htmlhistory_initialize() {
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(htmlhistory_historychange);
}
function htmlhistory_add(hash, data) {
	dhtmlHistory.add(hash, data);
}
function htmlhistory_historychange(newLocation, historyData) {
	htmlhistory_goto(newLocation, historyData);
}
//ajax requests
function error_filler(t, where, url) {
	$(where).innerHTML = '<div style="font-family:lucida console,courier new;font-size:12px;color:#990000;background-color:#ffcccc;margin:0px;padding:10px;border:1px solid #660000;">Error <b>' + t.status + '</b> in <b>' + url + '</b>: <b>' + t.statusText + '</b></div>';
}
function ajax_load(config) { //url, pars, where, evalonsuccess, hideloading
	if ((config.where != '') && (typeof(config.where) != 'undefined')) {
		if ($(config.where) != null) {
			if (config.hideloading == true) {
				//do nothing
			} else {
				if (config.where == 'all_page_content') {
					the_loading_div = {
						offsetWidth: 700,
						offsetHeight: 470
					};
				} else {
					the_loading_div = $(config.where);
				}
				temp_toinsert = '<span style="color:#44BB66">Loading...</span>';
				$(config.where).innerHTML = temp_toinsert;
			}
		} else {
			//alert('id="' + config.where + '" not found. cannot load "' + config.url + '"');
		}
	}
	var myAjax = new Ajax.Request(
		config.url,
		{
			method: 'get',
			parameters: 'w='+encodeURIComponent(rewrites)+'&ajax=true&random=' + Math.random() + '&' + config.pars,
			onSuccess: function(t) {
				if (config.where != '') {
					$(config.where).innerHTML = t.responseText;
				}
				eval(config.onsuccess);
				t.responseText.evalScripts();
				window.scrollTo(0, 0);
			},
			onFailure: function(t) {
				error_filler(t, config.where, config.url);
			}
		}
	);
}
function request(requrl, pars, where, hideloading) {
	if (pars) {
		pars = '&' + pars;
	} else {
		pars = '';
	}
	ajax_load({
		url: root_address + 'request.php',
		pars: query_string + '&request=' + requrl + pars,
		where: where,
		hideloading: true
	});
}
function request_submit(pars) { //url, form, pars, history, where
	if (pars.form) {
		request(pars.url, Form.serialize(pars.form), pars.where);
	} else if (pars.pars) {
		request(pars.url, pars.pars, pars.where);
	} else {
		alert('Please provide .form or .pars');
	}
	if (pars.history) htmlhistory_add(pars.history);
}

function Mod(X, Y) { 
	return X - Math.floor(X/Y)*Y; 
}

function Div(X, Y) { 
	return Math.floor(X/Y);
}

var Target_Date = 0;

function setClientTime() {
	if (Target_Date <= 0) {
		Today = new Date().getTime(); 	
		Target_Date = Today + 86400000; 	
		var pars = 'random=' + Math.random()+'&time_td='+Today;
		where='';
		var config=Array();
		config.url = root_address + 'ajax.setClientTime.php';
		config.pars=pars;
		config.where=where;
		config.hideloading=false;
		ajax_load(config);
	}
}

function curTime() { 
	Today = new Date().getTime();
	Time_Left = Math.round((Target_Date - Today)/1000);

	var m=Div(Time_Left, 60); 
	
	var hrs=Div(Time_Left, 3600);  
	var mns=Mod(m, 60); 
	var sec=Mod(Time_Left, 60);
	
	$('clock').innerHTML="<b>" +hrs+" hours "+mns+" minutes "+sec+" seconds </b> before this promo ends!";
	setTimeout("curTime()",1000);
}

function getEmailName(email, name) { 
	var pars = 'random=' + Math.random() + '&email=' + email + '&name=' + name;
	where='';
	var config=Array();
	config.url = root_address + 'ajax.getEmailName.php';
	config.pars=pars;
	config.where=where;
	config.hideloading=true;
	ajax_load(config); 
} 

function handleUnload() { 
	if ((this_address.indexOf('notify_free') >=0 ) || (this_address.indexOf('return') >=0 )) { 
		window.open(root_address + 'downloadarea.html','','width=377,height=257,menubar=0,resizable=1,status=0,toolbar=0,scrollbars=0,location=0');
	} 
} 

function popupGuru() { 
	window.open(root_address + 'moneyguruskiller.html','','width=439,height=376,menubar=0,resizable=1,status=0,toolbar=0,scrollbars=0,location=0');
}  

//get window width
function getWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
  return myWidth;
}

//get window height
function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }

  return myHeight;
}

//get page height
function getPageHeight() {
  return document.body.offsetHeight;
}

//-------------------------------------------------------------------------------------------------
function CheckForm(f,elem) {
	if (f.from.value == "") {
		alert("Please enter your email address.");
		f.from.focus();
		return false;
	} else { 
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = f.from.value;
		if(reg.test(address) == false) {
			alert('Invalid email address');
			return false;
		} else { 
			deactivateBox(elem);
		}
	}
	return true;
} 