function pageScroll()
{
		window.scrollBy(-30, -30); 
		scrolldelay = setTimeout('pageScroll()',10);
		stopScroll();
}	

function stopScroll()
{
		myHeight = document.body.scrollTop;
		if(myHeight <= 0)
		{	
			clearTimeout(scrolldelay);
		}
}

function changeURL(url)
{
	var id = document.getElementById('searching');
	id.action = "index.php?"+url;
	id.submit();
}

function status_change(value, code)
{
	var id = document.getElementById('searching');

	if(value == "no")
	{
		document.getElementById('status').value = "yes";
	}
	else
	{
		document.getElementById('status').value = "no";
	}
	
	document.getElementById('code').value = code;
	id.submit();
}

function saveRecord(no)
{
	var id = document.getElementById('searching');

	document.getElementById('no').value = no;
	
	id.submit();
}

function deleteRecord(no)
{
	var r=confirm("Are you sure you want to delete this product?")
	if(r==true)
	{
		document.getElementById('no').value = no;
		document.getElementById('del').value = true;
		
		var id = document.getElementById('searching');
		id.submit();		
	}
}

function deleteClient(id, form)
{
	var r=confirm("Are you sure you want to delete this record?")
	if(r==true)
	{
		document.getElementById('id').value = id;
		document.getElementById('delete').value = true;
		
		var id = document.getElementById(form);
		id.submit();		
	}
}

function newWindow(path, name, height, width)
{
	parentWindow = window.open(path, name, "location=no, directories=no, menubar=no, toolbar=no, status=no, scrollbars=yes, resizable=yes, height="+height+", width="+width);
}

function validate_inputs(form_id, submit_name)
{
	var val = "";
	var item = "";
	var error = "";
	var	item_id = "";
	var elem = document.getElementById(form_id).elements;
	
	for(var i = 0; i < elem.length; i++)
	{
		var itm= elem[i].name;

		item = itm.toString();
		
		var item_val = elem[i].value;

		item_val = item_val.toString();
		
		if(item.search("-") > -1 && item_val == "")
		{	
			item_id += "required_"+item.substring(1);
			error += item_id;

			document.getElementById(item_id).innerHTML = "<span class='required'>"+document.getElementById(item_id).innerHTML+"</span>";
			//document.getElementById('notification').innerHTML = "<em>please fill in all the required fields!</em><br><br>";			
		}
		item_id = "";
	} 
		
	document.getElementById(submit_name).value = 'submit';

	var form = document.getElementById(form_id);

	if(error == "")
	{
		form.submit();
	}	
}

var image_count = 2;

function multiple_files(object)
{
	if(image_count < 5)
	{
		var ni = document.getElementById('image_content');
		
		var newdiv = document.createElement('div');
		
		newdiv.setAttribute('id',image_count);
		//newdiv.innerHTML = object.value+"&nbsp;&nbsp;/&nbsp;&nbsp;<a style='cursor:pointer' onclick=\"remove_file('"+image_count+"')\">delete</a>";
		newdiv.innerHTML = "<a style='cursor:pointer' onclick=\"remove_file('"+image_count+"')\">delete</a>&nbsp;&nbsp;/&nbsp;&nbsp;<input type='file' class='box' name='image"+image_count+"' accept='jpg' onchange=\"multiple_files(this)\"/>";
		ni.appendChild(newdiv);
		document.getElementById('image_path').value += object.value+", ";
		//document.getElementById('tmp_name').value += object.value+", ";
		
		image_count++;
	}
	else
	{
		alert('Only 4 image uploads are allowed!');
	}
}

function remove_file(id)
{
  var d = document.getElementById('image_content');
  var olddiv = document.getElementById(id);
  d.removeChild(olddiv);
}

function preload_images()
{
	images = new Array();
	images[0]="./images/logo.jpg";
	images[1]="./images/header.jpg";
	images[2]="./images/admin.jpg";
	images[3]="./images/contact.jpg";
	images[4]="./images/pre_auction.jpg";	
	images[5]="./images/stress_sale.jpg";	
	images[6]="./images/quick.jpg";
	images[7]="./images/renevate.jpg";
	images[8]="./images/residential.jpg";	
	images[9]="http://za.offerforge.com/42/6014/17929/";	
	images[10]="http://za.offerforge.com/42/6014/1616/";	
	images[11]="http://affiliates.trafficsynergy.com/42/8717/1040341/";	
	images[12]="http://affiliates.trafficsynergy.com/42/8717/1027261/";		
	
	for(i=0; i<=images.length; i++) 
	{
		img[i] = new Image();
		img[i].src=images[i];
	}
}

function change_image(id)
{
	tmp = id.src;
	id.src = document.getElementById('image_1').src;
	document.getElementById('image_1').src = tmp;
}

var xmlhttp;
var div_id;

function showContent(str, url, id)
{
	div_id = id;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	//var url="getcustomer.asp";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById(div_id).innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}



