//SETTING UP OUR POPUP2 for cities.   
//0 means disabled; 1 means enabled;   
var popup2Status = 0;  
//loading popup2 with jQuery magic!   
function loadPopup2(){  
//loads popup2 only if it is disabled  
  if(popup2Status==0){   
  $("#backgroundPopup").css({   "opacity": "0.7"  });  
  $("#backgroundPopup").fadeIn("slow");  
  $("#popup2Contact").fadeIn("slow"); 
  popup2Status = 1;  
  }   
}  
//disabling popup2 with jQuery magic!   
function disablePopup2(){  
//disables popup2 only if it is enabled 
  if(popup2Status==1){  
  $("#backgroundPopup").fadeOut("slow");  
  $("#popup2Contact").fadeOut("slow");  
  popup2Status = 0;  
  }  
}  
//centering popup2  
function centerPopup2(){  
//request data for centering   
var windowWidth = document.documentElement.clientWidth;   
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popup2Contact").height(); 
var popupWidth = $("#popup2Contact").width();   
//centering  
$("#popup2Contact").css({   "position": "absolute",   "top": windowHeight/2-popupHeight/2,   "left": windowWidth/2-popupWidth/2   });   //only need force for IE6    
$("#backgroundPopup").css({   "height": windowHeight   }); 
}  

function listcities(letter1,letter2){
$.ajax({      
	   type:'POST',      
	   //url: 'http://localhost/myProg/myinsurancemaster_latest/getvalues_ajax.php', 
	   url: 'http://www.myinsurancemaster.com/getvalues_ajax.php', 
	   dataType: 'html',       
	   data:'letter1='+letter1+'&letter2='+letter2,    
	   success: function(data){   
	   //alert(data);
	   $("#cities").html(data);          //Insert ajax response html into div with id 'cities'
	   $("#cities a.clickable2").click(function(event){        // here add the link click handler               
			 event.preventDefault();
		
			  //For text links
			  $("input#child2txt").val($(this).html());   //put the clicked link text in textbox.
			  $("input#city").val($(this).html());
			  $("span#area").html($(this).html());    //changing text 'Area' with selected city.
			  resetAutoSuggest();   //function defind in headerform.php refresh json request for new autosuggest values.
	          disablePopup2(); 
			});    
	   }});
}

$(document).ready(function(){   
//following code will be here   
//LOADING POPUP2   
//Click the button event!  
/*$("a").click(function(event){
	event.preventDefault();
   });*/

   $("a.clickable2").live("click", function(event){ //.live() use to make .click() work on dynamically replaced html 
  
	//$("a.clickable2").click(function(event){ 
	  
		  event.preventDefault();
		  
		  //For text links. //put the clicked link text in textbox.
		  $("input#child2txt").val($(this).html());   
		  $("input#city").val($(this).html());
	  
	  //Change 'alt' attribute of an image.
	  //   imgFldr = 'images/nameofthesubfolder/';
	  //	 $('#'+this.name).attr('src', imgFldr+this.value).attr('alt', 'newattribute');
	  
	  //For image links
	  var imghtml=$(this).html();
	  //alert(imghtml);
	  $("input#child2txt").val($(imghtml).attr('alt'));  
	  $("input#city").val($(imghtml).attr('alt'));
	  
	  resetAutoSuggest();  //function defind in headerform.php refresh json request for new autosuggest values.
	  
	  disablePopup2(); //closing popup2 on clicking link. 
  
  });
  
  
  $("#button2").click(function(){ 
							  
  //centering with css   
  centerPopup2();   
  //load popup2   
  loadPopup2(); 
}); 

//CLOSING POPUP2   
//Click the x event!  
$("#popup2ContactClose").click(function(){disablePopup2();   });  
//Click out event!  
$("#backgroundPopup").click(function(){   disablePopup2();   });  
//Press Escape event!  
$(document).keypress(function(e){   if(e.keyCode==27 && popup2Status==1){   disablePopup2();   }   });  
});  


