
var xmlHttp;
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}





function change_county(value)
{	
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
				//alert(xmlHttp.responseText);
				document.getElementById('county').innerHTML=xmlHttp.responseText;
		}
	}
	if (value!='')
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="county.php";
		url=url+"?state="+value;
		
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
} 


function get_banner_img(state,id)
{	

	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}

	function cloneInnerHTML(node, target) 
	{	
		if (target) 
		{
			newNode = target;
			target.innerHTML = '';
		} else {
			var newNode = node.cloneNode(false);
		}
	
		if (node.hasChildNodes()) 
		{
			var children = node.childNodes;
			for (var i = 0; i < children.length; i++) 
			{
				var child = children[i];
				if (child.tagName == 'script') {
					var newScript = document.createElement('script');
					newScript.setAttribute('type', 'text/javascript');
					newScript.setAttribute('id', child.getAttribute('id'));
					copyScriptText(child, newScript);
					newNode.appendChild(newScript);
				} 
				else 
				{
					newNode.appendChild(cloneInnerHTML(child, null));
				}
	
			}
		}
	
		return newNode;

	}

	
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4)
		{ 			//alert(trim(xmlHttp.responseText));
					//
					//alert('ayaz');
					//
				if (xmlHttp.responseText.lastIndexOf('/script')>0)
				{	
					// create Element Method
						/*
						tempdiv = document.createElement('span');
						tempdiv.innerHTML = xmlHttp.responseText; // new html fetched via an ajax call
						cloneInnerHTML(tempdiv, document.getElementById('banner_div'));
						*/
					//
					//
					//
					// ProtoType Method Code in Testing Process we can not do live
						//showContent('script');
					//
					//
					//
					// Page Refrash method
					//alert(document.URL+'fetch_banner');
					//alert(trim(xmlHttp.responseText));
					var id_string=trim(xmlHttp.responseText);
					//alert(id_string.slice(0,id_string.lastIndexOf('%%')));
					var responseID=id_string.slice(0,id_string.lastIndexOf('%%'));
					if (document.URL.lastIndexOf('PageNo')>0)
					{	var temp=document.URL.lastIndexOf('fetch_banner');
						if (temp>0)
						{
							//alert(document.URL.slice(0,temp+13));
							//alert(document.URL.slice(temp+14));
							window.location=document.URL.slice(0,temp+13)+responseID+document.URL.slice(temp+14);
						}
						else
						{
							window.location=document.URL+'&fetch_banner='+responseID;							
						}
					}
					else
					{
						var temp=document.URL.lastIndexOf('fetch_banner');
						if (temp>0)
						{
							//alert(document.URL.slice(0,temp+13));
							//alert(document.URL.slice(temp+14));
							window.location=document.URL.slice(0,temp+13)+responseID+document.URL.slice(temp+14);
						}
						else
						{
							window.location=document.URL+'?fetch_banner='+responseID;							
						}
					}
				}
				else
				{
					document.getElementById('banner_div').innerHTML="&nbsp;"+xmlHttp.responseText;
				}
		}
	}
	if (id!='')
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="get_banner_img.php";
		url=url+"?id="+id+"&"+state;
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
} 



//By this function Call prototye.js 
function showContent(obVal, page, ref){
	switch (obVal){
		case 'script':
			//var url = 'get_banner_img.php?catID='+ref+'&page='+page;
			var url = 'get_banner_img.php';
			//document.getElementById('banner_div').style.display = 'block';
			// notice the use of a proxy to circumvent the Same Origin Policy.
			new Ajax.Request(url, {
		  	method: 'get',
		  	onSuccess: function(transport) {
			alert(transport.responseText);
			var notice = $('banner_div');
			  if (notice.update(transport.responseText)){
				  //alert('ayaz');
				  //document.getElementById('banner_div').style.display = 'none';
			  };
			
		  }
		});
		break;
	}
}
