//Value vanishes from text box

function inputOnFocus(element, name)
{
	
	if(element.value == name)
	{
		element.value='';
		
	}
}


function saveScrollCoordinates(element, action) 
{ 
	

  element.scrollx.value = (document.all)?document.body.scrollLeft:window.pageXOffset; 

  element.scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset; 
  
  if(action != 0)
  {

	element.action = action;

  }

} 

//Value re-appears in text box

function inputOnBlur(element, name)
{
	if(element.value=='')
	{
		element.value = name;
	}	
}


function new_window(url, name, w, h, features) 
{
  	if(screen.width)
  	{
		var winl = (screen.width-w)/2;
  		
  		var wint = (screen.height-h)/2;
  	}
  	else
  	{
  		winl = 0;
  		wint =0;
  	}
  	
  	if(winl < 0) 
  		winl = 0;
  	
  	if(wint < 0) 
  		wint = 0;
  	
  	var settings = 'height=' + h + ',';
  	
  	settings += 'width=' + w + ',';
  	
  	settings += 'top=' + wint + ',';
  	
  	settings += 'left=' + winl + ',';
  	
/*  	settings += "titlebar=no,";
  	settings += "status=no,";
  	settings += "location=no,";
  	settings += "menubar=no,";;
  */	
  	settings += features;
  	
  	win = window.open(url, name, settings);
  	
   	win.resizeTo(w,h);
  	
  	win.window.focus();
  	
  	
}


   

function on_over(td_name)
{

	td_name.setAttribute('bgcolor', '#ffffff', 0); //E6E6FA //cc9933 //770000
			
}
			
function on_out(td_name)
{
			
	td_name.setAttribute('bgcolor', '#ffffff', 0);
			
}



/////AJAX///////


var http_request = false;
  

function getEntities(s)
{
    
  var rval = "";
  
  for(i = 0; i < s.length; i++)
  {      
  	
  		var character=s.charCodeAt(i);
        
  		rval += "&#" + character + ";";
  
  } 
  
  return rval;
  
}



function geData(enterJobTitle, advertiser, telnumber, contact, location, country, website,  email, sector, contactMessage, postAdSave, ad_id) 
{
					
		document.getElementById('status').style.color = '#555555';

		document.getElementById('status').innerHTML = 'Saving...'; 
			
		enterJobTitle = getEntities(enterJobTitle);
	
		advertiser = getEntities(advertiser);
	
		telnumber = getEntities(telnumber);
		
		contact = getEntities(contact);
		
		location = getEntities(location);
		
		country = getEntities(country);
		
		contactMessage = getEntities(contactMessage);
		
		
		var poststr = "enterJobTitle=" + encodeURIComponent( enterJobTitle ) + "&advertiser=" + encodeURIComponent( advertiser ) + "&telnumber=" + encodeURIComponent( telnumber) + "&contact=" + encodeURIComponent( contact)  + "&location=" + encodeURIComponent( location)  + "&country=" + encodeURIComponent( country) + "&website=" + encodeURIComponent( website) + "&email=" + encodeURIComponent( email) + "&sector=" + encodeURIComponent( sector)  + "&contactMessage=" + encodeURIComponent( contactMessage) + "&postAdSave=" + encodeURIComponent( postAdSave)+  "&ad_id=" + encodeURIComponent( ad_id) ;

		makePOSTRequest('/html/saveAd.php', poststr);
		
		setTimeout('loadURL()', 1000);
	
				
}

function makePOSTRequest(url, parameters) 
{

		http_request = false;

		if (window.XMLHttpRequest) 
		{ 
			
			// Mozilla, Safari,...
	
			http_request = new XMLHttpRequest();
	
			if (http_request.overrideMimeType) 
			{
	 	
				// set type accordingly to anticipated content type
	    
		 	//http_request.overrideMimeType('text/xml');

		    http_request.overrideMimeType('text/html');
	 	}
	 	
	} 
	else if (window.ActiveXObject) 
	{ // IE
     
		try 
		{

			http_request = new ActiveXObject("Msxml2.XMLHTTP");
     	} 
     	catch (e) 
     	{
        	try 
        	{
           
        		http_request = new ActiveXObject("Microsoft.XMLHTTP");
        	
        	} 
        	catch (e) {}
     }
  }

	if (!http_request) 
	{

		alert('Cannot create XMLHTTP instance');

		return false;

	}

	http_request.onreadystatechange = alertContents;

	http_request.open('POST', url, true);
	
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	http_request.setRequestHeader("Content-length", parameters.length);
	
	http_request.setRequestHeader("Connection", "close");
	
	http_request.send(parameters);

}

function alertContents() 
{

	if (http_request.readyState == 4) 
	{

		if (http_request.status == 200) 
		{

			//alert(http_request.responseText);

			result = http_request.responseText;

			document.getElementById('error').innerHTML = result;
			
			if(document.getElementById('error').innerHTML == "")
			{

				document.getElementById('status').innerHTML = 'Done!';
				           
			}
			else
			{
			
				document.getElementById('status').innerHTML = '';
			
			}
				
			document.getElementById('status').style.color = '#339900';
			
			
		} 
		else 
		{

			//alert('There was a problem with the request.');
	
		}
	}
} 

function loadURL()
{
	var xmlhttp;

	if (window.XMLHttpRequest)
	{

		// code for IE7+, Firefox, Chrome, Opera, Safari

		xmlhttp=new XMLHttpRequest();
	  
	}
	else if (window.ActiveXObject)
	{
	  
		// code for IE6, IE5
	  
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	  
		alert("Your browser does not support XMLHTTP!");
	
	}
	xmlhttp.onreadystatechange=function()
	{
		
		if(xmlhttp.readyState==4)
		{
	    
		  	//document.getElementById("error").innerHTML = xmlhttp.responseText;
		  	
	  	}
	}
	
	xmlhttp.open("GET","/html/saveAd.php",true);
	
	xmlhttp.send(null);
	
}

