var win=null;


function changeregion(){ 
var changeregion=document.getElementById('changeregion').value;

// window.loaction='/index-a.php?action=loadregion&region_id='+changeregion+'';

document.getElementById('changingregion').innerHTML='CHANGING PLEASE HOLD';

 setTimeout("window.location = '/index-a.php?action=loadregion&region_id="+changeregion+"'",1500);
// alert(changeregion);

}

function publicreview(){
var pub_name=document.getElementById('pub_name').value;
var pub_email=document.getElementById('pub_email').value;
var babheads=document.getElementById('babheads').value;
var pub_review=document.getElementById('pub_review').value;
var loc_id=document.getElementById('loc_id').value;


 
	if(pub_name==""){
    alert( "Your Name Is Required!" );		
	document.getElementById('pub_name').focus();
	return false;	
	}
	
	if(pub_email==""){
    alert( "Your Email Is Required!" );		
	document.getElementById('pub_email').focus();
	return false;	
	}	
	
 	if(babheads=="0"){
    alert( "Please Select BAB Heads" );		
	document.getElementById('babheads').focus();
	return false;	
	}	
    if(pub_review==""){
    alert( "Please Type a Review" );		
	document.getElementById('pub_review').focus();
	return false;	
	}	
	
 
 
 ajaxpage('/indexb.php?action=publicreview&loc_id='+loc_id+'&pub_review='+pub_review+'&babheads='+babheads+'&pub_email='+pub_email+'&pub_name='+pub_name+'','sendpublic');	
 alert('YOUR PUBLIC REVIEW HAS BEEN SENT TO BAB! ONCE APPROVED IT WILL BE LISTED HERE');
 setTimeout("window.location = '/indexb.php?action=view&loc_id="+loc_id+"&sentok=1'",1500);
 
}


function sendfriend(){
var email1=document.getElementById('email1').value;
var s1=document.getElementById('s1').value;	
var email2=document.getElementById('email2').value;	
var s2=document.getElementById('s2').value;	
var m1=document.getElementById('m1').value;	
var loc_review_id=document.getElementById('loc_review_id').value;	
 
	if(email1==""){
    alert( "Your Email is Reqeuired!" );		
	document.getElementById('email1').focus();
	return false;	
	}
	
	if(s1==""){
    alert( "Your Name is Reqeuired!" );		
	document.getElementById('email1').focus();
	return false;	
	}	
	
	if(s2==""){
    alert( "Your Friends Name is Reqeuired!" );		
	document.getElementById('s2').focus();
	return false;	
	}	
	if(email2==""){
    alert( "Your Friend Email is Reqeuired!" );		
	document.getElementById('email2').focus();
	return false;	
	}

 
 ajaxpage('/inc/mods/sendafriend.php?action=done&email1='+email1+'&email2='+email2+'&s1='+s1+'&s2='+s2+'&m1='+m1+'&loc_review_id='+loc_review_id+'','morereviews');	
 
}


function loc_addit(loc_id,sublet){
	
	ajaxpage('/admin/indexb.php?action=locaddit&loc_id='+loc_id+'&sublet='+sublet+'',''+sublet+'_'+loc_id+'');	
	
}
function slocs(){
	var city=document.getElementById('city').value	
	var state=document.getElementById('state').value	
	var zipcode=document.getElementById('zipcode').value
	
 	
	
 if((city=="") && (state=="")){
	if(zipcode==""){
    alert('You must enter at least a ZIPCODE');	
	document.getElementById('zipcode').focus();
	return false;
	} 
	

}


ajaxpage('/indexb.php?action=ldgzips','ldgzips');
ajaxpage('/indexb.php?action=loading','searchgo');	

	if(zipcode!=""){
ajaxpage('/indexb.php?action=seturzip&yourzip='+zipcode+'','ai');	

	} 
	
var list="";
if(document.getElementById('searchq')){
	
var list="&loadstrap=1";

if(document.getElementById('searchq')){
var sq=document.getElementById('searchq').value	
	if(sq!=""){
	 list +="&sq="+sq+"";
	}
}


if(document.getElementById('bootstrap')){
var bootstrap=document.getElementById('bootstrap').value
list +="&bootstrap="+bootstrap+"";
}

if(document.getElementById('loc_type')){
var loc_type=document.getElementById('loc_type').value
list +="&loc_type="+loc_type+"";
}
if(document.getElementById('calone')){
	
var calone=document.getElementById('calone').value
	if(calone!=""){
list +="&calone="+calone+"";
	}
}
if(document.getElementById('caltwo')){
var caltwo=document.getElementById('caltwo').value
if(caltwo!=""){
list +="&caltwo="+caltwo+"";
}
}
 
//var wcouponsyes=document.getElementById('wcouponsyes').value
//var wpriceyes=document.getElementById('wpriceyes').value

var wcouponsyes = 0;
for( i = 0; i < document.searchform.wcouponsyes.length; i++ ){

	if( document.searchform.wcouponsyes[i].checked == true ){
	wcouponsyes = document.searchform.wcouponsyes[i].value;
list +="&wcouponsyes="+wcouponsyes+"";
	}

} 

var wpriceyes = 0;
for( i = 0; i < document.searchform.wpriceyes.length; i++ ){

	if( document.searchform.wpriceyes[i].checked == true ){
	wpriceyes = document.searchform.wpriceyes[i].value;
	list +="&wpriceyes="+wpriceyes+"";
	}
	
} 


if(document.searchform.loc_add){
var wcouponsyes = 0;
var listv ="";
for( i = 0; i < document.searchform.loc_add.length; i++ ){

	if( document.searchform.loc_add[i].checked == true ){
	wcouponsyes = document.searchform.loc_add[i].value;
listv +=""+wcouponsyes+",";
	}

} 
list +="&addv="+listv+"";
}

// alert(list);

}




if(!document.getElementById('radius')){
	var radius='20';
}else{
    var radius=document.getElementById('radius').value;	
}


ajaxpage('/inc/mods/reviews.php?action=search&city='+city+'&state='+state+'&zipcode='+zipcode+''+list+'&radius='+radius+'','maincontent');	

ajaxpage('/inc/mods/sortby.php?action=search&city='+city+'&state='+state+'&zipcode='+zipcode+''+list+'&radius='+radius+'','sortnav');	


setTimeout("ajaxpage('/indexb.php?action=loadsearchgo','searchgo')",1000);
}
function showblock(block,loc_st){
	
 
 if(loc_st=="1"){
	document.getElementById(''+block+'').style.display='block';
 }else{
	 document.getElementById(''+block+'').style.display='none';
 }

}
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

function addusercred(){
var cas_user=document.getElementById('cas_user').value	
var cas_pass=document.getElementById('cas_pass').value	
var cas_id=document.getElementById('cas_id').value

	if(cas_user==""){
    alert( "Please enter User Name!" );		
	document.getElementById('cas_user').focus();
	return false;	
	}
	
	if(cas_pass==""){
    alert( "Please enter A Password!" );		
	document.getElementById('cas_pass').focus();
	return false;	
	}

ajaxpage('/inc/mods/adduser.php?action=addusercred&cas_user='+cas_user+'&cas_pass='+cas_pass+'&cas_id='+cas_id+'','maincontent');	
		
	
}
function checkuser(){
var cas_user=document.getElementById('cas_user').value	
ajaxpage('/inc/mods/adduser.php?action=checkuser&cas_user='+cas_user+'','isuser');	
	
}

function addloc(){
var cas_name=document.getElementById('loc_name').value;	
var cas_address=document.getElementById('loc_add1').value;	
var cas_address2=document.getElementById('loc_add2').value;	
var cas_city=document.getElementById('loc_city').value;	
var cas_state=document.getElementById('loc_state').value;	
var cas_zip=document.getElementById('loc_zip').value;	
var cas_phone1=document.getElementById('loc_phone').value;	
var cas_phone2=document.getElementById('loc_phone2').value;	
var cas_fax=document.getElementById('loc_fax').value;	
var cas_email=document.getElementById('loc_email').value;	
var cas_url=document.getElementById('loc_url').value;	
var loc_country=document.getElementById('loc_country').value;
var loc_price=document.getElementById('loc_price').value;
var loc_type=document.getElementById('loc_type').value;
var loc_place=document.getElementById('bootstrap').value;
var region_id=document.getElementById('region_id').value; 


// ADDRESS CHECKS
	if(cas_name==""){
    alert( "Please enter A Location Name!" );		
	document.getElementById('loc_name').focus();
	return false;	
	}
    
	if(cas_address==""){
    alert( "Please enter A Location Address!" );		
	document.getElementById('loc_add1').focus();
	return false;	
	}
	if(cas_city==""){
    alert( "Please enter A Location City!" );		
	document.getElementById('loc_city').focus();
	return false;	
	}	
	if(cas_state==""){
    alert( "Please enter A Two Letter Location State ( NJ/NY )!" );		
	document.getElementById('loc_state').focus();
	return false;	
	}	
	if(cas_zip==""){
    alert( "Please enter A Location 5 Digit Zip Code!" );		
	document.getElementById('loc_zip').focus();
	return false;	
	}
// PHONE FAX CHECK
	if(cas_phone1==""){
    alert( "Please enter A Location Phone Number (xxx-xxx-xxxx)!" );		
	document.getElementById('loc_phone').focus();
	return false;	
	}
/*	if(cas_fax==""){ 
    alert( "Please enter A Location Fax Number (xxx-xxx-xxxx)!" );		
	document.getElementById('loc_fax').focus();
	return false;	
	}
	
// EMAIL AND URL CHECK
	if(cas_email==""){
    alert( "Please enter A Location Email Address (xxxx@xxxx.xxx)!" );		
	document.getElementById('loc_email').focus();
	return false;	
	}	
	if(cas_url==""){
    alert( "Please enter A Location Website URL http://thesite.com!" );		
	document.getElementById('cas_url').focus();
	return false;	
	}	*/
	
// COLOR PICKER
	var r=document.getElementById('red').value;
	var g=document.getElementById('green').value;
	var b=document.getElementById('blue').value;
	var cl=''+r+'-'+g+'-'+b+''; 
 
 findaddress();

var lat=document.getElementById('lat').value;	
var lng=document.getElementById('lng').value;

if(lat==""){
//findaddress();
return false;
}
if(lng==""){
//findaddress();
return false;
}
	
	
 ajaxpage('/inc/mods/create.php?action=addcas&region_id='+region_id+'&cas_lat='+lat+'&cas_lng='+lng+'&cas_icon='+cl+'&cas_url='+cas_url+'&cas_email='+cas_email+'&cas_fax='+cas_fax+'&cas_phone1='+cas_phone1+'&cas_zip='+cas_zip+'&cas_state='+cas_state+'&cas_city='+cas_city+'&cas_address2='+cas_address2+'&cas_name='+cas_name+'&cas_address='+cas_address+'&loc_country='+loc_country+'&loc_price='+loc_price+'&loc_type='+loc_type+'&loc_place='+loc_place+'','admincontent');

}


function mapiconcolor(){
	var r=document.getElementById('red').value;
	var g=document.getElementById('green').value;
	var b=document.getElementById('blue').value;
	
	
	if(r >255){
	alert("CAN NOT BE MORE THAN 255");
	document.getElementById('red').value='0';
	document.getElementById('red').focus();
	}else if(r < 0){
	alert("MUST BE MORE THAN 0");
	document.getElementById('red').value='0';
	document.getElementById('red').focus();
	}
	
		if(g >255){
	alert("CAN NOT BE MORE THAN 255");
	document.getElementById('green').value='0';
	document.getElementById('green').focus();
	}else if(g < 0){
	alert("MUST BE MORE THAN 0");
	document.getElementById('green').value='0';
	document.getElementById('green').focus();
		
	}
	
	if(b >255){
	alert("CAN NOT BE MORE THAN 255");
	document.getElementById('blue').value='0';
	document.getElementById('blue').focus();
	}else if(b < 0){
	alert("MUST BE MORE THAN 0");
	document.getElementById('blue').value='0';
	document.getElementById('blue').focus();
		
	}
	
	ajaxpage('/inc/mods/create.php?action=loadicon&red='+r+'&green='+g+'&blue='+b+'','thecolor');
	
}

function numchange(action,field){
	
	var num=document.getElementById(field).value;
	var total=10;
	if(action=="1"){
	 newnum=document.getElementById(field).value + total;
     total=parseInt(num) + parseInt(total)
	}else if(action=="0"){
total=parseInt(num) - parseInt(total)
		
	}
 	document.getElementById(field).value=total;	
    mapiconcolor();
	
}

function admincontent(){
	
	ajaxpage('/inc/mods/loadadmin.php','admincontent');


 setTimeout("admincontent()",2000);
}
	   
	   function jumper(url,time,div){
		
				ajaxpage('/inc/actions.php?action=loading',''+div+'');
				 
				setTimeout("ajaxpage('"+url+"','"+div+"')", time); // Recall the script after so many milliseconds	
		
			
		}



 function loadstates(){
		
		var state=document.getElementById('state').value;
        var city=document.getElementById('search').value;
		
		document.getElementById('statelist').innerHTML=state;
           	if(state.length=="2"){
		
		document.getElementById('loadgstates').checked=true;			
			
			
				if(city.length>"0"){
				
				
				jumper('/inc/actions.php?action=loadcities&state='+state+'&city='+city+'','1200','cities');
				 
				 
		//		 loadmap(''+city+'',''+state+'','');  
				  
				  }
		  
	 	  jumper('/inc/actions.php?action=loadcities&state='+state+'','1200','cities');
         loadmap('',''+state+'','');  
		   }else{
			   
			   document.getElementById('loadgstates').checked=false;	

			   clearmap();
	           
		   }
 
                 
		}

 function loadcities(){
		
		var state=document.getElementById('state').value;
		var city=document.getElementById('search').value;
		
		document.getElementById('statelist').innerHTML=state;
           	if(state.length=="2"){
		  jumper('/inc/actions.php?action=loadcities&state='+state+'&city='+city+'','500','cities');
                 	}
 
		}
	 

     // this variable will collect the html which will eventualkly be placed in the side_bar
      var side_bar_html = "";
    
      // arrays to hold copies of the markers used by the side_bar
      // because the function closure trick doesnt work there
      var gmarkers = [];

      // A function to create the marker and set up the event window
      function createMarker(point,name,html,icon,cas_id) {
      var casinoIcon = new GIcon();
      casinoIcon.image = "/images/mapmarkers.php?cl="+icon+"";
      casinoIcon.shadow = "/images/mm_20/mm_20_shadow.png";
	  casinoIcon.iconSize = new GSize(12, 20);
	  casinoIcon.shadowSize = new GSize(22, 20);
	  casinoIcon.iconAnchor = new GPoint(6, 20);
      casinoIcon.infoWindowAnchor = new GPoint(5, 1);    

       var marker = new GMarker(point,casinoIcon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }

function clearmap(){
	
     // this variable will collect the html which will eventualkly be placed in the side_bar
      var side_bar_html = '';	
	  // arrays to hold copies of the markers used by the side_bar
      // because the function closure trick doesnt work there
    gmarkers.reverse();
	 // gmarkers.push(marker)
	  ajaxpage('/index.php?action=none','side_bar');
//	  document.getElementById('side_bar').innerHTML=cleanit;
      map.clearOverlays(); 
      map.setCenter(new GLatLng(41	,-97),3);
}

function adminload(url){
	clearmap();	
        // Read the data from example.xml
        GDownloadUrl(url, function(doc) {
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var html = markers[i].getAttribute("html");
          var label = markers[i].getAttribute("label");
		  var icon = markers[i].getAttribute("icon");
		  var cas_id = markers[i].getAttribute("cas_id");
          // create the marker
          var marker = createMarker(point,label,html,icon,cas_id);
          map.addOverlay(marker);
        }
        // put the assembled side_bar_html contents into the side_bar div
        document.getElementById("side_bar").innerHTML = side_bar_html;
      });	
	
}

function loadmap2(theplace){
 
document.getElementById('search').value=theplace;
showAddress();

//
//     			      // Read the data from example.xml
//        GDownloadUrl("/inc/mods/load.php?city="+city+"&state="+state+"", function(doc) {
//        var xmlDoc = GXml.parse(doc);
//        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
//          
//        for (var i = 0; i < markers.length; i++) {
//          // obtain the attribues of each marker
//          var lat = parseFloat(markers[i].getAttribute("lat"));
//          var lng = parseFloat(markers[i].getAttribute("lng"));
//          var point = new GLatLng(lat,lng);
//          var html = markers[i].getAttribute("html");
//          var label = markers[i].getAttribute("label");
//		  var icon = markers[i].getAttribute("icon");
//		  var cas_id = markers[i].getAttribute("cas_id");
//          // create the marker
//          var marker = createMarker(point,label,html,icon,cas_id);
//          map.addOverlay(marker);
//        }
//        // put the assembled side_bar_html contents into the side_bar div
//        document.getElementById("side_bar").innerHTML = side_bar_html;
//      });
	
 	
}

function loadmap(city,state,zip){
//clearmap();	
 var theplace=''+city+' '+state+' '+zip+'';
document.getElementById('search').value=theplace;
showAddress();
     			      // Read the data from example.xml
        GDownloadUrl("/inc/mods/load.php?city="+city+"&state="+state+"", function(doc) {
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var html = markers[i].getAttribute("html");
          var label = markers[i].getAttribute("label");
		  var icon = markers[i].getAttribute("icon");
		  var cas_id = markers[i].getAttribute("cas_id");
          // create the marker
          var marker = createMarker(point,label,html,icon,cas_id);
          map.addOverlay(marker);
        }
        // put the assembled side_bar_html contents into the side_bar div
        document.getElementById("side_bar").innerHTML = side_bar_html;
      });
	
 	
}
function findaddress(){
var cas_name=document.getElementById('loc_name').value;	
var cas_address=document.getElementById('loc_add1').value;	
var cas_address2=document.getElementById('loc_add2').value;	
var cas_city=document.getElementById('loc_city').value;	
var cas_state=document.getElementById('loc_state').value;	
var cas_zip=document.getElementById('loc_zip').value;	
var cas_phone1=document.getElementById('loc_phone').value;	
var cas_phone2=document.getElementById('loc_phone2').value;	
var cas_fax=document.getElementById('loc_fax').value;	
var cas_email=document.getElementById('loc_email').value;	
var cas_url=document.getElementById('loc_url').value;	

var address = ''+cas_address+' '+cas_city+' '+cas_state+' '+cas_zip+'';
	      // Create new geocoding object
  //    geocoder = new GClientGeocoder();

      // Retrieve location information, pass it to addToMap()
      geo.getLocations(address, addToMap);
 	
}

 function addToMap(response)
   {
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);
 document.getElementById('lat').value=place.Point.coordinates[1];	
 document.getElementById('lng').value=place.Point.coordinates[0];	
 document.getElementById('addcas').style.display='block';	
  document.getElementById('findcas').style.display='none';	
      // Center the map on this point
      map.setCenter(point, 13);

      // Create a marker
      marker = new GMarker(point);

      // Add the marker to map
      map.addOverlay(marker);

      // Add address information to marker
      marker.openInfoWindowHtml(place.address);
 }

function loadzipcode(){

var state = document.getElementById('state').value;
var city = document.getElementById('city').value;

//var zip = document.getElementById('zipcode').value;



setTimeout("ajaxpage('/indexb.php?action=loadzipcodego&city="+city+"&state="+state+"','loadzip')",1200);
setTimeout("ajaxpage('/indexb.php?action=ldgzips','ldgzips')",2500);



}

function clearwhereareyou(){
	
document.getElementById('state').value='';
document.getElementById('city').value='';
setTimeout("ajaxpage('/indexb.php?action=clearwru','loadzip')",500);

	
}

function whereruload(c,s){
var state = document.getElementById('state').value=s;
var city = document.getElementById('city').value=c;

	loadzipcode();
	
}


function searchmore(page_id){
	
 jumper('/inc/mods/searchmore.php','1200','reviewcontent');
 jumper('/inc/mods/loadpage.php?page_id='+page_id+'','2500','contentareaSM');
				
}