function disablePage(){
   if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}

//  document.getElementById("greypage").style.height = yWithScroll + 'px';
  showDiv("greypage",yWithScroll);
}

function enablePage(){
  hideDiv("greypage");
}

function centerDiv(id){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
 
 var top = Math.ceil((new Number(myHeight))/2 - (new Number(document.getElementById(id).style.height.slice(0, -2)))/2) + scrOfY;
 var left = Math.ceil((new Number(myWidth))/2 - (new Number(document.getElementById(id).style.width.slice(0, -2)))/2) + scrOfX;

 document.getElementById(id).style.top = top + 'px';
 document.getElementById(id).style.left = left + 'px';
}

function showDiv(id,h){
	if(h > 0){
		//document.getElementById(id).style.display = "block";
		  document.getElementById("greypage").style.height = h + 'px';
	}
	document.getElementById(id).style.visibility = "visible";
}

function hideDiv(id){
  //document.getElementById(id).style.display = "none";
    document.getElementById(id).style.height ='0px';
  document.getElementById(id).style.visibility = "hidden";
}

function favourites(fav, id, lang){
	
	$("favourites").innerHTML='<img src="/images/loading.gif" alt="" align="center">';
	url = "/includes/ajax.php?func="+fav+"&cid="+id+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("favourites").innerHTML = transport.responseText;
	  }
	});
}

function add_new_tag(lang){
	var tag = document.getElementById('tag').value;
	
	url = "/includes/ajax.autocomplete.php?type=new_tag&lang_id="+lang+"&tag="+tag;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var res = transport.responseText.split("@@@@");
	    var data = res[0];
	    var value = res[1];
	    if(data && value){
		  	var tagBox1 = document.getElementById('tag_box').innerHTML;
			var tagSpan1 = "";
			var addTagBox1 = "";
			
			if(!document.getElementById('T_'+data)) {
				var form = $('form');
				var input = form['tags_num'];
				var v = $(input).getValue();
				$(input).value = Number(v) + Number(1);
				tagSpan1 = '&nbsp;<span id="T_'+data+'" class="bit-box">'
				+'<input type="hidden" name="tag_id[]" value="'+data+'" />'
				+'<div class="fll" id="sb-iepos"><div class="sb-start"></div><div class="sb-mid"><div class="fll">'
				+value
				+'</div><div class="fll" style="margin:0 0 0 2px;"><a class="remove-s-button" onclick="remove_tag_span('+data+')">x</a></div></div><div class="sb-end"></div>     </div></span>';
			}
	        
	        document.getElementById('tag').value = "";
	        addTagBox1 = tagBox1+tagSpan1;
	        $('tag_box').update(addTagBox1);
	        document.getElementById('tag_content').value = addTagBox1;
		    //$("friend").innerHTML = transport.responseText;
		}else {
	  		document.getElementById('tag').value = "";
	  	}
	  }
	});
}

function selectCategory(param){
	var select_list_field = document.getElementById('selectCatId');
	var select_list_selected_index = select_list_field.selectedIndex;

	var text = select_list_field.options[select_list_selected_index].text;
	var value = select_list_field.value;
	
	if(text && value){
		var box = document.getElementById('box').innerHTML;
		var span = "";
		var addBox = "";
			
		if(!document.getElementById('C_'+value)) {
			
			var form = $('form');
			if(param != 'add'){
				var input = form['cats_num'];
				var v = $(input).getValue();
				$(input).value = Number(v) + Number(1);
			}
			
			span = '&nbsp;<span id="C_'+value+'" class="bit-box">'
				+'<input type="hidden" name="category_id[]" value="'+value+'" />'
				+'<div class="fll" id="sb-iepos">'
				+'<div class="sb-start">'
				+'</div><div class="sb-mid">'
				+'<div class="fll">'
				+text
				+'</div><div class="fll" style="margin:0 0 0 2px;"><a class="remove-s-button" onclick="remove_category_span('+value+')">x</a></div></div><div class="sb-end"></div>     </div></span>';
		}
        
        //document.getElementById('query').value = "";
        addBox = box+span;
        $('box').update(addBox);
        document.getElementById('category_content').value = addBox;
	    //$("friend").innerHTML = transport.responseText;
	}else {
  		document.getElementById('tag').value = "";
  	}
}

function getSubCategories(sel, langId, langCode, param){
	//var catId = sel.options[sel.selectedIndex].value;
	var catId = sel;
	//alert(catId);
	document.getElementById('subCat').innerHTML = '<div align="center" style="width:220px;"><img src="/images/loading.gif"/></div>';
	url = "/includes/ajax.php?func=subcategories&cat_id="+catId+"&lang_id="+langId+"&lang="+langCode+"&param="+param;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("subCat").innerHTML = transport.responseText;
	  }
	});
}

function hideprintable(){
  //document.getElementById(id).style.display = "none";
  document.getElementById('p_active').style.visibility = "hidden";
  document.getElementById('o_active').style.visibility = "visible";
}

function hideonline(){
  //document.getElementById(id).style.display = "none";
  document.getElementById('o_cative').style.visibility = "hidden";
  document.getElementById('p_active').style.visibility = "visible";
}

function countryRegion(sel, langCode, langId){
	//var countryCode = sel.options[sel.selectedIndex].value;
	var countryCode = sel;
	//alert(countryCode);
	url = "/includes/ajax.region.php?func=country_region&country_id="+countryCode+"&langCode="+langCode+"&langId="+langId;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    //$("region").innerHTML = transport.responseText;
		  jQuery("#region").html(transport.responseText);
	  }
	});
}

function regionCity(sel, langCode, langId){
	var regionCode = sel.options[sel.selectedIndex].value;
	url = "/includes/ajax.region.php?func=region_city&region_id="+regionCode+"&langCode="+langCode+"&langId="+langId;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("city").innerHTML = transport.responseText;
	  }
	});
}

function reportInappropriate(uri, lang){
	jQuery('#report-inappropriate').dialog({
		modal: true,
		width: 665,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	url = "/includes/ajax.php?func=report_inappropriate&uri="+uri+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("inappropriate").innerHTML = transport.responseText;
	  }
	});
}

function reportSubmit(uri, lang){
	jQuery('#report-inappropriate').dialog({
		modal: true,
		width: 665,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	var reportForm = document.getElementById('reportForm');
	
	url = "/includes/ajax.php?func=report_inappropriate&message="+reportForm.elements['message'].value+"&send="+reportForm.elements['send'].value+"&lang="+lang+"&uri="+uri;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("inappropriate").innerHTML = transport.responseText;
	  }
	});
}

function sendFriend(uri, lang){
	//centerDiv('send-friend');
	//disablePage();
	//showDiv('send-friend');
	
	jQuery('#send-friend').dialog({
		modal: true,
		width: 665,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	url = "/includes/ajax.php?func=send_friend&uri="+uri+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("friend").innerHTML = transport.responseText;
	  }
	});	
}

function friendSubmit(lang){
	//centerDiv('send-friend');
	//disablePage();
	//showDiv('send-friend');
	
	jQuery('#send-friend').dialog({
		modal: true,
		width: 665,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	var friendForm = document.getElementById('friendForm');
	/*var params = '';
	for(i=0; i<friendForm.elements.length; i++){
		params = params + '&params['+friendForm.elements[i].name+']='+friendForm.elements[i].value;
	}*/
	
	url = "/includes/ajax.php?func=send_friend&email="+friendForm.elements['email'].value+"&subject="+friendForm.elements['subject'].value+"&message="+friendForm.elements['message'].value+"&send="+friendForm.elements['send'].value+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("friend").innerHTML = transport.responseText;
	  }
	});
}

function loginSubmit(uri, lang){
	//centerDiv('login-form');
	//disablePage();
	//showDiv('login-form');
	
	jQuery('#login-form').dialog({ modal: true, width: 665 });
	jQuery('#login-form').height("180");
	var loginForm = document.getElementById('loginForm');
	
	/*var params = '';
	for(i=0; i<friendForm.elements.length; i++){
		params = params + '&params['+friendForm.elements[i].name+']='+friendForm.elements[i].value;
	}*/
	
	url = "/includes/ajax.php?func=login&uri="+uri+"&email="+loginForm.elements['email'].value+"&pswd="+loginForm.elements['pswd'].value+"&send="+loginForm.elements['send'].value+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	if(transport.responseText == 200){
	  		location.reload(true);
	  	} else {
	    	$("login-sub").innerHTML = transport.responseText;
	  	}
	  }
	});
}

function remove_advs_param(element, st, catid, shopid, city, spanId){
	
	var lang = jQuery('input[name=param6]').val();
	
	if(document.getElementById(spanId)){
		document.getElementById(spanId).style.display = "none";
	}
	try{
	url = "/includes/ajax.php?func=remove_advs_param&st="+st+"&catid="+catid+"&shopid="+shopid+"&city="+city+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var res = transport.responseText.split("******");
	  	jQuery('input:hidden[name=param2]').val(res[0]);
	  	jQuery('input:hidden[name=param4]').val(res[0]);
	  	$("advs").innerHTML = res[1];
	  	advsGetCounts(element, st, catid, shopid, city, spanId, lang);
	  	ajaxCoupons(element, 'advanced_search');
	  }
	});
	} catch(e){alert(e.message)}
}

function advsGetCounts(element, st, catid, shopid, city, spanId, lang){
	try{
		url = "/includes/ajax.php?func=advs_get_counts&st="+st+"&catid="+catid+"&shopid="+shopid+"&city="+city+"&lang="+lang;
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
		  	var res = transport.responseText.split("******");
		  	
		  	jQuery('#o_active .passive-coup-title2 .visited-coup2').html(res[1]);
	    	jQuery('#p_pasive .active-coup-title2 .visited-coup2').html(res[0]);
	    	jQuery('#p_active .active-coup-title2 .act-coup').html(res[1]);
	    	jQuery('#o_pasive .passive-coup-title2 .visited-coup2').html(res[0]);
		  }
		});
		} catch(e){alert(e.message)}
}

function printCoupon(func, cid, uid, lang){
	jQuery('#print-coupon').dialog({
		width: 665,
		modal: true,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	
	url = "/includes/ajax.print.php?func="+func+"&cid="+cid+"&uid="+uid+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("printCoupon").innerHTML = transport.responseText;
	  }
	});	
}

function removeFromFavourites(id){
	url = "/includes/ajax.php?func=remove_from_favourites&cid="+id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    location.reload(true);
	    //alert(transport.responseText);
	  }
	});
}

function sendCouponCode(func, ccode, name, id, c_url, lang){
	//centerDiv('print-coupon');
	//disablePage();
	//showDiv('print-coupon');
	jQuery('#print-coupon').dialog({width: 665,
									modal: true,
									resizable: false,
									close: removeAppendedBottom()
								   });
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	
	url = "/includes/ajax.php?func="+func+"&code="+ccode+"&cname="+name+"&cid="+id+"&c_url="+c_url+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("printCoupon").innerHTML = transport.responseText;
	  }
	});
}

function preview(id, lang){
	//centerDiv('preview-coupon');
	//disablePage();
	//showDiv('preview-coupon');
	
	jQuery('#preview-coupon').dialog({
		width: 665,
		modal: true,
		resizable: false,
		close: removeAppendedBottom()
	});
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	url = "/includes/ajax.php?func=preview_coupon&cid="+id+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(ajaxCoupons) {
	    $("previewCoupon").innerHTML = ajaxCoupons.responseText;
	  }
	});
}

function deleteCoupon(id, part, mess){
	var r = confirm(mess);
	if(r == true){
		url = "/includes/ajax.php?func=delete_coupon&cid="+id+"&from_part="+part;
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
		    location.reload(true);
		  }
		});
	}
}

function removeImage(image){
	url = "/includes/ajax.php?func=remove_image&shop_image="+image;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("shop_image").innerHTML = transport.responseText;
	    var script = '/scripts/jquery.filestyle.js';
	    jQuery.getScript( script );
	  }
	});
}

function removeCouponImage(){
	url = "/includes/ajax.php?func=remove_coupon_image";
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("coupon_image").innerHTML = transport.responseText;
	    var script = '/scripts/jquery.filestyle.js';
	    jQuery.getScript( script );
	  }
	});
}

function redir(){
	hideDiv('login-form');
	enablePage();
}

function autocomplete(){
	new Autocomplete('query', { serviceUrl: '/includes/ajax.autocomplete.php' });
}

function explode (delimiter, string, limit) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned. 
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/explode
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
  
    var emptyArray = { 0: '' };
     
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' )
    {
        return null;
    }
  
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null )
    {
        return false;
    }
  
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' )
    {
        return emptyArray;
    }
  
    if ( delimiter === true ) {
        delimiter = '1';
    }
     
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function getPaymentOptions(sel, langCode){
	var id = sel.options[sel.selectedIndex].value;
	if(id != 0){
		url = "/includes/ajax.php?func=show_payment_options&currency_id="+id+"&lang="+langCode;
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
		    $("paymentOptions").innerHTML = transport.responseText;
		  }
		});
	}
}

function payment_choice(costId){
	
	document.forms['pay_'+costId].submit();
}

function orderPayment(sel, order, langCode, p){
	if(p == 'paging'){
		var page = sel.options[sel.selectedIndex].text;
	} else {
		var page = sel;
	}
	
	url = "/includes/ajax.php?func=order_payment_table&order_by="+order+"&lang="+langCode+"&page="+page;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("orders_table").innerHTML = transport.responseText;
	  }
	});
}

function onlineCouponRadioActive(){
	document.getElementById('online_url').style.display='block';
	document.getElementById('condition-area').style.display='none';
}

function printableCouponRadioActive(){
	document.getElementById('online_url').style.display='none';
	document.getElementById('condition-area').style.display='block';
}

function pay_but(){
	if(document.form1.submit.disabled == false){
		document.form1.submit.disabled = true;
	} else {
		document.form1.submit.disabled = false;
	}
}

function changeStar(id, cid)
{
	var starName = 'rating_act.png';
	
	for(var i=1; i<=5; i++)
	{
		document.getElementById('star_empty_'+i+'_'+cid).src='/images/rating_empt.png';
	}
		
	for(var i=1; i<=id; i++)
	{
		document.getElementById('star_empty_'+i+'_'+cid).src='/images/'+starName;
	}
	return;
}

function login(uri, param, lang){
	//jQuery('body').append('<div id="login-form"></div>');
	jQuery('#login-form').dialog({ modal: true,
								   width: 665,
								   resizable: false,
								   close: removeAppendedBottom()
								 });
	jQuery('.ui-dialog').append('<div id="login-form2"></div>');
	jQuery('#login-form').height("150");
	
	//centerDiv('login-form');
	//disablePage();
	//showDiv('login-form');
	jQuery(this).focus();
	url = "/includes/ajax.php?func=login&uri="+uri+"&param="+param+"&lang="+lang;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    $("login-sub").innerHTML = transport.responseText;
	  }
	});
}

function removeAppendedBottom(){
	jQuery('#login-form2').remove();
}

function voting(rate, id, changeData, voteOnlyOnce, thanksForVoting, langCode, R_URI, siteURL, accountTypeDiscrepancy, downloadCouponFirst){
	var div = "div_voting_"+id;
	url = "/includes/ajax.voting.php?func=vote&rate="+rate+"&id="+id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	if(transport.responseText == 0){
	  		login(R_URI, "", langCode);
	  	} else if(transport.responseText == 1){
	  		location.href=siteURL+"/"+langCode+"/profile/"+changeData;
	  	} else if(transport.responseText == 2){
	  		jQuery('#voting-alert').dialog({
	  			width: 665,
	  			modal: true,
	  			resizable: false,
	  			close: removeAppendedBottom()
	  		});
	  		jQuery('.ui-dialog').append('<div id="login-form2"></div>');
			document.getElementById('voteAlert').innerHTML = '<div>'+voteOnlyOnce+'</div>'
			+'<div style="margin:20px auto;width:70px">'
    		+'<div class="s-btn" >'
      		+'<input type="submit" value="OK" class="s-btn-sub1" name="send" onclick="closeDialog('+"'voting-alert'"+'); enablePage();" />'
    		+'</div>'
			+'</div>';
	  	} else if(transport.responseText == 3){
	  		jQuery('#voting-alert').dialog({
	  			width: 665,
	  			modal: true,
	  			resizable: false,
	  			close: removeAppendedBottom()
	  		});
	  		jQuery('.ui-dialog').append('<div id="login-form2"></div>');
			document.getElementById('voteAlert').innerHTML = '<div>'+accountTypeDiscrepancy+'</div>'
			+'<div style="margin:20px auto;width:70px">'
    		+'<div class="s-btn" >'
      		+'<input type="submit" value="OK" class="s-btn-sub1" name="send" onclick="closeDialog('+"'voting-alert'"+'); enablePage();" />'
    		+'</div>'
			+'</div>';
	  	} else if(transport.responseText == 4){
	  		jQuery('#voting-alert').dialog({
	  			width: 665,
	  			modal: true,
	  			resizable: false,
	  			close: removeAppendedBottom()
	  		});
	  		jQuery('.ui-dialog').append('<div id="login-form2"></div>');
			document.getElementById('voteAlert').innerHTML = '<div>'+downloadCouponFirst+'</div>'
			+'<div style="margin:20px auto;width:70px">'
    		+'<div class="s-btn" >'
      		+'<input type="submit" value="OK" class="s-btn-sub1" name="send" onclick="closeDialog('+"'voting-alert'"+'); enablePage();" />'
    		+'</div>'
			+'</div>';
	  	} else {
	  		jQuery('#voting-alert').dialog({
	  			width: 665,
	  			modal: true,
	  			resizable: false,
	  			close: removeAppendedBottom()
	  		});
	  		jQuery('.ui-dialog').append('<div id="login-form2"></div>');
			document.getElementById('voteAlert').innerHTML = '<div>'+thanksForVoting+'</div>'
			+'<div style="margin:20px auto;width:70px">'
    		+'<div class="s-btn">'
      		+'<input type="submit" value="OK" class="s-btn-sub1" name="send" onclick="closeDialog('+"'voting-alert'"+'); enablePage();" />'
    		+'</div>'
			+'</div>';
		  	var res = transport.responseText.split("@@@@");
		    $(div).innerHTML = res[0];
		    $("voting_stat").innerHTML = res[1];
		    //location.reload(true);
	  	}
	  }
	});
}

function ajaxCoupons(e, couponType)
{	
	try{
	var param  = jQuery('input[name=param]').val();
	var param2 = jQuery('input[name=param2]').val();
	var page   = '';
	var param3 = jQuery('input[name=param4]').val();
	var URL_1 = jQuery('input[name=param5]').val();
	var lang = jQuery('input[name=param6]').val();
	
	disablePage();
	if(jQuery(".curSortBy").length){
		var sortById = jQuery(".curSortBy > ul > li").attr("id");
		var orderType = jQuery(".curSortBy > ul > li > img").attr("id");
		var sortBy = 'coupons.'+sortById.replace("sort_", "")+orderType.replace("sort-", " ").toUpperCase();
	} else {
		var sortBy = "coupons.startdate DESC";
	}	
	
	if(page){
		var curpage = page;
	} else {
		var curpage = 1;
	}
	$("coupons_div").innerHTML= '<div id="loader">'
	+'<div class="load-ltop"></div>'
	+'<div class="load-toprep"></div>'
	+'<div class="load-rtop"></div>'
	+'<div class="load-contrep">'
    +'<img src="/images/loading.gif" alt="" align="center">'
    +'</div>'
	+'<div class="load-lbot"></div>'
    +'<div class="load-botrep"></div>'
	+'<div class="load-rbot"></div>'
	+'</div>';
	
	
	if(couponType == 'online')
	{
		jQuery('#p_active').css("display", "none");
		jQuery('#p_pasive').css("display", "block");
		jQuery('#o_active').css("display", "block");
		jQuery('#o_pasive').css("display", "none");
	}
	else if(couponType == 'printable')
	{
		jQuery('#p_active').css("display", "block");
		jQuery('#p_pasive').css("display", "none");
		jQuery('#o_active').css("display", "none");
		jQuery('#o_pasive').css("display", "block");
	}
	else if(couponType == 'sort')
	{
		sortById = e.id;
		
		if(orderType == "sort-desc"){
			var img = '<img id="sort-asc" src="/images/sort_by_arr.gif" style="padding-left:4px;" alt="" title="" />';
		} else {
			var img = '<img id="sort-desc" src="/images/sort_by_asc_arr.gif" style="padding-left:4px;" alt="" title="" />';
		}
		
		sortBy = sortById + orderType.replace("sort-", " ").toUpperCase();
		if(sortById == 'rating'){
			sortBy = sortBy + ', votes' + orderType.replace("sort-", " ").toUpperCase();
		}
		
		var sortContent = e.innerHTML + img;
		jQuery(".curSortBy > ul > li").eq(0).attr("id", "sort_"+sortById).html(sortContent);
	} 
	else if (couponType == 'paging')
	{
		if(e.id == "next-page"){
			curpage = e.name.replace("page-", "");
		}
		else if(e.id == "prev-page"){
			curpage = e.name.replace("page-", "");
		} else {
			curpage = e.innerHTML;
		}
	}
	else if(couponType == 'advanced_search')
	{
		
	}
	
	var tabCss1 = jQuery("#p_pasive").css("display");
	var tabCss2 = jQuery("#p_active").css("display");
	if(tabCss1 == 'none' && tabCss2 == 'none')
		var cType = 'both';
	else if(tabCss1 == 'block')
		var cType = 'online';
	else if(tabCss2 == 'block')
		var cType = 'printable';
	
	url = "/includes/ajax.coupons.php?func="+cType+"_coupons&param="+param+"&param2="+param2+"&page="+curpage+"&param3="+param3+"&URL_1="+URL_1+"&lang="+lang+"&sort="+sortBy;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	enablePage();
	    var res = transport.responseText.split("*****");
	    //$("coupons_div").innerHTML = res[0];
	    jQuery("#coupons_div").html(res[0]);
	    $("paging").innerHTML = res[1];
	  }
	});	
	
	} catch(err){
		alert(err);
	}
}



function hideGrayPopup(){
	document.getElementById("window").style.display = "none";
	document.getElementById("greypage").style.display = "none";
}


function showstuff(boxid){
	document.getElementById(boxid).style.visibility="visible";
}

function hidestuff(boxid){
	document.getElementById(boxid).style.visibility="hidden";
}

function slide(){
  jQuery('#simpleNext').click();
}

//On user click deactivate auto-scrolling
jQuery('#previous, #simpleNext').click(function(){
  window.clearInterval(intervalId);
});

	
var plugin_exists = true;

jQuery(document).ready(function(){
	var footHeight = jQuery('#footer').height();
	
	jQuery('#container').css('padding-bottom', footHeight);
	
	if(jQuery(".tooltip-target").length)
	{
		jQuery(".tooltip-target").ezpz_tooltip({
			showContent: function(content) {
				content.fadeIn('slow');
			},
			hideContent: function(content) {
				// if the showing animation is still running, be sure to stop it
				// and clear the animation queue. otherwise, repeatedly hovering will
				// cause the content to blink.
				content.stop(true, true).fadeOut('slow');
			}
		});
		
		if(jQuery("#current-page").length){
			var curCtrlPanelPage = jQuery("#current-page").html();
			if(curCtrlPanelPage == "shop_copy_coupon" || curCtrlPanelPage == "add_coupon"){
				Zapatec.Calendar.setup({
					 inputField : "enddate", // id of the input field
					 button : "showCal", // What will trigger the popup of the calendar
					 showsTime : false, //no time
					 dateStatusFunc : disallowDateBefore, //the function to call
					 onUpdate : null,
					 ifFormat:"%d/%m/%Y"
				});
			}
		}
		
		var lang = jQuery('input:hidden[name=currentLangId]').val();
		
		new Autocomplete('tag', { serviceUrl: '/includes/ajax.autocomplete.php?type=tag&lang='+lang,
			onSelect: function(value, data){
				var tagBox = document.getElementById('tag_box').innerHTML;
				var tagSpan = "";
				var addTagBox = "";
				
				if(!document.getElementById('T_'+data)) {
					if(jQuery("#c_id").length){
						var form = $('form');
						var input = form['tags_num'];
						var v = $(input).getValue();
						$(input).value = Number(v) + Number(1);
					}
					tagSpan =  '&nbsp;<span id="T_'+data+'" class="bit-box">'
					+'<input type="hidden" name="tag_id[]" value="'+data+'" />'
					+'<div class="fll" id="sb-iepos"><div class="sb-start"></div><div class="sb-mid"><div class="fll">'
					+value
					+'</div><div class="fll" style="margin:0 0 0 2px;"><a class="remove-s-button" onclick="remove_tag_span('+data+')">x</a></div></div><div class="sb-end"></div>     </div></span>';
				}
		        
		        document.getElementById('tag').value = "";
		        addTagBox = tagBox+tagSpan;
		        $('tag_box').update(addTagBox);
		        document.getElementById('tag_content').value = addTagBox;
		        
		      }
		});
		
		jQuery('select[name=top_category]').change(function(){
			var langCode = jQuery('input:hidden[name=langCode]').val();
			var langId = jQuery('input:hidden[name=langId]').val();
			var category = jQuery('select[name=top_category]').val();
			
			getSubCategories(category, langId, langCode, 'add');
		});
	}
	if(jQuery('#viewport').length){
		jQuery('#viewport').show();
		if(jQuery('#simpleNext').length){
			jQuery('#viewport').carousel('#simplePrevious', '#simpleNext');
			//Launch the scroll every 4 seconds
			var intervalId = window.setInterval(slide, 4000);
		
			jQuery('#viewport ul').mouseover(
				function(){
					window.clearInterval(intervalId);
				}
			);
			jQuery('#viewport ul').mouseout(
				function(){
					intervalId = window.setInterval(slide, 4000);
				}	
			);
		}
	}
	
	jQuery('.category-bg').mouseover(function(){
		jQuery(this).children('.category-bg1').removeClass('category-bg1').addClass('category-bg1_green');
		jQuery(this).children('.category-bg2').removeClass('category-bg2').addClass('category-bg2_green');
		jQuery(this).children('.category-bg3').removeClass('category-bg3').addClass('category-bg3_green');
	});
	
	jQuery('.category-bg').mouseout(function(){
		jQuery(this).children('.category-bg1_green').removeClass('category-bg1_green').addClass('category-bg1');
		jQuery(this).children('.category-bg2_green').removeClass('category-bg2_green').addClass('category-bg2');
		jQuery(this).children('.category-bg3_green').removeClass('category-bg3_green').addClass('category-bg3');
	});
	
	jQuery('.sub-cat-list').mouseover(function(){
		jQuery(this).next().css('visibility', 'visible');
	});
	jQuery('.sub-cat-list').mouseout(function(){
		jQuery(this).next().css('visibility', 'hidden');
	});
	
	jQuery('.curSortBy').click(function(){
		jQuery('.sortListBy').slideToggle('slow');
	});
	
	jQuery('.tag-coupon').mouseover(function(){
		jQuery(this).children('.flr').children('.tag-coupons-num').css('background', '#f7f2e3');
	});	
	
	jQuery('.tag-coupon').mouseout(function(){
		jQuery(this).children('.flr').children('.tag-coupons-num').css('background', 'none');
	});
	
	jQuery('.shop-text-box').mouseover(function(){
		jQuery(this).children('.amt').css('background', '#f7f2e3');
	});	
	
	jQuery('.shop-text-box').mouseout(function(){
		jQuery(this).children('.amt').css('background', 'none');
	});
	
	jQuery('#country').change(function(){
		var langCode = jQuery('input[name=curLangCode]').val();
		var langId = jQuery('input[name=curLangId]').val();
		var sel = jQuery('#country').val();
		countryRegion(sel, langCode, langId);
	});
	
	jQuery(".coup-img").live('mouseover', function(){
		jQuery(this).children(".s-btn2").css("visibility", "visible");
	});
	
	jQuery(".coup-img").live('mouseout', function(){
		jQuery(this).children(".s-btn2").css("visibility", "hidden");
	});
})


function selectLang()
{
	jQuery('#div_needs').slideToggle('slow');
}

function remove_category_span(id){
	$('C_'+id).remove();
	document.getElementById('category_content').value = document.getElementById('box').innerHTML;
	//document.getElementById(id).style.display = 'none';
}

function remove_tag_span(id){
	$('T_'+id).remove();
	document.getElementById('tag_content').value = document.getElementById('tag_box').innerHTML;
}

function closeDialog(contentId){
	jQuery('#'+contentId).dialog("close");
}

function remove_ajax_tag_span(id){
	var form = $('form');
	var input = form['tags_num'];
	var v = $(input).getValue();
	var c_id = document.getElementById('c_id').value;
	var removedTgs = form['removed_tags'].value;
	
	url = "/includes/ajax.php?func=remove_coupon_tag&tagid="+id+"&c_id="+c_id+"&v="+v;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	if(transport.responseText == 1){
	  		alert(jQuery("tags-notification").html());
	  	}else{
	  		$('T_'+id).remove();
	  		document.getElementById('removed_tags').value = removedTgs+','+id;
	  		$(input).value = Number(v) - Number(1);
			document.getElementById('tag_content').value = document.getElementById('tag_box').innerHTML;
	  	}
	  }
	});
}

function remove_ajax_category_span(id){
	var form = $('form');
	var input = form['cats_num'];
	var v = $(input).getValue();
	var c_id = document.getElementById('c_id').value;
	var removedCats = form['removed_categories'].value;
	
	url = "/includes/ajax.php?func=remove_coupon_category&catid="+id+"&c_id="+c_id+"&v="+v;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	if(transport.responseText == 1){
	  		alert(jQuery("categories-notification").html());
	  	}else{
	  		$('C_'+id).remove();
	  		document.getElementById('removed_categories').value = removedCats+','+id;
	  		$(input).value = Number(v) - Number(1);
			document.getElementById('category_content').value = document.getElementById('box').innerHTML;
	  	}
	  }
	});
}





