


$(document).ready(function() {
   $("#search_text_input").defaultValue({});
   $('.countriesSelection a[href][title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		style: { 
			padding: 5,
			background: '#F7BB0F',
			color: '#172835',
			textAlign: 'center',
			border: {
				width: 0,
				radius: 2,
				color: '#E8AD11'
			},
			'font-weight':'bold',
			tip: 'topMiddle',
			name: 'dark' // Inherit the rest of the attributes from the preset dark style
		},
		position: {
			corner: {
				target: 'bottomMiddle',
				tooltip: 'topMiddle'
			},
			adjust: { 
				y: 2
			}			
		}
   });

});


function switch_search_to(link,url,instr)
{
	$("#search_webpage").removeClass('selected');
	$("#search_coupons").removeClass('selected');
	$(link).addClass('selected');
	$("#search_instr").html(instr);
	$("#search_form").attr("action",url);
	$("#search_text").focus();
	if (link=='#search_coupons')
	{
		$("#search_text").attr("name","coupon");
	} else {
		$("#search_text").attr("name","keywords");
	}
}

function search_enter_submit(e)
{
	var key;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	else return true;
	if (key == 13)
	{
		$("#search_form").submit();
		return false;
   }
	else return true;
}

function serverTime() { 
    var time = null; 
    $.ajax({url: '/server_time/', 
        async: false, dataType: 'text', 
        success: function(text) { 
            time = new Date(text); 
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
    return time; 
}

function showModal(s_width,s_height)
{
$("#modal").modal({
	opacity:90,
	minWidth : s_width,
	minHeight : s_height,
	onClose: function (dialog) {
		$.modal.close(); // must call this!
		$("#modal").css("display","none");
	}
});
$("#modal_close").css("display","block");
}

function tellFriendDealEmailModal()
{
	showModal(450,250);
}

function showModalAjax(s_width,s_height, ajaxURL){
	$.get(ajaxURL, function(data){
		$("#ajaxModal_content").html(data);
		try
		{
			FB.XFBML.parse(document.getElementById("#ajaxModal_content")); //parse FBML
		}
		catch(err)
		{
			alert(err);
		}
		
		$("#ajaxModal").modal({
			opacity:90,
			minWidth : s_width,
			minHeight : s_height,
			onClose: function (dialog) {
				$.modal.close(); // must call this!
				$("#ajaxModal").css("display","none");
			}
		});
		$("#ajaxModal_close").css("display","block");
	});
}

function loadContentModal(ajaxURL){
	$.get(ajaxURL, function(data){
		$("#ajaxModal_content").html(data);
		FB.XFBML.parse(document.getElementById("#ajaxModal_content")); //parse FBML
	});	
}

function registerOptions(){
	showModalAjax(450,250,'/profile/?action=registration_options');
}

function setupAccount(step){
	showModalAjax(550,480,'/welcome/?step='+step);
}

function setupRemindHide(){
	$('#setupRemind').fadeOut('slow');
	$.get("/welcome/?step=100", function(data){

	});	
}

function rewardDetails(id){
	showModalAjax(450,250,'/molo-rewards/reward_details/?id='+id);
}

function couponDetails(id){
	showModalAjax(500,350,'/coupons/details/?id='+id);
}

function androidQR(){
	$.modal.close(); // must call this!
	$("#ajaxModal").css("display","none");
	$("#modal").html('<p><b>Scan QR-Code with your mobile phone</b></p><img src="/img/qrcodes/qrcode_android.png" alt="android" /><p>Press ESC to close window.</p>');
	showModal(500, 500);
}

function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}







	