function initialize() {
	// initialize dynoforms
	DynoForm('topNav', '', 'topNav');
	if(location.href.match(/gog.uncoso.com/)) {
		location.replace('http://www.thegiftofgiving.com'+location.pathname);
	} else if(location.href.replace(/http[s]?:\/\//,'').match(/^www/) == null) {
		location.replace(location.href.replace(/(http[s]?:\/\/)/,"$1www."));
	}
}

function $(id) {
	return document.getElementById(id);
}

function getPositionX(element) {
  var posX = 0;
  while(element != null) {
    posX += element.offsetLeft;
    element = element.offsetParent;
  }
  return posX;
}

function getPositionY(element) {
  var posY = 0;
  while(element != null) {
    posY += element.offsetTop;
    element = element.offsetParent;
  }
  return posY;
}

function noClass(str) {
	if((str == '') || (str == null)) return '';
	return str.toString().replace(/class=[a-zA-Z0-9_"']/ig, '');
}

function noTags(str) {
	if((str == '') || (str == null)) return '';
	return str.toString().replace(/<[^>]+>/ig, '').replace(/&[a-zA-Z0-9#]{2,5};/ig, '');
}

function fixHTML(str) {
	if((str == '') || (str == null)) return '';
	str = str.toString();

	str = str.replace(/&lt;/ig, '<');
	str = str.replace(/&gt;/ig, '>');
	str = str.replace(/&quot;/ig, '"');
	return str;
}
	
DFO.formatMoney = function(value) {
	value = value.toString().replace(/[^0-9.]/g, '');
	if(isNaN(value)) {
		value = 0;
	} else {
		value = Number(value);
	}
	value = value.toFixed(2);
	return '$'+value.toString();
}

DFO.checkEmail = function(element) {
	if(element.value.match(/^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-\.]+\.[A-Za-z]{2,4}$/)) {
		return true;
	} else {
		alert('You must enter a valid email address');
		element.value = '';
		return false;
	}
}

DFO.login = function() {
	if(location.href.match(/default.aspx/i)) {
		var newURL = location.href.replace(/ctl\/[a-zA-Z]+\//, '').replace(/default.aspx/i, 'ctl/Login/Default.aspx');
	} else {
		var newURL = 'http://www.thegiftofgiving.com/Home/tabid/36/ctl/Login/Default.aspx';
	}
	location.replace(newURL);
}

DFO.logout = function() {
	if(location.href.match(/default.aspx/i)) {
		var newURL = location.href.replace(/ctl\/[a-zA-Z]+\//, '').replace(/default.aspx/i, 'ctl/Logoff/Default.aspx');
	} else {
		var newURL = 'http://www.thegiftofgiving.com/Home/tabid/36/ctl/Logoff/Default.aspx';
	}
	location.replace(newURL);
}

DFO.changeDetails = function() {
	if(userident) {
		if(location.href.match(/default.aspx/i)) {
			var newURL = location.href.replace(/ctl\/[a-zA-Z]+\//, '').replace(/UserID\/[0-9]+\//, '').replace(/default.aspx/i, 'ctl/Profile/UserID/'+userident+'/Default.aspx');
		} else {
			var newURL = 'http://www.thegiftofgiving.com/Home/tabid/36/ctl/Profile/UserID/'+userident+'/Default.aspx';
		}
		location.replace(newURL);
	} else {
		DFO.login();
	}
}

DFO.register = function() {
	if(location.href.match(/default.aspx/i)) {
		var newURL = location.href.replace(/ctl\/[a-zA-Z]+\//, '').replace(/default.aspx/i, 'ctl/Register/Default.aspx');
	} else {
		var newURL = 'http://www.thegiftofgiving.com/Home/tabid/36/ctl/Register/Default.aspx';
	}
	location.replace(newURL);
}

DFO.setCookie = function(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
		";path=/";
}

DFO.getCookie = function(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return null;
}

document.write('<div id="tooltip" style="position: absolute; z-index: 100; display: none;"></div>');
document.onmousemove = positionTip;
var posX;
var posY;
function positionTip(e) {
	posX = (!document.all)? e.pageX : event.clientX+document.body.scrollLeft;
	posY = (!document.all)? e.pageY : event.clientY+document.body.scrollTop;
}

DFO.tooltip = function(id) {
	if(posY && posX) {
		$('tooltip').style.top = posY+'px';
		$('tooltip').style.left = posX+'px';
		// write the contents
		if(id == 'addressName') {
			$('tooltip').innerHTML = 'The address will be saved in<br />your addressbook using this label';
		}
		// display the tip
		$('tooltip').style.display = 'block';
	}
}

DFO.clearTooltip = function() {
	$('tooltip').style.display = 'none';
}

// Hide title for manage profile page
function fixPage() {
	if(location.href.match(/ctl\/Profile/i)) {
		if($('dnn_ctr_dnnTITLE_lblTitle')) $('dnn_ctr_dnnTITLE_lblTitle').style.display = 'none';
		if($('dnn_ctr_ManageUsers_cmdProfile') && $('dnn_ctr_ManageUsers_cmdProfile').parentNode) {
			$('dnn_ctr_ManageUsers_cmdProfile').parentNode.style.display = 'none';
		}
	} else if(location.href.match(/ctl\/Register/i)) {
		if($('dnn_ctr_dnnTITLE_lblTitle')) $('dnn_ctr_dnnTITLE_lblTitle').style.display = 'none';
	}
}
