function updateSearchMethod(method) {
	
	var alpha_left = document.getElementById("tab_alpha_left");
	var alpha_mid = document.getElementById("tab_alpha_mid");
	var alpha_right = document.getElementById("tab_alpha_right");

	var recom_left = document.getElementById("tab_recom_left");
	var recom_mid = document.getElementById("tab_recom_mid");
	var recom_right = document.getElementById("tab_recom_right");

	var spec_left = document.getElementById("tab_spec_left");
	var spec_mid = document.getElementById("tab_spec_mid");
	var spec_right = document.getElementById("tab_spec_right");
	
	var search_method = document.getElementById("search_method");

	alpha_left.className = 'tab_left_closed';
	alpha_mid.className = 'tab_mid_closed';
	alpha_right.className = 'tab_right_closed';
	recom_left.className = 'tab_left_closed';
	recom_mid.className = 'tab_mid_closed';
	recom_right.className = 'tab_right_closed';
	spec_left.className = 'tab_left_closed';
	spec_mid.className = 'tab_mid_closed';
	spec_right.className = 'tab_right_closed';

	if(method == "Alpha")
	{
		alpha_left.className = 'tab_left_open';
		alpha_mid.className = 'tab_mid_open';
		alpha_right.className = 'tab_right_open';
		search_method.value = "alphabet";
	}
	else if(method == "Recom")
	{
		recom_left.className = 'tab_left_open';
		recom_mid.className = 'tab_mid_open';
		recom_right.className = 'tab_right_open';
		search_method.value = "recommend";
	}
	else if(method == "Spec")
	{
		spec_left.className = 'tab_left_open';
		spec_mid.className = 'tab_mid_open';
		spec_right.className = 'tab_right_open';
		search_method.value = "special";
	}
}

function load_map(address) {
	  if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("google_map"));
		//map.addControl(new GSmallMapControl());
		//map.addControl(new GOverviewMapControl());
		//map.addControl(new GMapTypeControl());
		//address = document.getElementById(address);
		var start_address = address;
        
        geocoder = new GClientGeocoder();
		geocoder.getLatLng(
          start_address,
          function(point) 
		  {
            if (!point) 
			{
              //alert(start_address + " not found");
            } 
			else 
			{
              map.setCenter(point, 14);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              //marker.openInfoWindowHtml(start_address);
            }
          }
        );
      }
    }
function load_biz_map(lng, lat) {
	  if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("biz_map"));
		map.addControl(new GSmallMapControl());
		//map.addControl(new GOverviewMapControl());
		map.addControl(new GMapTypeControl());
		var map_address = document.getElementById("biz_address");
		var biz_contact_card = document.getElementById("google_address");
		var start_address = map_address.innerHTML;
       
      geocoder = new GClientGeocoder();
		
		if(lng != 0.00000 && lat != 0.00000)
		{
			var point = new GLatLng(lat, lng);
			map.setCenter(point, 14);
         var marker = new GMarker(point);
         map.addOverlay(marker);
         marker.openInfoWindowHtml(biz_contact_card.innerHTML);
		}
		else
		{
		geocoder.getLatLng(
          start_address,
          function(point) 
		  {
            if (!point) 
			{
//              alert(start_address + " not found");
            } 
			else 
			{
              map.setCenter(point, 14);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(biz_contact_card.innerHTML);
            }
          }
        );
		};
      }
    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) 
		  {
            if (!point) 
			{
//              alert(address + " not found");
            } 
			else 
			{
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }

function openFrameless(open_what, urlPop, title, autoclose){
	
	if(open_what == "web")
		window.open(urlPop, 'popFrameless', 'width=870,height=500, screenx='+ (screen.width-765)/2 +',screeny=20,scrollbars=yes,menubar=yes,location=yes,resizable=yes');
	else
		window.open(urlPop, 'popFrameless', 'width=870,height=500, screenx='+ (screen.width-765)/2 +',screeny=20,scrollbars=yes,resizable=yes');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function BY_swapImgRestore() { //v3.0
  var i,x,y,a=document.MM_sr,b=document.MM_div; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  for(i=1;i<b.length;i++)
  {
	  y=b[i];
	  y.style.visibility = "hidden";
  }
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function confirm_yeah(string) {
	var ret_value = confirm(string);
	
	if(ret_value) {
		document.MainForm.cancel_yes.value = 0;
	}
	else
	{
		document.MainForm.cancel_yes.value = 1;
	}
}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
	document.MM_sr[j++]=x;
	if(!x.oSrc)
		x.oSrc=x.src;
	x.src=a[i+2];
	}
}
function BY_icon_ro() { //v3.0
  var i,j=0,x,a=BY_icon_ro.arguments; 
  document.MM_sr=new Array;
  document.MM_div=new Array;
  for(i=0;i<(a.length-2);i+=3)
  {
   if ((x=MM_findObj(a[i]))!=null)
   {
	document.MM_sr[j++]=x;
	if(!x.oSrc)
		x.oSrc=x.src;
	x.src=a[i+2];
	}
	if ((y=MM_findObj(a[i+1]))!=null)
	{
		document.MM_div[j++]=y;
		y.style.visibility = "visible";
		var curleft = curtop = 0;
		if (x.offsetParent) {
			curleft = x.offsetLeft;
			curtop = x.offsetTop;
			while (x = x.offsetParent) {
				curleft += x.offsetLeft;
				curtop += x.offsetTop;
			}
		}
		y.style.top = (curtop+55) + "px";
		y.style.left = (curleft+5) + "px";
	}
  }
}


function formatTelNo (telNo)
{
    // If it's blank, save yourself some trouble by doing nothing.
    if (telNo.value == "") return;

    

    var phone = new String (telNo.value);
    
    phone = phone.substring(0,14);

    /*
    "." means any character. If you try to use "(" and ")", the regular expression becomes 
    complicated sice both are reserve characters and escaping them sometimes fails. So just 
    use "." for any character and replace it later.
    */
    if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        /*
        Following "if" is for user making any changes to the formatted tel. no. If you don't put this 
        "if" condition, the user can not correct a digit by first deleting it and then entering a 
        correct one, since this will fire two "onkeyup" events : first one on deleting a 
        character and second one on entering the correct one. The first "onkeyup" event will fire this 
        function which will reformatt the tel no before the user gets a chace to correct the digit. This 
        will surely confuse the user. The "if" condition below eliminates that.
        */
        if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
            ".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
        {
            /*
            You will reach here only if the user is still typing the number or if he/she has 
            messed up already formatted number. 
            */
            var phoneNumeric = phoneChar = "", i;
            // Loop thru what user has entered.
            for (i=0;i<phone.length;i++)
            {
                // Go thru what user has entered one character at a time.
                phoneChar = phone.substr (i,1);
    
                // If that character is not a number or is a White space, ignore it. Only if it is a digit, 
                // concatinate it with a number string.
                if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
            }
    
            phone = "";
            // At this point, you have picked up only digits from what user has entered. Loop thru it.
            for (i=0;i<phoneNumeric.length;i++)
            {
                // If it's the first digit, throw in "(" before that.
                if (i == 0) phone = phone + "(";
                // If you are on the 4th digit, put ") " before that.
                if (i == 3) phone = phone + ") ";
                // If you are on the 7th digit, insert "-" before that.
                if (i == 6) phone = phone + "-";
                // Add the digit to the phone charatcer string you are building.
                phone = phone + phoneNumeric.substr (i,1)
            }
        }
    }
    else
    { 
        // This means the tel no is in proper format. Make sure by replacing the 0th, 4th and 8th character.
        phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13); 
    }
    // So far you are working internally. Refresh the screen with the re-formatted value.
    if (phone != telNo.value) telNo.value = phone;
}

/*
CheckTelNo method takes in current element of the form as input. This method should be 
fired as the user attempts to leave the current element in the form (by using onBlur method). 
It checks to see if the format of the phone is "(123) 456-7890".
Eg. <netui:textBox size="13" maxlength="13" onBlur="JavaScript:checkTelNo (this);" onKeyUp="JavaScript:formatTelNo (this);" onKeyDown="JavaScript:formatTelNo (this);"/>  
*/      
function checkTelNo (telNo)
{
    if (telNo.value == "") return;
    if (telNo.value.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        if (telNo.value.match ("[0-9]{10}") != null)
            formatTelNo (telNo)              
    }
}

//The show_map function is designed to show the google map based on the address.
function show_map(id)
{
	//var map_title = document.getElementById("map_title");
	load_map(id.innerHTML);
	var google_map = document.getElementById("google_map");
	google_map.style.visibility="visible";
	var curleft = curtop = 0;
		if (id.offsetParent) {
			curleft = id.offsetLeft;
			curtop = id.offsetTop;
			while (id = id.offsetParent) {
				curleft += id.offsetLeft;
				curtop += id.offsetTop;
			}
		}
		google_map.style.top = (curtop-425) + "px";
		google_map.style.left = (curleft+350) + "px";
	
	
}
//The hide_map function is designed to show the google map based on the address.
function hide_map(id)
{
	//var map_title = document.getElementById("map_title");
	var google_map = document.getElementById("google_map");
	google_map.style.visibility="hidden";
	//map_title.innerHTML = id.innerHTML;
}
function showEditMode(template, divisional)
{
	var div_template = document.getElementById(template);
	var div_divisional = document.getElementById(divisional);
	
	div_divisional.innerHTML = div_template.innerHTML;
}

function editBusinessReview(number, score, bizdataid, home_user, reviewid, state)
{	

	var div_divisional = document.getElementById("review_"+number+"_text");
	var review_content = div_divisional.innerHTML;

	var insert_text = '<div class="recent_review" style="border-bottom:1px solid silver; padding-bottom:7px; margin-bottom:15px;" id="edit_'+number+'"><b>Edit the review below and click save.</b><form action="/process.userhome.php" method="post"><div align="center" style="height:100%; "><textarea name="review" class="edit_review">'+review_content+'</textarea></div><div><input type="hidden" value="'+score+'" id="review_score_'+number+'" name="score">Please Rate This Business<img src="/images/empty_star.gif" id="star'+number+'_1" onMouseOver="showStars('+number+', 1);" onMouseOut="hideStars('+number+');" onClick="updateStars('+number+', 1)" class="star_score" /><img src="/images/empty_star.gif" id="star'+number+'_2" onMouseOver="showStars('+number+', 2);" onMouseOut="hideStars('+number+');" onClick="updateStars('+number+', 2)" class="star_score" /><img src="/images/empty_star.gif" id="star'+number+'_3" onMouseOver="showStars('+number+', 3);" onMouseOut="hideStars('+number+');" onClick="updateStars('+number+', 3)" class="star_score" /><img src="/images/empty_star.gif" id="star'+number+'_4" onMouseOver="showStars('+number+', 4);" onMouseOut="hideStars('+number+');" onClick="updateStars('+number+', 4)" class="star_score" /><img src="/images/empty_star.gif" id="star'+number+'_5" onMouseOver="showStars('+number+', 5);" onMouseOut="hideStars('+number+');" onClick="updateStars('+number+', 5)" class="star_score" /><span id="visible_score_'+number+'">'+score+' out of 5</span></div><div align="center" style="margin-top:4px; "><input type="submit" onclick="" value="SAVE" class="admin_button" />&nbsp;&nbsp;&nbsp;<input type="button" value="CANCEL" class="admin_button" onclick="document.location=document.location" /><input type="hidden" name="businessid" value="'+bizdataid+'" /><input type="hidden" name="state" value="'+state+'" /><input type="hidden" name="sub_modify_review" value="1" /><input type="hidden" name="return_url" value="/members/'+home_user+'/" /><input type="hidden" name="reviewid" value="'+reviewid+'" /></div><div align="right" class="gray_subtitle" style="margin-top:5px; "></div></form></div>';

	div_divisional.innerHTML = insert_text;
	
}
function hideEditMode(divisional)
{

	var div_divisional = document.getElementById(divisional);
	
	div_divisional.innerHTML = "";
}
function showStars(num, star_num)
{
	var star_array = Array(star_num);	
	for(i=0; i<star_num; i++)
	{
		star_array[i] = document.getElementById("star"+num+"_" + (i+1));
		star_array[i].src = '/images/transstar.gif';
	}
}
function hideStars(num)
{
	var score = document.getElementById("review_score_" + num);
	var num_stars = score.value;
	var visible_score = document.getElementById('visible_score_' + num);
	visible_score.innerHTML = num_stars + ' out of 5';
	var star_array = Array(5);
	for(i=0; i<(5); i++)
	{
		if (num_stars<(i+1))
		{
			star_array[i] = document.getElementById("star"+num+"_" + (i+1));
			star_array[i].src = '/images/empty_star.gif';
		}
	}
}
function updateStars(num, star_num)
{
	var score = document.getElementById("review_score_"+num);
	score.value=star_num;
	hideStars(num);
}

function writeCaption()
{
	var main_image = document.getElementById("main_image");
	var gallery_caption = document.getElementById("gallery_caption");
	
	gallery_caption.innerHTML = main_image.title;
}
function biz_swap_image(thumbnail)
{
	var main_image = document.getElementById("main_image");
	
	document.main_img_src = main_image.src;
	document.main_img_title = main_image.title;
	
	main_image.src=thumbnail.src;
	main_image.title=thumbnail.title;
}
function biz_return_image()
{
	var main_image = document.getElementById("main_image");
	main_image.src = document.main_img_src;
	main_image.title = document.main_img_title;
}
function biz_set_image(thumbnail)
{
	var main_image = document.getElementById("main_image");
	var gallery_caption = document.getElementById("gallery_caption");
	
	var new_main = thumbnail.src;
	var new_title = thumbnail.title;
	main_image.src=thumbnail.src;
	main_image.title=thumbnail.title;

	document.main_img_src = new_main;
	document.main_img_title = new_title;
	
	gallery_caption.innerHTML = document.main_img_title;
}
function showLoginLeft(login_link)
{
	var login_div = document.getElementById("user_login_container");
	if(document.isShown==1)
	{
		document.isShown = 0;
		login_div.style.visibility = "hidden";
	}
	else
	{
		document.isShown = 1;
		login_div.style.visibility = "visible";
		var curleft = curtop = 0;
		if (login_link.offsetParent) {
			curleft = login_link.offsetLeft;
			curtop = login_link.offsetTop;
			while (login_link = login_link.offsetParent) {
				curleft += login_link.offsetLeft;
				curtop += login_link.offsetTop;
			}
		}
		login_div.style.top = (curtop+15) + "px";
		login_div.style.left = (curleft) + "px";
	}
}
function hideLoginDelayed()
{
	alert("hello");
	if (document.ro_state == 1)
	{
		setTimeout("hideLogin()", 1500);
		document.ro_state = 0;
	}
	else
	{
		document.ro_state = 1;
	}
}
function hideLogin()
{
	document.isShown = 0;
	var login_div = document.getElementById("user_login_container");
	login_div.style.visibility = "hidden";
}
function showLoginRight(login_link)
{
	var login_div = document.getElementById("user_login_container");
	var user_name_input = document.getElementById("user_name_input");
	
	user_name_input.focus();
	
	if(document.isShown==1)
	{
		document.isShown = 0;
		login_div.style.visibility = "hidden";
	}
	else
	{
		document.isShown = 1;
		login_div.style.visibility = "visible";
		var curleft = curtop = 0;
		if (login_link.offsetParent) {
			curleft = login_link.offsetLeft;
			curtop = login_link.offsetTop;
			while (login_link = login_link.offsetParent) {
				curleft += login_link.offsetLeft;
				curtop += login_link.offsetTop;
			}
		}
		login_div.style.top = (curtop+15) + "px";
		login_div.style.left = (curleft-226) + "px";
	}
}
function checkReview()
{
	var review_text = document.getElementById("review_text");
	var review_score = document.getElementById("review_score");
	var errors = 0;
	var error_message = "There are problems with this review.";
	if (review_text.value.length < 250)
	{
		errors++;
		error_message += "\n-Review must be at least 250 characters.";		
	}
	if (review_score.value == 0)
	{
		errors++;
		error_message += "\n-You must rate this business with a score from 1 to 5.";
	}
	if (errors>0)
	{
		alert(error_message);
		return false;
	}
	else
		return true;	
}
function checkDescription()
{
	var description_text = document.getElementById("description_text2");
	var contact_name = document.getElementById("contact_name");
	var secondary_phone = document.getElementById("secondary_phone");
	var email = document.getElementById("email");
	var errors = 0;
	var error_message = "";
	if (description_text.value.length < 500)
	{
		errors++;
		error_message += "There are problems with this review.\n-Business description must be at least 500 characters.";
	}
	if (contact_name.value == "")
	{
		errors++;
		error_message += "\n-You need to provide a contact name.";
	}
	if (email.value == "")
	{
		errors++;
		error_message += "\n-You need to provide a valid email address.";
	}
	if (errors>0)
	{
		alert(error_message);
		return false;
	}
	else
		return true;	
}
function checkUserDescription()
{
	var description_text = document.getElementById("description_text");
	var errors = 0;
	var error_message = "There are problems with this review.";
	if (!check_login())
	{
		errors++;
		error_message += "\n-You must be logged in.";	
	}
	if (description_text.value.length < 500)
	{
		errors++;
		error_message += "\n-Description must be at least 500 characters.";		
	}
	if (errors>0)
	{
		alert(error_message);
		return false;
	}
	else
		return true;	
}
function check_login()
{
	var check_login = document.getElementById("check_login");
	if (check_login.value == 1)
		return true;
	else
		return false;
}
function updateReviewCharacters(text_field, req_chars)
{
	var numCharacters = document.getElementById("numCharacters");
	var rem_chars = req_chars - text_field.value.length;
	if (rem_chars > 0)
		numCharacters.innerHTML = req_chars - text_field.value.length + " remaining.";
	else
		numCharacters.innerHTML = "Minimum requirement met.";
}
                  