//browser detection, variable initialization
var d, dom, ie, ie4, ie5x, moz, mac, win, old, ie5xmac, ie5xwin, op, awindow;

d=document;
n=navigator;
na=n.appVersion;
nua=n.userAgent;
win=(na.indexOf('Win')!=-1);
mac=(na.indexOf('Mac')!=-1);

if (!d.layers){
	dom=(d.getElementById);
	op=(nua.indexOf('Opera')!=-1);
	moz=(nua.indexOf('Gecko')!=-1);
	ie=(d.all&&!op);
	ie4=(ie&&!dom);
	/*ie5x tests only for functionality. (dom||ie5x) would be default settings. 
	Opera will register true in this test if set to identify as IE 5*/
	ie5x=(d.all&&dom);
	ie5xmac=(mac&&ie5x);
	ie5xwin=(win&&ie5x);
}

//puts in a spacer gif if d.layers.x
function spacer_gif(depth){
	if (d.layers) {
		document.write('<img src="'+depth+'images/site/blank.gif" alt="" class="blank" \/>');
	}
}
//day=Date.getDay();

//validates email form data
function isvalid() {
	
	//firstname=d.frmJoinlist.firstname;
	email=d.frmJoinlist.email;
	blankemail='Please Fill in your Email Address.\n';
	at='Email addresses must include the \' @ \' character.\n';
	period='Email addresses must include a Period.\n';
	message='The following information \nneeds to be completed:\n\n';
	var bUndone=true, bEmail=false;
	
	if (email.value==' ') {email.value='';}

	if (email.value=='') {
		message+=blankemail;
		bEmail=true;
		bUndone=false;
	}
	if (email.value!=''){
		if (email.value.indexOf('@')==-1){
			message+=at;
			bEmail=true;
			bUndone=false;
		}
		if (email.value.indexOf('.')==-1){
			message+=period;
			bEmail=true;
			bUndone=false;
		}
	}
	if (!bUndone){
		alert(message);
		if (bEmail)	email.focus();
		return false;
	}
}
//specific css for different browsers
function browser(depth) {
	if (d.layers) {
		d.write('<link rel="stylesheet" type="text\/css" href="'+depth+'css\/cw_custom_ns4.css" \/>');
	}
}

//basic pop up code, takes passed url from below
function pop_up(url){
	var sizex, sizey, features;

	if(url.indexOf('special_report.htm')!=-1){
		sizex = 750; sizey = 500; url = 'http://emotionaleating.com' + url;
	}
	features = 'top=15,left=35,scrollbars=yes,toolbar=no,menubar=no,status=no,resizable=yes,width='+sizex+',height='+sizey;
	awindow=window.open(url, "secondwindow",features);
	awindow.focus();
}

//writes this to page, so that page can use noscript feature to allow for no script popup
//this calls the pop_up function, using the passed variables to build the url and image strings
function write_pop_up(depth, url, image_1){
	url = depth + 'site\/' + url;
	url="'" + url + "'";

	if (image_1=='free_report.png'){
		d.write('<a href="javascript:pop_up(' + url + ');">');
		d.write('<img src="' + depth + 'images\/site\/' + image_1 + '" alt="Get a Free Report" class="welcome" \/>');
		d.write('<\/a>');
	}
	else if (image_1=='Free Report'){
		d.write('<a href=\"javascript:pop_up(' + url + ')\;\" class=\"leftnav-button\">' + image_1 + '<\/a>');
	}
	else {}
}

//scripts all email addresses on site so spiders can't read them unless they
//support javascripting
function no_spam(name, domain, css_class, subject, text) 
{
	if (text)// do this first to avoid putting query string into printname
	{
		printname = text;
	}
	else 
	{
		printname = name + '&#064;' + domain;
	}
	if (subject)
	{
		domain += '?subject=' + subject;
	}
	if (css_class)
	{
		css_class += ' class="' + css_class + '\"';
	}
	
	email = '<a href=\"mailto:' + name + '&#064;' + domain + '\"' + css_class + '\>' + printname + '<\/a>';
	document.write(email);
}