// ajax browser code
function getHTTPObject()
{
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 highlight_refine_search_box(event_name)
{
 td1_ob_1 = document.getElementById("td1");
 td2_ob_1 = document.getElementById("td2");
 td3_ob_1 = document.getElementById("td3");

 if(event_name == "mouseover")
 {
 td1_ob_1.className="mediumblack";
 td2_ob_1.className="mediumblack";
 td3_ob_1.className="mediumblack";
 }
 else if(event_name == "mouseout")
 {
 td1_ob_1.className="refinelink";
 td2_ob_1.className="refinelink";
 td3_ob_1.className="refinelink";
 }
}

var js_img_path ="http://192.168.9.8/indiabestmatch";

 // get page size
 function getPageSize()
 {
 var xScroll, yScroll;
// alert(window.scrollMaxY);
 if (window.innerHeight && window.scrollMaxY)
 {
 //alert("hello1");
 xScroll = document.body.scrollWidth;
 yScroll = window.innerHeight + window.scrollMaxY;
 }
else if (document.body.scrollHeight > document.body.offsetHeight)
 {
 //alert("hello2");
 // all but Explorer Mac
 xScroll = document.body.scrollWidth;
 yScroll = document.body.scrollHeight;
// alert(yScroll);
 }
 else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight)
 {
	 //alert("hello3");
 // Explorer 6 strict mode
 xScroll = document.documentElement.scrollWidth;
 yScroll = document.documentElement.scrollHeight;
 }
 else
 {
	//alert("hello4");
// Explorer Mac...would also work in Mozilla and Safari
 xScroll = document.body.offsetWidth;
 yScroll = document.body.offsetHeight;
 }

 var windowWidth, windowHeight;
 if (self.innerHeight)
 {
	// alert("hello5");
 // all except Explorer
 windowWidth = self.innerWidth;
 windowHeight = self.innerHeight;
 }
 else if (document.documentElement && document.documentElement.clientHeight)
 {
	 //alert("hello6");
 // Explorer 6 Strict Mode
 windowWidth = document.documentElement.clientWidth;
 windowHeight = document.documentElement.clientHeight;
 }
 else if (document.body)
 {
	 //alert("hello7");
 // other Explorers
 windowWidth = document.body.clientWidth;
 windowHeight = document.body.clientHeight;
 }

 // for small pages with total height less then height of the viewport
 if(yScroll < windowHeight)
 {
	 //alert("hello8");
 pageHeight = windowHeight;
 }
 else
 {
	 //alert("hello9");
 pageHeight = yScroll;
 }

 // for small pages with total width less then width of the viewport
 if(xScroll < windowWidth)
 {
	//alert("hello10");
 pageWidth = windowWidth;
 }
else
 {
 //alert("hello11");
 pageWidth = xScroll;
 }
 
 //alert(pageHeight);
 //alert(windowHeight);

 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
 return arrayPageSize;
}

var http = new getHTTPObject();
var doc,doc_mt_ct,optionarray,stateobj,counter, selected_state_option_array,selected_country_option_array,event_name,event_name1,caste_mothertongue_option,mothertongue_caste_option,selected_mt_ct,filename;

function ShowSearchPartner(pg_search_id)
{
  
 var obj_image = document.getElementById('backimage');
 var objcontainer = document.getElementById('container');
 var arrayPageSize = getPageSize();
 // set height of BackImage to take up whole page and show
 obj_image.style.height = (arrayPageSize[1] + 'px');
 obj_image.style.display = 'block';
 

 /*#################### width and height of Middle Content ####################*/
var SearchWindowTop = 0 + ((arrayPageSize[3] - 600) / 2); //First Term will be 0 because the scrollTop of the browser is set to 0 and the arrayPageSize[3] is the windowHeight
var SearchWindowLeft = ((arrayPageSize[2] - 420) / 2); //arrayPageSize[0] is the windowHeight
alert(SearchWindowTop);
alert(SearchWindowLeft);
 objcontainer.style.top = (SearchWindowTop < 0) ? "0px" : SearchWindowTop + "px";
 objcontainer.style.left = (SearchWindowLeft < 0) ? "0px" : SearchWindowLeft + "px";
/* #################### end of width and height of Middle Content ##############*/

 objcontainer.style.width = 400 + 'px'; //Assign widht to the middle div as per requirement

 objcontainer.style.display = 'block';

 //to avoid vertical scroll in IE
 if(navigator.appVersion.indexOf("MSIE") != -1)
 {
 obj_image.style.height = (arrayPageSize[1] - 4 + 'px');
 }

 /*########################### Middle Content #################################*/
 //start bring middle content using ajax
 myurl = "refine_search.php";
 if(http)
 {
 //http.open("GET", myurl, true);
 myurl= myurl+"?pg_search_id="+pg_search_id;
 http.onreadystatechange = useHttpResponse;
 http.open("GET", myurl, true);
 http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 http.send(null);
 //http.send('pg_search_id ='+ pg_search_id );
 }
 else
 {
 alert("Your Browser dosen't support Ajax");
 HideSearchPartner();
 showSelectBoxes();
 }
//END bring middle content using ajax
/*############################ End of Middle Content #########################*/
 return false;
}

function useHttpResponse() //Ajax Handler for fetching HTML Forms
{
 var objcontainer = document.getElementById('container');
 if(http.readyState == 4 && http.status == 200)
 {
 result = http.responseText;
 objcontainer.innerHTML = result;
 }
else
 {
  // show loading still page load
 objcontainer.innerHTML = "<p align='center'><img src='" + js_img_path + "/images/loading.gif' border='0'/></p>";
 }
}

//only for IE hides all the Select Boxes on the Page
function hideSelectBoxes()
{
 var browsername = navigator.appName;
 if(browsername == "Microsoft Internet Explorer")
 {
 selects = document.getElementsByTagName("select");
 for (i = selects.length-1; i >= 0; i--)
 {
 if(selects[i].name == "url" || selects[i].name == "nearestcityarray[]" || selects[i].name == "sort_type")
 {
 selects[i].style.visibility = "hidden";
 }
 }
 }

 return false;
}

function LoadSearchPartner()
{
 var objBody = document.getElementsByTagName("body").item(0); //Assign the body object reference
 var arrayPageSize = getPageSize();
  var obj_image = document.createElement("div");
 obj_image.setAttribute('id','backimage');
 obj_image.style.display = 'none';
 obj_image.style.position = 'absolute';
 obj_image.style.top = '0';
 obj_image.style.left = '0';
 obj_image.style.zIndex = '90';
 if(navigator.userAgent.indexOf('MSIE') != -1)
 {
 obj_image.style.width = arrayPageSize[0];
 }
 else
 {
 obj_image.style.width = arrayPageSize[0] - 20;
 }
 objBody.insertBefore(obj_image, objBody.firstChild); //this will the root element i.e body

 // create SearchPartner div, same note about styles as above
 var objcontainer = document.createElement("div");
 objcontainer.setAttribute('id','container');
 objcontainer.style.display = 'none';
  objcontainer.style.position = 'absolute';
 objcontainer.style.zIndex = '100';
 objBody.insertBefore(objcontainer, obj_image.nextSibling); //this will the root element of the "backimage" div
}


function HideSearchPartner()
{
 // get the objects reference of the div getting used in the process
  obj_image = document.getElementById('backimage');
  objcontainer = document.getElementById('container');
 // hide SearchPartner and BackImage
 obj_image.style.display ='none';
 objcontainer.style.display ='none';
 // disable keypress listener
}

function Countrysearch(value)
  {
   xmlHttp=getHTTPObject();
   if(value!="101")
	  {
	     //document.loginsearchresult.selectcity.disabled =true;
		 document.getElementById("searchcity1").style.display="none";
	     document.getElementById("citysearch").disabled =true;
  	  }
   else
	  {
	   //document.loginsearchresult.selectcity.disabled =false;
	     document.getElementById("searchcity1").style.display="block";
	     document.getElementById("citysearch").disabled =false;
	  }
  if(xmlHttp)
	{
	 var url = 'searchstate.php';
	 url = url+'?country='+value;
	 url=url+"&sid="+Math.random();
	 xmlHttp.onreadystatechange=countryfunction;
	 xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
    }
}  
function countryfunction()
{     
	if (xmlHttp.readyState==4)
	{   
		document.getElementById("statesearch").innerHTML=xmlHttp.responseText;
	}
}

function citysearch(value)
{
    var boxLength=document.getElementById('stStatus').length;
	var selectedItem = document.getElementById('stStatus').selectedIndex;
	var selectedValue = document.getElementById('stStatus').options[selectedItem].value;
	if(boxLength!=0){
		k=0;
		for (i = 0; i < boxLength; i++) {  
			if(document.getElementById('stStatus').options[i].selected){
				if(k==0){
					thisitem = document.getElementById('stStatus').options[i].value;
				}
				else{
					thisitem=thisitem + "," + document.getElementById('stStatus').options[i].value;
				}
				document.getElementById('ajaxdelete').value=thisitem; 
				k++;
			}

		}
	}
   xmlHttp=getHTTPObject();
  if(xmlHttp)
	{
   xmlHttp.onreadystatechange=cityfunction;
      var url = "searchcity.php";
     url = url+'?state='+value;
    xmlHttp.open("GET",url,true);
   xmlHttp.send(null); 
    } 
}

function showSelectBoxes()
{
 var browsername = navigator.appName;
 if(browsername == "Microsoft Internet Explorer")
 {
 selects = document.getElementsByTagName("select");
 for (i = selects.length-1; i >= 0; i--)
 {
 if(selects[i].name == "url" || selects[i].name == "nearestcityarray[]" || selects[i].name == "sort_type")
 {
 selects[i].style.visibility = "visible";
 }
 }
 }
}



