
function pager_submit(v,prefix){
	var obj=document.getElementById(prefix+'_pagestart');
	if (obj) {
		obj.value = v;
		document.forms['pagingform'].submit();
	}else{
		alert("For paged listings you must have a form with some hidden variables, pagestart, sortby, sortdes etc\\nEither include one given here or make your own");
	}
}


function swap_pic(contianer,num){	
	//alert('swap pic = '+nm);
	var c = document.getElementById(contianer);
	if (c){
		var divs = c.getElementsByTagName('div');

		if (divs){
			for (var x=0;x<divs.length ;x++ ){
				divs[x].style.display = (x==num)?"block":"none";
			}
		}else{
			alert ("divs not found inside the div named '"+contianer+"'")
		}	
	}else{
		alert ("div '"+contianer+"' not found")
	}

}

function contact(model){
	if (model != null){
		location.href = "/dyn/_pages/dynamic_contact.shtml?state=new&model="+escape(model);
	}
}

function contact_dev(model){
	if (model != null){
		location.href = "/dyn/_pages/developments_contact.shtml?state=new&model="+escape(model);
	}
}

function more_details(path){
	if (path != null){
		location.href = path;
	}
}

function arrayrandomise(arr,n){
// Will randomise a single dimension array,of integers or strings.
	var l=arr.length;
	if (n!=null){
		for (w=0;w<n;w++)arr[w]=w;
		l=n;
	}
	//alert("Lenght of array "+l);
	for (var w=0; w<l;w++){

		var r = parseInt(Math.random()*l);
		var t = arr[r];
		arr[r]=arr[w];
		arr[w]=t ;
	}
	//for (w=0; w<l;w++){

	//	alert(arr[w]);
	//}
}

// Select 3 random adds
function rand_small_ads(){
	var w=0;
	while (document.getElementById("smallad_"+w)){
		w++;
	}
	var arr=new Array();
	arrayrandomise(arr,w);
	var s="";
	var t=(w>3)?3:w;
	for (var w=0; w<t;w++){
		s+=document.getElementById("smallad_"+arr[w]).innerHTML;
	}
	document.getElementById("smallads").innerHTML=s;
}

// Use list item 0 then select 2 random adds from rest of list (used on slmvauxhall)
function rand_small_ads2(){
	var w=0;
	while (document.getElementById("smallad_"+w)){
		w++;
	}
	var arr=new Array();
	arrayrandomise(arr,w);
	var s="";
	var t=(w>3)?3:w;

	for (var x=0; x<w;x++){
		if(arr[x]==0){
			arr[x] = arr[0];
			arr[0] = 0;
			break;
		}
	}

	for (var x=0; x<t;x++){
		s+=document.getElementById("smallad_"+arr[x]).innerHTML;
	}
	document.getElementById("smallads").innerHTML=s;
}

function copyToField(sourcefield,destfieldname){
	//alert(sourcefield+" <=> "+destfieldname);
	var sourceObj = document.getElementById(sourcefield);
	var destObj = document.getElementById(destfieldname);
	if(destObj && sourceObj){
		destObj.value = sourceObj.value;
	}
}

function show_or_hide_other(value,othervalue,element){
	if(value == othervalue){
		show_elements(element);
	}else{
		hide_elements(element);
	}
}

function show_elements(ids){
	var elements = ids.split(',');
	for(var x=0;x<elements.length;x++){
		var obj = document.getElementById(elements[x]);
		if(obj) obj.style.display = 'block';
	}
}

function hide_elements(ids){
	var elements = ids.split(',');
	for(var x=0;x<elements.length;x++){
		var obj = document.getElementById(elements[x]);
		if(obj) obj.style.display = 'none';
	}
}

function togglePanels(ids){
	var elements = ids.split(',');
	for(var x=0;x<elements.length;x++){
		var obj = document.getElementById(elements[x]);
		if(obj) obj.style.display = (obj.style.display == 'none')?'block':'none';
	}
}

function bounce_secure(){
	var href = location.href;
	if(href.search('https://') == -1){
		//location.href = href.replace('http://','https://');
	}
}

function popup_control(url,type,title,width,height){
	//alert("URL: "+url+"  Window Type: "+windowtype);
	if(url != 0 && url != '' && location.href != url){
		if(type == 'gallery'){
			OpenWindow(new Array(0,url,title,width,height,0,1,0,0,0,0,0));
		}
	}
}

function OpenWindow(action) {
	//alert(action[1]);
	var wf = "";
	wf = wf + "top=10,left=10";
	wf = wf + ",width=" + action[3];
	wf = wf + ",height=" + action[4];
	wf = wf + ",resizable=" + (action[5] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");
	wf = wf + ",menubar=" + (action[7] ? "yes" : "no");
	wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");
	wf = wf + ",directories=" + (action[9] ? "yes" : "no");
	wf = wf + ",destination=" + (action[10] ? "yes" : "no");
	wf = wf + ",status=" + (action[11] ? "yes" : "no");
	return window.open(action[1],action[2],wf);
}