//// JAVASCRIPT FILE ////
//// MOLE PRODUCTIONS MARCH 2005 ////


d=document;

function movepic(img_name,img_src) {
	d[img_name].src=img_src;
}

function printYear() {
	var startyear=2005;
	thedate=new Date();
	theyear=thedate.getFullYear();
	if (theyear == startyear) {
		d.write(theyear);
	}else{
		d.write(startyear+" - "+theyear);
	}
}

function checkForm() {
	if (d.f.sessionName) {
		var found_it;
		for (var i=0; i<d.f.sessionName.length; i++)  {
			if (d.f.sessionName[i].checked)  {
				found_it = d.f.sessionName[i].value //set found_it equal to checked button's value
			} 
		}
		if(found_it == null){ //if found_it is NOT equal to null, a button HAS been checked
			alert("Please choose a session topic that you are likely to be attending");
			return false;
		}
	}
	if (d.f.address_type) {
		var found_it2;
		for (var i=0; i<d.f.address_type.length; i++)  { 
			if (d.f.address_type[i].checked)  {
				found_it2 = d.f.address_type[i].value //set found_it equal to checked button's value
			} 
		}
		if(found_it2 == null){ //if found_it is NOT equal to null, a button HAS been checked
			alert("Please state whether this is your home or work address.");
			return false;
		}
	}
	var theFields=d.f.fields.value;
	data=theFields.split(",");
	for (i=0; i< data.length; i++) {
		field=data[i].split("|");
		if (d.f[field[0]].value == "") {
			alert("Please enter your "+field[1]+" before proceeding.");
			d.f[field[0]].select();
			d.f[field[0]].focus();
			return false;
		}
	}
	return true;
}



function checkLoginForm() {
	d.f.submit.disabled=true;
	if (d.f.email.value.length < 3) {
		alert("Please enter a email address to continue");
		d.f.email.select();
		d.f.email.focus();
		d.f.submit.disabled=false;
		return false;
	}
	if (d.f.password.value == "") {
		alert("Please enter a password to continue");
		d.f.password.select();
		d.f.password.focus();
		d.f.submit.disabled=false;
		return false;
	}
	return true;
}


function goHome() {
	if (opener) {
		window.close();
		opener.focus();
	} else {
		document.location.href="http://www.woundsuk.co.uk";
	}
}
		

// FUNCTION TO GET A COOKIE.
function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
    if (dc.length > 0) {              
	    begin = dc.indexOf(cname);       
        if (begin != -1) {           
	        begin += cname.length;       
	        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
	return null;
}


// FUNCTION TO SET A COOKIE //
function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) + "; path=/" +
	((expires == null) ? "" : "; expires=" + expires);
}

// SET THE EXPIRY DATE (millisecs * secs * mins * hours * days * months)//
var exp = new Date();
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31 * 3)); // 3 months


// PRINT LOGGED IN AND BASKET LINK AT TOP RIGHT OF PAGE CONTENT //
function printLoggedIn() {
	var	 loginName=getCookie('loginname');
	if (loginName != "" && loginName != null && loginName != "null" && loginName != "undefined"){
		document.writeln('<div align="right"><p><span class="loggedin"><b>Logged in as: '+loginName+' | <a href="http://www.wounds-uk.com/cgi-bin/club_logout.cgi">Logout</a></b>');
	}else{
		var loginName="";
	}


	// CHECK TO SEE IF THE BASKET IS EMPTY //
	var basket=getCookie('TheBasket');
	if (basket == "" || basket == null || basket == "null" || basket == "undefined") {
		var basket="";
	}else if (basket.length <= 1) { //>
		// nothing //
	}else{
		if (loginName == "") {
			document.writeln('<div align="right"><p><span class="loggedin"><b><a href="/basket.shtml">View basket</a></b>');
		}else{
			document.writeln(' | <a href="/basket.shtml">View basket</a>');
		}
	}

	document.writeln('</b></span></div>');

}



function ifLoggedIn(yesUrl,noUrl) {
	var	 loginName=getCookie('loginname');
	if (loginName != "" && loginName != null && loginName != "null" && loginName != "undefined"){
		if (yesUrl != "") {
			d.location.href=yesUrl;
		}
	}else{
		if (noUrl != "") {
			d.location.href=noUrl;
		}
	}
//	alert("yesUrl="+yesUrl+"\nnoUrl="+noUrl);
}



// POP-UP WINDOW //
function popup(url,winx,winy,scrollbaryn) {
	newwin=window.open(url, "popup", "width="+winx+",height="+winy+",toolbar=0,status=0,"+scrollbaryn);
	//e.g. <a href="javascript:popup('me.html','300','100','scrollbars');">Open with scroll</a> //
	//e.g. <a href="javascript:popup('me.html','300','100','');">Open without scroll</a> //
}

// CONVERT //

function str_to_num(val) {
	var str_in;
	var str_out = ""; 
	var num_in;
	var num_out = "";
	num_out = "";
	str_in = escape(val);
	for(i = 0; i < str_in.length; i++) {
		num_out += str_in.charCodeAt(i) - 23;
	}
	return num_out;
}

function num_to_str(val) {
	var str_in;
	var str_out = ""; 
	var num_in;
	var num_out = "";
	str_out = "";
	num_out = val;  
	for(i = 0; i < num_out.length; i += 2) {
		num_in = parseInt(num_out.substr(i,[2])) + 23;
		num_in = unescape('%' + num_in.toString(16));
		str_out += num_in;
	}
	return(unescape(str_out));
}


function insertHomePageBanner(bannerName, url) {
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {  // if we've detected an acceptable version
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
				'width', '468',
				'height', '60',
				'src', bannerName,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', bannerName,
				'bgcolor', '#ffffff',
				'name', bannerName,
				'menu', 'false',
				'allowFullScreen', 'false',
				'allowScriptAccess','sameDomain',
				'movie', '/flash/'+bannerName,
				'salign', ''
			); //end AC code
		} else {  // flash is too old or we can't detect the plugin
			var alternateContent = "<a href='"+url+"' target='_blank'><img src='flash/alternative-non-flash/"+bannerName+".gif' border='0'></a>";
			document.write(alternateContent);  // insert non-flash content
		}
	}
}

function insertHomePageBannerSkyScraper(bannerName,url) {
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {  // if we've detected an acceptable version
			AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '161',
			'height', '600',
			'src', bannerName,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', bannerName,
			'bgcolor', '#ffffff',
			'name', bannerName,
			'menu', 'false',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', '/flash/'+bannerName,
			'salign', ''
			); //end AC code
		} else {  // flash is too old or we can't detect the plugin
			var alternateContent = "<a href='"+url+"' target='_blank'><img src='flash/alternative-non-flash/"+bannerName+".gif' border='0'></a>";
			document.write(alternateContent);  // insert non-flash content
		}
	}
}
