
//pop-up style
function menu_colours()
	{
	var a = document.getElementsByTagName("A")
	for (var b=0;b<a.length;b++)
		{
		if (a[b].id)
			{
			a[b].onclick = function(){num=this.id.replace(/m/,'');u=eval('document.getElementById("s'+num+'")');if(u.style.display=="block"){u.style.display="none";document.cookie="s"+num+"=hide"}else{u.style.display="block";document.cookie="s"+num+"=show"}}
			}
		}
	for (var b=0;b<20;b++)
		{
		if (get_cookie(b))
			{u=eval('document.getElementById("s'+b+'")');v=get_cookie("s"+b);if (v=="show"){u.style.display="block"}}
		}	
	}
	
//Get cookie routine by Shelley Powers 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function cats()
{
var c = document.getElementById("container").getElementsByTagName("DIV")
for (var d=0;d<c.length;d++)
	{
	if (c[d].className=="cat")
		{c[d].onclick=function(){num=this.id.replace(/c/,'');location.href='/stuff/sell_item.asp?cat='+num}}
	}
}

function check(a)
{
empty = false;
check1('dname','Name');check1('street_address','First Line of the Address');check1('town','Town');
check1('post_code','Post Code');email('demail');check1('yname','Your Name');check1('contact_number1','Contact Number');
email('yemail');check1('category','Advertising Category');check1('adtitle','Advertising Title')
check_words('ad');
if (a==null){check1('adprice','Item Price')}
if (empty == false){document.ad_form.submit()}
}

function booking()
{
empty = false;
book1('delegate','Delegate');
book1('school','Organisation');
book1('tel','Telephone');
email2('email');
if (empty == false){document.book.submit()}
}

function book1(fobj,msg)
{
obj=eval('document.book.'+fobj);
if((obj.value==""|| obj.value=="£")&& empty==false)
	{alert('The ' + msg + ' cannot be left blank');empty=true;obj.focus()}
}


function check1(fobj,msg)
{
obj=eval('document.ad_form.'+fobj);
if((obj.value==""|| obj.value=="£")&& empty==false)
	{alert('The ' + msg + ' cannot be left blank');empty=true;obj.focus()}
}

function check2(fobj,msg)
{
obj=eval('document.ad_form.'+fobj);
if(obj.value=="" && empty==false)
	{alert('The ' + msg + ' cannot be left blank. Insert a zero');empty=true;obj.focus()}
}

function check_words(fobj)
{
txt_str = eval('document.ad_form.'+fobj+'.value');
str_len	= txt_str.length;
var b	= 1;
for (var a=0;a<str_len;a++){if (txt_str.charAt(a)==' '){b++}}	
if (b>64){alert('Your advertisement contains '+b+' words. The maximum allowed is 64');empty=true;obj.focus()}
}

function email(fobj)
{
var obj=eval('document.ad_form.'+fobj);var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
if ((matchArray==null) && empty==false){alert("Email address seems incorrect (check @ and .'s)");empty=true;obj.focus()}
if (empty==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){alert("The username doesn't seem to be valid.");empty=true;obj.focus()}}
if (empty==false){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255){alert("Destination IP address is invalid!");empty=true;obj.focus()}}}}
if (empty==false){var domainArray=domain.match(domainPat);if (domainArray==null){alert("The domain name doesn't seem to be valid.");empty=true;obj.focus()}}
if (empty==false){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){alert("The address must end in a three-letter domain, or two letter country.");empty=true;obj.focus()}}
if ((len<2) && empty==false){alert("This address is missing a hostname!");empty=true;obj.focus()};
}

function email2(fobj)
{
var obj=eval('document.book.'+fobj);var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
if ((matchArray==null) && empty==false){alert("Email address seems incorrect (check @ and .'s)");empty=true;obj.focus()}
if (empty==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){alert("The username doesn't seem to be valid.");empty=true;obj.focus()}}
if (empty==false){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255){alert("Destination IP address is invalid!");empty=true;obj.focus()}}}}
if (empty==false){var domainArray=domain.match(domainPat);if (domainArray==null){alert("The domain name doesn't seem to be valid.");empty=true;obj.focus()}}
if (empty==false){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){alert("The address must end in a three-letter domain, or two letter country.");empty=true;obj.focus()}}
if ((len<2) && empty==false){alert("This address is missing a hostname!");empty=true;obj.focus()};
}

var processing = false;

function pc_check(a)
	{
	if (a==1)
		{
		if (processing)
			{alert("Checking Post Code.");return;}
		var post_code = document.ad_form.post_code.value;
		if (post_code == "")
			{alert("Please enter the post code.");return;}
		processing = true;
		document.ad_form.post_code.readOnly = true;
		document.getElementById("remote").src = "/stuff/post_code_checker.asp?pc=" + escape(post_code);
		}
	else if (a==2)
		{
		if (processing)
			{alert("Checking Promo Code.");return;}
		var promo_code = document.ad_form.promo_code.value;
		if (promo_code == "")
			{return;}
		processing = true;
		document.ad_form.promo_code.readOnly = true;
		document.getElementById("remote2").src = "/stuff/promo_code_checker.asp?pc=" + escape(promo_code);

		}
	return false;
	}
	
function callback(isResolved)
	{
	document.ad_form.post_code.readOnly = false;
	processing = false;
	if (isResolved==1)
		{document.getElementById("go").style.display=''}
	else 
		{alert("You have entered an invalid post code. You must be registered with KSD to place an advertisement");document.getElementById("go").style.display='none';document.ad_form.post_code.focus()}
	}

function callback2(isResolved)
	{
	document.ad_form.promo_code.readOnly = false;
	processing = false;
	if (isResolved==1)
		{alert("Promo Code Accepted. You will not be charged for this advertisement.");document.ad_form.zinv.value='0'}
	else 
		{alert("You have entered an invalid promotion code. Please try again");document.ad_form.promo_code.focus()}
	}
	
function ads()
	{
	for (a=1;a<=10;a++)
		{
		b=eval('document.getElementById("a'+a+'")')
		//run through child nodes of DIV
		if(b)
			{
			
			for (i=0;i<b.childNodes.length;i++) 
			{
			node = b.childNodes[i];
			if (node.nodeName=="H5"){c=node}
			else if(node.nodeName=="H3"){d=node}
			}
			
			if(b.offsetHeight>c.offsetHeight)
				{
				c.style.height=(b.offsetHeight-17)+"px"
				if (document.all)
					{
					d.style.height=(b.offsetHeight-92)+"px"
					}
				}
			else
				{
				b.style.height=(c.offsetHeight+20)+"px"
				}
			}
		}
	}
	
function stars()
	{
	var a = document.getElementById("adf")	
	for (b=0;b<a.childNodes.length;b++) 
		{
		node = a.childNodes[b];
		if (node.nodeName=="FIELDSET")
			{
			for (c=0;c<node.childNodes.length;c++)
				{
				node2 = node.childNodes[c];
				if (node2.nodeName=="LABEL")
					{
					node2.innerHTML=node2.innerHTML.replace(/\*/,'<span style="color:#f00">*</span>')
					}
				}
			}
		}
		
	var a = document.getElementById("red")
	a.innerHTML=a.innerHTML.replace(/\*/,'<span style="color:#f00">*</span>')	
	}
	
function do_search()
	{
	if (document.fsearch.tsearch.value.length>2){document.fsearch.submit()}else{alert('You must enter at least three characters')}
	}

menu_colours()