<!--
//TO SHOW TERMS AND CONDITIONS
function termspop(div,action) {
	if (action=='show') {
		document.getElementById(div).style.display = 'block';
	} else {	
		document.getElementById(div).style.display = 'none';
	}
}

//TO SHOW NEW CATEGORY OPTIONS
function newcatfield(index) {
	if (index==0) {
		termspop('newcat','show');
	} else {
		termspop('newcat','hide');
	}
}

// TO CHECK BASIC FORM COMPLPETION
//function to check each field
function checkfield(field,mand,mini,maxi,reg,type) {
	field=document.getElementById(field);
	if (mand || field.value != '') {
		if (field.length < mini || field.length > maxi || !reg.test(field.value))	{
			var message;
			if(type=='email') message='You must type a valid email address!';
			else if(type=='captcha') message='Please copy the captcha code exactly as it appears in the box!';
			else message='The '+field.id+' must be '+mini+'-'+maxi+' '+type+' characters!';
			alert(message);
			field.focus();
			return false;
		}	
	}
	return true;
}

//main function for whole form
function checkuserform() {
	//check username
	var reg = /^[A-Za-z0-9]{3,15}$/;
	if (!checkfield('user',true,3,15,reg,'alphanumeric')) return false;

	//check password
	var pass = document.getElementById('pass');
	var pass2 = document.getElementById('pass2');
	if (!checkfield('pass',true,3,15,reg,'alphanumeric')) return false;
	else if (pass.value != pass2.value)	{
		alert('The passwords entered do not match!');
		pass2.focus();
		return false;
	}

	//check email
	var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!checkfield('email',true,6,35,reg,'email')) return false;

	//check firstname
	var reg = /^[A-Za-z]{3,15}$/;
	if (!checkfield('firstname',false,3,25,reg,'alphabetic')) return false;

	//check lastname
	if (!checkfield('lastname',false,3,25,reg,'alphabetic')) return false;

	//check compinfo
	var reg = /^[A-Za-z0-9 ]{3,50}$/;
	if (!checkfield('compinfo',false,3,50,reg,'alphanumeric')) return false;

	//check telephone
	var reg = /^[0-9 ]{11,12}$/;
	if (!checkfield('tel',false,11,12,reg,'numeric')) return false;

	//check address
	var reg = /^[A-Za-z0-9\/, -]{5,50}$/;
	if (!checkfield('address1',false,5,50,reg,'alphanumeric')) return false;
	if (!checkfield('address2',false,5,50,reg,'alphanumeric')) return false;
	var reg = /^[A-Za-z0-9 ]{6,8}$/;
	if (!checkfield('postcode',false,6,8,reg,'alphanumeric')) return false;

	if (!document.getElementById('is18').checked) {
		alert('Sorry, but you must be at least 18 to join.');
		return false;
	}
	if (!document.getElementById('conditions').checked) {
		alert('Please read and agree to the terms and conditions before signing up.');
		return false;
	}	
	//check captcha
	var reg = /^[A-Za-z0-9]{4}$/;
	if (!checkfield('captcha_code',true,4,4,reg,'captcha')) return false;

	return true;
}

function showcat(id) {
	document.getElementById(id).style.display='block';
	document.getElementById('img'+id).src='images/minus.png';
	document.getElementById('img'+id).alt='Contract';
	document.getElementById('link'+id).href='javascript:hidecat("'+id+'");';
}

function hidecat(id) {
	document.getElementById(id).style.display='none';
	document.getElementById('img'+id).src='images/plus.png';
	document.getElementById('img'+id).alt='Expand';
	document.getElementById('link'+id).href='javascript:showcat("'+id+'");';
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}

//AJAX HTTP REQUEST FUNCTION
function ajaxFunction(ad) {
	var xmlHttp;
	try {  // Firefox, Opera 8.0+, Safari  
	  xmlHttp=new XMLHttpRequest();  }
	catch (e)
	  {  // Internet Explorer  
	  try
		{    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
	  catch (e)
		{    try
		  {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
		catch (e)
		  {    return false;      }    }  }
  var vpurl = "vp.php?ad="+ad+"&amp;session=";
  if (session!='na') vpurl=vpurl+session;
  xmlHttp.open("GET",vpurl,true);
  xmlHttp.send(null);  
  return true; 
}

//OPACITY FADE FUNCTION
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//BLEND FUNCTION
function blend(millisec) { 
	var pic='pic'+numads[addiv];
	var innerdiv='ad'+numads[addiv];
	addivid='adcont'+numads[addiv];
	previd='adcont'+prev;
	var prevprevid='adcont'+prevprev;
    try {   document.getElementById(prevprevid).style.display='none';  } catch (e) {} 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
	
	//alert('Existing: '+previd+'\r\n New: '+addivid+'\r\n Removing: '+prevprevid);
	
    //make image transparent 
    changeOpac(0, addivid); 
    //set the current ad
    document.getElementById(addivid).style.display='block'; 
    document.getElementById(addivid).style.zIndex=1; 
    //move old ad to back
    document.getElementById(previd).style.zIndex=0; 
    //document.getElementById(previd).style.display='none'; 
	var adheight=document.getElementById('content').offsetHeight-35;
	var adwidth=document.getElementById('content').offsetWidth-20;
	if (adheight<400) {
		document.getElementById('content').style.height = '400px';
		document.getElementById(addivid).style.height='365px';
	} else document.getElementById(addivid).style.height=adheight+'px';
	//document.getElementById(addiv).style.width=adwidth+'px';
	document.getElementById(innerdiv).style.width=adwidth+'px'
	if (document.getElementById(pic)!=null) {
		document.getElementById(pic).style.cssFloat=floaty;
		document.getElementById(pic).style.styleFloat=floaty;
		if (floaty=='left') floaty='right';
		else floaty='left';
	};
     
    //document.getElementById(prev).style.display='block'; 
	 
	prevprev=prev;
	prev=numads[addiv];

    //fade in image 
    for(var i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + addivid + "')",(timer * speed)); 
       timer++; 
    } 
} 

var adthis = 0;
var adlast;
var adsin = new Array();
var addiv
var addivid;
var previd;
var prevprev;
var playads;
var floaty = 'left';
var adorderno=1;
var adorder = new Array();

//called to change the advert
function changeads(tochange) {
	if (tochange) addiv=tochange;
	else {
		var j;
		adthis = adthis+1;
		var length = numads.length-1;
		if (adthis>length) { 
			adthis=1;
			for(j=1;j<=length;j++) {
				adsin[j] = 0;
			}
		}
		addiv=Math.floor((Math.random()*length)+1);
		//if (length>=10) 
		var loops;
		while ((adsin.join().indexOf(addiv)>=0||prev==numads[addiv])&&loops<20) { 
			addiv=Math.floor((Math.random()*length)+1); 
			loops+=1;
		}
		adsin[adthis]=addiv;
	}
	blend(1000);
	ajaxFunction(numads[addiv]);
	adorder[adorderno] = addiv;
	adorderno+=1;
}

function play() {
	playads=setInterval('changeads()', 4000);
	document.getElementById('playing').style.display='block';
	document.getElementById('paused').style.display='none';
}

function pause() {
	clearInterval(playads);
	document.getElementById('playing').style.display='none';
	document.getElementById('paused').style.display='block';
}

function rewind() {
	pause();
	adorderno=adorderno-2;
	changeads(adorder[adorderno]);
}

function fastforward() {
	pause();
	adorderno=adorderno+1;
	changeads(adorder[adorderno]);
}

var message="";
//-->
