//btn//////////////////////////////////////////////////////////////////////////////////////
function btn_load(){

	$$('.btnS').each(function(s, index) { s.observe('mouseover', respondToOverS); });
	$$('.btnS').each(function(s, index) { s.observe('mouseout', respondToOutS); });
	$$('.btnM').each(function(s, index) { s.observe('mouseover', respondToOverM); });
	$$('.btnM').each(function(s, index) { s.observe('mouseout', respondToOutM); });
	$$('.btnL').each(function(s, index) { s.observe('mouseover', respondToOverL); });
	$$('.btnL').each(function(s, index) { s.observe('mouseout', respondToOutL); });

}

function respondToOverS(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn70_over.gif)'});
  element.setStyle({background: 'url(./images/btn70_over.gif)'});
}

function respondToOutS(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn70.gif)'});
  element.setStyle({background: 'url(./images/btn70.gif)'});
}

function respondToOverM(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn100_over.gif)'});
  element.setStyle({background: 'url(./images/btn100_over.gif)'});
}

function respondToOutM(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn100.gif)'});
  element.setStyle({background: 'url(./images/btn100.gif)'});
}

function respondToOverL(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn150_over.gif)'});
  element.setStyle({background: 'url(./images/btn150_over.gif)'});
}

function respondToOutL(event) {
  var element = Event.element(event);
  element.setStyle({backgroundImage: 'url(./images/btn150.gif)'});
  element.setStyle({background: 'url(./images/btn150.gif)'});
}
///////////////////////////////////////////////////////////////////////////////////////////
//navigator////////////////////////////////////////////////////////////////////////////////
var need_to_hide_subnav = false;
var current_subnav_active = 0;
var current_timeout = null;

function hide_all() {
	if (need_to_hide_subnav) {
		current_subnav_active = 0;
		need_to_hide_subnav = false;
		clearTimeout(current_timeout);
		$$('div.subnav').invoke('hide');
	}
}

function hide_all_immediately() {
	unkeep_subnav(null);
	hide_all();
}

function show_subnav(a) {
	$$('div.subnav').invoke('hide');
    keep_subnav(a);
    new Effect.Appear("subnav_" + a, {duration: 0.5});
}

function keep_subnav(a) {
	need_to_hide_subnav = false;
	if (a) {
		current_subnav_active = a;
	}
	clearTimeout(current_timeout);
}

function unkeep_subnav(a) {
	need_to_hide_subnav = true;
	if (a) {
		current_subnav_active = a;
	}
	current_timeout = setTimeout(hide_all, 7000);
}
///////////////////////////////////////////////////////////////////////////////////////////
function popUpWindow(URLStr, width, height)
{
	if(width >= screen.width)
		width = 'full';
	if(height >= screen.height)
		height = 'full';

	if(width == "full")
		width = window.screen.availWidth;
	else
		var left = Math.round((screen.width - width) / 2);
	if(height == "full")
		height = window.screen.availHeight;
	else
		var top = Math.round((screen.height - height) / 2);

	popUpWin = open(URLStr, 'adsbxc_ss', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.opener.name="1A2B3C4D";
}

function countryChanged() {
	$('state').value = '';
	$('city_id').value = '';
	$('city_name').value = '';
	$('country_code_hidden').value = $('country_id')[$('country_id').selectedIndex].value;
}

function changeStatus(status_id) {
	if (status_id<0) {
		status_id = 0;
	}
	var url = 'ajax_status_change.php?status_id='+status_id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	responce = transport.responseText.split('|');
	    if (responce[0] == 'true') {
	    	if (responce[1].length > 0) {
				$('status_updated').update(responce[1]);
				if (status_id>-1) {
					$('status_text').update(status[status_id]);
					if (status_id>0) {
						$('status_img').src = 'images/status/'+status_id+'.gif';
						$('status_img').setStyle({display: 'inline'});
					} else {
						$('status_img').setStyle({display: 'none'});
					}
				}
	    	}
	    }
	  }
	});

	//top.tb_remove();
	hs_iframe_close();
	return false;
}

function submitNewCity(form_val) {

	var city_name="";		
	/*var city_bug_fixed=$$('#city_input');			
	for( var i=0;i<city_bug_fixed.length;i++)
	{
		if(city_bug_fixed[i].getValue())
		{
			city_name=city_bug_fixed[i].getValue();
			break;
		}
	}*/
	city_name=form_val.form['f[city_name]'].value;	
	new Ajax.Request('ajax_add_new_city.php', {
		method: 'post',
		parameters: { city_name: city_name, cmd: 'add_on', country_id: $('country_id').value },
		onSuccess: function(transport) {
			var returnedData = eval('(' + transport.responseText + ')');

			if (returnedData.status == 'success') {
				top.$('city_name').value = returnedData.city_name;
				top.$('city_id').value = returnedData.city_id;
				//top.tb_remove();
				top.hs_iframe_close();
			} else {
				alert(returnedData.error_message);
			}
		}
	});
	return false;
}

function showBirthdayCalendar() {
	return hs.htmlExpand($('a_birthday_calendar'), { objectType: 'iframe', preserveContent: true, height: 255, width: 250} );
}

function chatInvitation(user_id) {
	if (confirm(inv_confirm)) {
		var popup_ = window.open('private_chat.php?uid='+user_id+'&invite=1', 'Private Chatroom', 'height=720,width=985,scrollbars=no,resizable=no');
	}
	return false;
}

var invitationTemplate = new Template('<center><span style="font-size:18px;">You have new chat invitation from <a href="#{login}?invitation=1" target="_blank" style="font-size:20px;text-decoration:none;color:#25739F;">#{login}</a>.</span>'+
									  '<br/><span style="font-size:12px;"><a href="private_chat.php?uid=#{user_id}&invitation_id=#{invitation_id}" onclick="top.resultChatRequest(#{invitation_id},\'accept_chat_invitation\');" target="_blank" style="font-size:20px;text-decoration:none;color:#25739F;">Join Chat</a> or <a href="javascript:void(0);" onclick="top.resultChatRequest(#{invitation_id},\'decline_chat_invitation\');" style="font-size:20px;text-decoration:none;color:#25739F;">Decline Request</a></span>'+
									  '<br/><span style="font-size:10px;color:#999999;line-height:12px;">Chat will be opened in new window.<br/>You could also adjust who may invite you using your permission settings.</span></center>');

var juserTemplate = new Template('<div id="juser_#{user_id}" class="jusers" style="float:left;margin:2px;"><a href="#{login}" title="#{login}, #{age}"><img src="images/users/s/#{photo}" width="75" id="juser_img_#{user_id}" class="juser_img"></a></div>');

function resultChatRequest(invitation_id, status) {
	if (invitation_id>0) {
		new Ajax.Request('ajax_action_getWindowUpdate.php', {
			method: 'post',
			parameters: { cmd: status, invitation_id: invitation_id },
			onSuccess: function(transport) {
				invitationOpened = 0;
				hs.close();
			}
		});
	}
}

function getUpdate() {
	if (invitationOpened == 0) {
		new Ajax.Request('ajax_action_getWindowUpdate.php', {
			method: 'post',
			parameters: { last_update: lastUpdate, jusers_page: jusersPage },
			onSuccess: function(transport) {
				var returnedData = eval('(' + transport.responseText + ')');

				if (lastUpdate < returnedData.last_update) {
					lastUpdate = returnedData.last_update;
					if (returnedData.invitation != null) {
							invitationOpened = 1;
							$('requests_container').update(invitationTemplate.evaluate(returnedData.invitation));
							hs.htmlExpand($('requests_container'), { contentId: 'requests_container', height: 110, width: 280 } );
					}
				}
				/*if (returnedData.last_joined_users != null && jusers_counter>0) {
					new Effect.Fade('box_jusers_bar', {afterFinish: function() {
						jusersPage = returnedData.last_joined_users_page;
						var jusers_cont = '';
						returnedData.last_joined_users.each( function(line) {
							jusers_cont += juserTemplate.evaluate(line);
						} );
						$('box_jusers_bar').update(jusers_cont);
						new Effect.Appear('box_jusers_bar', {afterFinish: function() {
							//reobserveImages();
						}}); //new Effect.Appear('box_jusers_bar', {afterFinish: function()
					}}); //new Effect.Fade('box_jusers_bar', {afterFinish: function()
				} //if (returnedData.last_joined_users != null)
				jusers_counter = jusers_counter+1;*/
			} //onSuccess: function(transport)
		}); //new Ajax.Request('ajax_action_getWindowUpdate.php'
	} // if (invitationOpened == 0)
} // function getUpdate()

/*function reobserveImages() {
	box_jusers_bar_width = $('box_jusers_bar').getStyle('width');
	var box_jusers_bar_width_n = new Number(box_jusers_bar_width.substr(0, box_jusers_bar_width.length-2));
	if (box_jusers_bar_width_n > 950) {
		box_jusers_bar_width_n = 950;
		box_jusers_bar_width = '950px';
	}
	var box_jusers_bar_width_growed = new String(box_jusers_bar_width_n+30)+'px';
  		$$('.juser_img').each( function(e) {
 				Event.observe(e, 'mouseover', function() {
 					new Effect.Morph(e,
							{
								style: {width: '90px', height: '90px'},
								duration: 0.6,
								queue: { position: 'end', scope: 'box_jusers_img_'+e.id },
								beforeStart: function() {
									if (isGrowed==false && currentGrowes==0) {
										new Effect.Morph('box_jusers_bar',
													{
														style: {width: box_jusers_bar_width_growed},
														duration: 0.1,
														queue: { position: 'end', scope: 'box_jusers_bar' },
														beforeStart: function() { isGrowed = true; }
													}
													);
									}
									currentGrowes = currentGrowes+1;
								}
							}
							);
 				});
 				Event.observe(e, 'mouseout', function() {
 					new Effect.Morph(e,
							{
								style: {width: '75px', height: '75px'},
								duration: 0.1,
								queue: { position: 'end', scope: 'box_jusers_img_'+e.id },
								afterFinish: function() {
								currentGrowes = currentGrowes-1;
								if (isGrowed==true && currentGrowes==0) {
									new Effect.Morph('box_jusers_bar',
													{
														style: {width: box_jusers_bar_width},
														duration: 0.1,
														queue: { position: 'end', scope: 'box_jusers_bar' },
														beforeStart: function() { isGrowed = false; }
													});
								}
							}
					}); //new Effect.Morph
 				}); //Event.observe(e, 'mouseout'
		});
}


Event.observe(window, 'load', function() {
	reobserveImages();
});
*/

Event.observe(window, 'load', function() {
  $$('a[href^=#]:not([href=#])').each(function(element) {
    element.observe('click', function(event) {
      new Effect.ScrollTo(this.hash.substr(1));
      Event.stop(event);
    }.bindAsEventListener(element))
  });
});

function hs_iframe_close() {
	return hs.close();
}

function messageFormShow(link) {
	return hs.htmlExpand(link, { objectType: 'iframe', width: 740, height: 620 } );
}

function clickAntispam(id) {
	if ($('f_antispam_'+id).value == 0) {
		$('f_antispam_'+id).value = 1;
		$('d_antispam_'+id).style.display = 'block';
	} else {
		$('f_antispam_'+id).value = 0;
		$('d_antispam_'+id).style.display = 'none';
	}
}

function reportFormShow(link) {
	return hs.htmlExpand(link, { objectType: 'iframe', width: 740, height: 620 } );
}

function sendWink(link) {
	return hs.htmlExpand(link, { objectType: 'iframe', width: 400, height: 160 } );
}

function showSiteMapCalendar() {
	return hs.htmlExpand($('a_site_map_calendar'), { objectType: 'iframe', preserveContent: true, height: 250, width: 250} );
}


function setFooterCity(id,elm) {
	res_city= "no";
	if(elm.checked)
	{
		res_city="yes";
	}
	new Ajax.Request('ajax_city_to_footer.php', {
		method: 'post',
			parameters: { "f[id]": id, cmd: 'change_status',"f[status_footer]": res_city},
		onSuccess: function(transport) {
			var returnedData = eval('(' + transport.responseText + ')');
			if (returnedData.status == 'success') {
				alert(returnedData.message);
			}else
			{
				alert(returnedData.message);
				if(res_city=='yes')
				{
					elm.checked=false;
				}else
				{
					elm.checked=true;
				}
			}
		}
	});
	return false;
}