// Render flash object for SEO
function swf(m, d, w, h, p,b) {
	var sw = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+w+'" height="'+h+'" align="middle">';
	sw += '<param name="allowScriptAccess" value="sameDomain" />'; sw += '<param name="wmode" value="transparent" />';
	sw += '<param name="movie" value="'+m+'" />'; sw += '<param name="quality" value="high" />'; sw += '<param name="Flashvars" value="'+p+'" />'; 
	sw += '<embed src="'+m+'" wmode="transparent" align="middle" quality="high" '; sw += 'Flashvars="'+p+'" '; 
	sw += 'width="'+w+'" height="'+h+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	$("#" + d).html(sw);
}
function swfbycss(m, d, w, h, p,b) {
	var sw = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+w+'" height="'+h+'" align="middle">';
	sw += '<param name="allowScriptAccess" value="sameDomain" />'; sw += '<param name="wmode" value="transparent" />';
	sw += '<param name="movie" value="'+m+'" />'; sw += '<param name="quality" value="high" />'; sw += '<param name="Flashvars" value="'+p+'" />'; 
	sw += '<embed src="'+m+'" wmode="transparent" align="middle" quality="high" '; sw += 'Flashvars="'+p+'" '; 
	sw += 'width="'+w+'" height="'+h+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	$("." + d).html(sw);
}

//ajax get
function xajax(controller,ajax_reply){
	
	startLoading();	
	$.ajax({
		type: "GET",
		url: controller,
		success: function(html){
			$("#"+ajax_reply).html(html);
			endLoading();
		},
		error:function(){
			endLoading();
		}
	});
	
}
function geter(controller,ajax_reply,gifimg){
	if(gifimg!=null)	{
		$("#"+gifimg).show();	
	}
	$.ajax({
		type: "GET",
		url: controller,
		success: function(html){
			$("#"+ajax_reply).html(html);
			if(gifimg!=null)	{
				$("#"+gifimg).hide();	
			}
		},
		error:function(){
			if(gifimg!=null)	{
				$("#"+gifimg).hide();	
			}
		}
	});
	
}
//--------------tour comment Reply

function showReply(self,id)
{	if($(self).html()=='Reply')
	{	$(self).html('Close')
		$(self).parent().append($('#review_box'))
		$('#review_box .ms').html('')
		$('#review_box').attr('rel',id)
	}
	else
	{	$('.rev_email .reply').html('Reply')
		$('#review_box .ms').html('')
		$('.review_box_container').append($('#review_box'))
		$('#review_box').attr('rel',0)
	}
}
//----------------------------------
function addToCard(val)
{	var pcount=1
	if($('#add_cart_product_count').val()!=undefined)
	{	var RE = /^[1-9]$/;
		if(RE.test($('#add_cart_product_count').val()))
		{	pcount=$('#add_cart_product_count').val()
		}
		else
		{	return alert("Please type one digit!");
		}
	}
	startLoading();	
	$.post("/mycart/add",{id:val, count:pcount},function(data){ $("#mybasket").html(data); endLoading();})
}
function pajax(controller,ajax_reply){
	
	startLoading();	
	$.ajax({
		type: "POST",
		url: controller,
		success: function(html){
			$("#"+ajax_reply).html(html);
			endLoading();
		},
		error:function(){
			endLoading();
		}
	});
	
}
//
function startLoading()
{ 
	$('.loading_div').css({opacity:0.4})
 	$('.loading_div table').css({width:$(window).width()})
 	$('.loading_div table').css({height:$(window).height()})
 	var x=$(window).scrollLeft()
 	var y=$(window).scrollTop()	
	//$('body').css('overflow','hidden');
 	$('.loading_div').css({top:y,left:x})
 	$('.loading_div').show()
}
function endLoading()
{ 
	$('.loading_div').hide();
	//$('body').css('overflow','auto');
}
$(document).ready(function()
{	//quick search ..........
	$('#hotel_city').change(function(){
		if($(this).val()=='Ulaanbaatar')
			$('.quick_body .hotelStar').show()
		else
			$('.quick_body .hotelStar').hide()
	})
	$('#hotel_city').change();
	$('#quick_flight_i').click(function()
	{	$(".quick_dom_body").hide()
		$(".quick_intern_body").show()
	});
	$('#quick_flight_d').click(function()
	{	$(".quick_intern_body").hide()
		$(".quick_dom_body").show()
	});
	$('#quick_tour_len').click(function()
	{	$("#tour_len").val('');
		$("#tour_price").val('');
		$(".quick_price_body").hide()
		$(".quick_len_body").show()
	});
	$('#quick_tour_p').click(function()
	{	$("#tour_price").val('');
		$("#tour_len").val('');
		$(".quick_len_body").hide()
		$(".quick_price_body").show()
	});
	/////////////////////////////////////////////////
	
	$(".oclick").click(function(){
		var aidstr = $(this).attr('id');
		var aids = aidstr.split('-'); 
		
		//alert(aids[0]);
		
		$(this).addClass('stab_le');
		$("#"+aidstr+' h2').addClass('stab_ri');
		$(this).removeClass('mod_tab_inactive');
		
		$("#"+aids[1]+'-'+aids[0]).removeClass('stab_le');		
		$("#"+aids[1]+'-'+aids[0]+' h2').removeClass('stab_ri');
		$("#"+aids[1]+'-'+aids[0]).addClass('mod_tab_inactive');
		
		$('#data'+aids[1]+'-'+aids[0]).hide();
		$('#data'+aids[0]+'-'+aids[1]).show();
		
	});	
	$("#tab100").click(function() {
		$("#tab200").removeClass('mod_tab2');
		$("#tab200").addClass('mod_tab_inactive');
		$(this).removeClass('mod_tab_dis');
		$(this).addClass('mod_tab');
		
		$('#tab100_data').show()
		$('#tab200_data').hide();
	});	
	$("#tab200").click(function() {
		$("#tab100").removeClass('mod_tab');
		$("#tab100").addClass('mod_tab_dis');		
		$(this).removeClass('mod_tab_inactive');
		$(this).addClass('mod_tab2');
		
		$('#tab200_data').show()
		$('#tab100_data').hide();
	});	
	
	$("#tab300").click(function() {
		$("#tab400").removeClass('mod_tab2');
		$("#tab400").addClass('mod_tab_inactive');
		$(this).removeClass('mod_tab_dis');
		$(this).addClass('mod_tab');
		
		$('#tab300_data').show()
		$('#tab400_data').hide();
	});	
	$("#tab400").click(function() {
		$("#tab300").removeClass('mod_tab');
		$("#tab300").addClass('mod_tab_dis');		
		$(this).removeClass('mod_tab_inactive');
		$(this).addClass('mod_tab2');
		
		$('#tab300_data').hide();
		$('#tab400_data').show()
	});
	
	$("#tab500").click(function() {
		$("#tab600").removeClass('vtab_video');
		$("#tab600").addClass('vtab_video_in');
		$(this).removeClass('vtab_photo_in');
		$(this).addClass('vtab_photo');
		
		$('#tab500_data').show()
		$('#tab600_data').hide();
	});	
	$("#tab600").click(function() {
		$("#tab500").removeClass('vtab_photo');
		$("#tab500").addClass('vtab_photo_in');		
		$(this).removeClass('vtab_video_in');
		$(this).addClass('vtab_video');
		
		$('#tab500_data').hide();
		$('#tab600_data').show()
	});
		
	$(".qs_tabs li").click(function() {
		$(".qs_tabs li").each(function() { $(this).find("span").removeClass($(this).attr('id') + '_h'); });
		$(".qs_content div[id]").addClass('hide');
		$(this).find("span").addClass($(this).attr('id') + '_h');
		$("#" + $(this).attr('id') + "_detail").removeClass('hide');
	});
	//Blog photos remove
	$(".m_photos span").click(function() {
		$(this).parent().parent().remove();
	});
	//
	$(".tab").click(function()
	 { var parent=$(this).parent()
	  $('.tab',parent).removeClass('selected')
	  $(parent).attr("rel",$(this).attr("rel"))
	  $(this).addClass('selected')
	  $('.con',parent).removeClass('selected')
	  $("#c"+$(this).attr("rel"),parent).addClass('selected')
	 });
	//Leave comment, search bar class changer
	$("#im55").focus(function() {
		if($(this).val() == 'Your name') {
			$(this).removeClass('m_bgray');
			$(this).val('');
		}
	});
	$("#im55").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_bgray');
			$(this).val('Your name');
		}
	});
	$("#im44").focus(function() {
		if($(this).val() == 'E-mail') {
			$(this).removeClass('m_bgray');
			$(this).val('');
		}
	});
	$("#im44").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_bgray');
			$(this).val('E-mail');
		}
	});
	$(".m_comments textarea[id]").focus(function() {
		if($(this).val() == 'Comment') {
			$(this).removeClass('m_bgray');
			$(this).val('');
		}
	});
	$(".m_comments textarea[id]").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_bgray');
			$(this).val('Comment');
		}
	});
	$("#s_bar").focus(function() {
		if($(this).val() == 'First name, Last name etc...') {
			$(this).removeClass('m_nos');
			$(this).val('');
		}
	});
	$("#s_bar").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_nos');
			$(this).val('First name, Last name etc...');
		}
	});
	$("#em").focus(function() {
		if($(this).val() == 'E-mail...') {
			$(this).removeClass('m_nos');
			$(this).val('');
		}
	});
	$("#em").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_nos');
			$(this).val('E-mail...');
		}
	});
	$("#ps").focus(function() {
		if($(this).val() == 'Password...') {
			$(this).removeClass('m_nos');
			$(this).val('');
		}
	});
	$("#ps").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_nos');
			$(this).val('Password...');
		}
	});
	$(".m_photos textarea").focus(function() {
		if($(this).val() == 'Add description') {
			$(this).removeClass('m_gray');
			$(this).val('');
		}
	});
	$(".m_photos textarea").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_gray');
			$(this).val('Add description');
		}
	});
})
//Blog photos upload
function uploaded(a) {
	var ex = a.split('#');
	var file = ex[2].split('.');
	var elem = '<div class="m_photos"><div class="m_photo"><img src="/upload/blog/' + file[0] + '_50x50.' + file[1] + '" width="50" height="50" alt="" />';
	elem += '<span>remove</span><textarea class="m_gray" name="caps[]">Add description</textarea></div><input type="hidden" name="photos[]" value="' + file[0] + '.' + file[1] + '" /></div>';
	$(".m_photobar").append(elem);
	$(".m_photos span").click(function() {
		$(this).parent().parent().remove();
	});
	$(".m_photos textarea").focus(function() {
		if($(this).val() == 'Add description') {
			$(this).removeClass('m_gray');
			$(this).val('');
		}
	});
	$(".m_photos textarea").blur(function() {
		if($(this).val() == '') {
			$(this).addClass('m_gray');
			$(this).val('Add description');
		}
	});
}
function avatar(a) {
	var ex = a.split('#');
	var d = new Date(); var t = d.getTime();
	var elem = '<img src="/upload/avatars/' + ex[1] + '.jpg?' + t + '" width="120" height="120" alt="" />';
	$(".m_avatimg").html(elem);
}
function tmapp(a) {
	var ex = a.split('#');
	var d = new Date(); var t = d.getTime();
	var elem = '<img src="/upload/travelmap/' + ex[1] + '.jpg?' + t + '" width="120" height="90" alt="" />';
	$(".m_avatimg").html(elem);
}
function valid(form_id) {
	var valid = true;
	$("#" + form_id + " input[accesskey]").each(function() {
		if($(this).val() == '') {
			$(this).parent().next().html('Required field!');
			$(this).parent().next().slideDown(50);
			$(this).change(function() { $(this).parent().next().slideUp(50); })
			valid = false;
		}
	});
	return valid;
}
function valid2(form_id) {
	var valid = true;
	$("#" + form_id + " input[accesskey]").each(function() {
		if(($(this).val() == 'Your name' || $(this).val() == '') && $(this).attr('accesskey') == 'T') {
			$(this).parent().css('color', '#FF0000');
			$(this).change(function() { $(this).parent().css('color', '#CCCCCC'); })
			valid = false;
		}
		if($(this).val().trim().search(/^([a-z]+)([a-z0-9\-\_\.]{1,100})([a-z0-9]+)\@([a-z0-9]+)([a-z0-9\-\.]*)([a-z0-9]+)\.([a-z]{2,6})$/) == -1  && $(this).attr('accesskey') == 'E') {
			$(this).parent().css('color', '#FF0000');
			$(this).change(function() { $(this).parent().css('color', '#CCCCCC'); })
			valid = false;
		}
	});
	$("#" + form_id + " textarea[accesskey]").each(function() {
		if($(this).val() == 'Comment' || $(this).val() == '') {
			$(this).parent().css('color', '#FF0000');
			$(this).change(function() { $(this).parent().css('color', '#CCCCCC'); })
			valid = false;
		}
	});
	return valid;
}
function redirect(url) {
	window.location = url;
}
