// Pepperells JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function init() {
	theObjects = document.getElementsByTagName("object"); 
	for (var i = 0; i < theObjects.length; i++) { 
		theObjects[i].outerHTML = theObjects[i].outerHTML; 
	}
}

function changeText(ele, text) {
	
	if(ele == "address"){
	
		if(text == "Please include your postcode."){
			
			document.getElementById(ele).value = "";
			
		}else{
			
			if(text == ""){
			
				document.getElementById(ele).value = "Please include your postcode.";
			
			}
			
		}
	
	}
	
	if(ele == "enquiry"){
		
		if(text == "Please be concise but give enough detail for us to respond."){
			
			document.getElementById(ele).value = "";
			
		}else{
			
			if(text == ""){
			
				document.getElementById(ele).value = "Please be concise but give enough detail for us to respond.";
			
			}
			
		}
		
	}
	
}

window.onload = function() {
	
	init();	
	
}

function displaySupport(option){

	var option;
	
	if(option == "hide"){
		
		opacity('support_holder', 50, 0, 500); 
		opacity('support', 100, 0, 500);
		
	}else{ 
	
		if(option == "quick"){
			
			opacity('support_holder', 0, 50, 0); 
			opacity('support', 0, 100, 0);
			
		}else{
			
			opacity('support_holder', 0, 50, 500); 
			opacity('support', 0, 100, 500);
			
		}
		
	}

}

var loadtimer = "";
var scrolltimer = "";

function url(url, containerid){

  var page_request = false
	
	if(window.XMLHttpRequest){
	
		page_request = new XMLHttpRequest();
	
	}else if(window.ActiveXObject){
	
		try {
		
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
			
		} 
		
		catch (e){
		
			try{
			
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
				
			}
			
			catch (e){}
	
		}
		
	}else{
	
		return false
		
	}

	page_request.onreadystatechange=function(){
	
		urlDone(page_request, containerid);
	
	}
	
	page_request.open('GET', url, true);
	page_request.send(null);
}  

function urlDone(page_request, containerid){
	
  if(page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	
		document.getElementById(containerid).innerHTML=page_request.responseText;
	
	}
	
}

function load(name, div) {
	url(name, div);
	return false;
}


function toBottom(id){

	document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight

} 

function stop_Int(){

    if(scrolltimer!=""){

		window.clearInterval(scrolltimer);
		window.clearInterval(loadtimer);
		  
	}

}

function start_Int(){        
	
    scrolltimer = window.setInterval('toBottom(\'support_window_message\');', 100);
	loadtimer = window.setInterval('load(\'../support/support_user.php\',\'support_window_message\');', 100); 
	

}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function changeOpac(opac, id){

	document.getElementById(id).style.filter = 'alpha(opacity=' + opac + ')';	
	opac = opac / 100;	
	document.getElementById(id).style.opacity = opac;
	
}

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

	if(millisec == 0){
		
		setTimeout("document.getElementById('" + id +"').style.display = 'block';", millisec);
		setTimeout("changeOpac(" + opacEnd + ",'" + id + "')", millisec);
		
	}else{
	
		if(opacStart > opacEnd){
			
			for(i = opacStart; i >= opacEnd; i--) {
				
				if(i == opacStart){
				
					setTimeout("document.getElementById('" + id +"').style.display = 'block';", (timer * speed));
				
				}
				
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				
				if(i == opacEnd && opacEnd == 0){
					
					setTimeout("document.getElementById('" + id +"').style.display = 'none';", (timer * speed));
					
				}
				
				timer++;
				
			}
			
		}else if(opacStart < opacEnd){
			
			for(i = opacStart; i <= opacEnd; i++){
				
				if(i == opacStart){
				
					setTimeout("document.getElementById('" + id +"').style.display = 'block';", (timer * speed));
					
				}
				
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
				
			}
			
		}
	
	}
	
}

function checkKey(evt){
	
	var charCode = (evt.which) ? evt.which : window.event.keyCode;

	if (charCode == 13){
		
		return true;
	
	}else{
		
		return false;		
		
	}

}

function selectOver(id){
	
	document.getElementById(id).style.border = '#4E080B solid 1px';
	document.getElementById(id).style.background = '#EFEFEF';
	
}

function selectOut(id){

	document.getElementById(id).style.border = '#999999 solid 1px';
	document.getElementById(id).style.background = '#FFFFFF';

}

function timedRefresh(timeoutPeriod) {
	
	setTimeout("location.reload(true);",timeoutPeriod);
	
}

var newshold = "news2";

function newsMover(){

	document.getElementById("news1").style.display = "none";
	document.getElementById("news2").style.display = "none";
	document.getElementById("news1").style.top = "-33px";
	document.getElementById("news2").style.top = "-33px";

	mover();
	setInterval("mover();", 9600);

}

function mover(){

	var counter = 100;

	for(i=(33-66); i<=33; i++){
		
		if(i==(33-66)){
			setTimeout("document.getElementById('" + newshold + "').style.display = 'block';", counter);
		}
		
		if(i==33){
			setTimeout("document.getElementById('" + newshold + "').style.display = 'none';", counter);
		}
		
		holder = "" + i + "px";
		
		if(i==8){
			
			counter += 3000;
			
			setTimeout("document.getElementById('" + newshold + "').style.top = '" + holder + "';", counter);

		}else{
			
			setTimeout("document.getElementById('" + newshold + "').style.top = '" + holder + "';", counter);	
			
		}
		
		counter += 100;
		
	}
	
	if(newshold == "news1"){
		newshold = "news2";	
	}else{
		newshold = "news1";		
	}

}
