//<![CDATA[
$(document).ready(function() {
	
	//var loader = jQuery("#loader");

	//end progress bar
	jQuery().ajaxStart(function() {
		//loader.show();
		$('#result').hide('slow');		
	}).ajaxStop(function() {
		//loader.hide();
	}).ajaxError(function(a, b, c) {
		//loader.hide();
		alert("myError 1: " + a + ", 2: " + b+ ", 3: " + c );
	});
	//end progress bar

			
	jQuery('#countryout').keyup(function(){	
		var addy = $(this).attr("value");
		var inx = addy.indexOf("#")
		var cod = addy.substring(0,inx)
		$(".ccode").html("+"+ cod);
	});

	jQuery('#countryout').change(function(){	
		var addy = $(this).attr("value");
		var inx = addy.indexOf("#")
		var cod = addy.substring(0,inx)
		$(".ccode").html("+"+ cod);
	});
	
	jQuery('#category').keyup(function(){	
		var addy = $(this).attr("value");
		if(addy == "Others"){
			$('#othercat').fadeIn("normal");
		}else{
			$('#othercat').fadeOut("normal");
		}
	});

	jQuery('#category').change(function(){	
		var addy = $(this).attr("value");
		if(addy == "Others"){
			$('#othercat').fadeIn("normal");
		}else{
			$('#othercat').fadeOut("normal");
		}
	});
	
	//start date
	jQuery(function($){$(".dateinput").attachDatepicker();});
	//end date
	
	//start select val
	$.metadata.setType("attr", "validate");
	//end select val

	//start accordion
	jQuery('#sidebar').accordion({
	active: '.selected',
	header: '.box_title',
	autoheight: false,        //true
	event: 'click', //click/mouseover
	selectedClass: 'active',
	animated: 'easeslide'     //easeslide/bounceslide/false		
	});
	//end accordion

	//start validation

	var v = jQuery('#form').validate();
	//end validation

	//START page loader 4
	/* This block handles requests with respect to the type of link */
	$('a.deta').click(
		function(){	
			var addy = $(this).attr("url");
			var vali = $(this).attr("vali");
			var tit = $(this).attr("tit");
			//alert("hi ady : " + addy + " val: " + vali + " title : "+ tit );
			$('#detale').fadeOut("normal");
			jQuery('#detale').load(addy,{ ido : vali, title: tit },function(){
				$('#detale').fadeIn("normal");
				return false;
			});
			return false;
		}
	);
	/* This block handles requests with respect to the type of link */
	//end page loader 4

	//START page loader
	/* This block handles requests with respect to the type of link */
	$('a.trg').click(
		function(){	
		
			var addy = $(this).attr("url");
			var vali = $(this).attr("vali");
			var usr = $(this).attr("usr");

			$('#detale').fadeOut("normal");
			jQuery('#detale').load(addy,{ valy : vali , user : usr },function(){
				$('#detale').fadeIn("normal");
				return false;
			});
			return true;
		}
	);
	/* This block handles requests with respect to the type of link */
	//end page loader

	//delete processor
	var linkclasslog = "";
	jQuery('.linkclass').change(function(){	
		var addy = $(this).attr("id");
		linkclasslog = linkclasslog+ parseInt(addy)  + "_" ;
	});
	
	jQuery('#linkdellog').click(function(){	
		var len = linkclasslog.length - 1;
		if(linkclasslog.length==0){ alert("Please specify the Offers you want to delete."); return false; }
		var finallinkclasslog = linkclasslog.substring(0,len);
		//alert("spec : "+finallinkclasslog);
		var originaldeladdy = "";
		originaldeladdy = $(this).attr("href");
		//alert("original href : "+originaldeladdy);
		$(this).removeAttr("href");
		//alert("empty href : "+$(this).attr("href"));
		$(this).attr("href", originaldeladdy+"?AgC9HnVUXCHh5cy5iSQuIhqbvZx4_SIG="+finallinkclasslog);
		//alert("full href : "+ $(this).attr("href"));
		return true;
	});
	//delete processor
	
	//START Visit
	$('._visited').click(function(){	
			var addy = $(this).attr("url");
			var valun = $(this).attr("vali");
			//alert("Addy : "+ addy + ",  ID :"+ valun );
			$('#rater').load(addy, { offer_id : valun } , function(){ /*alert("Thanks for Visiting!");*/ });
			return true; // <-- important
	});	
	//end Visit
	
});
//]]>