/**
 * jQuery timeout
 * Example: $('.notice').fadeIn().idle(2000).fadeOut('slow'); 
 */
(function($){$.fn.idle=function(k){var o=$(this);o.queue(function(){setTimeout(function() {o.dequeue();},k);});return this;}})(jQuery);
/**
 * jQuery redirect 
 * Example: $('.notice').redirect('http://www.example.com');
 */
(function($){$.fn.redirect = function(k){setTimeout(function(){window.location = k;}, '2500');return null;}})(jQuery);
jQuery(document).ready(function(){
    if (jQuery('#loginform').length > 0) {
		var v = jQuery('#loginform').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					url			: ajaxurl + Math.random(),
					clearForm	: true, 
					success		: function(responseText, statusText){
						var json = eval("(" + responseText + ")");
                        if (json.success === true) {
							if (json.code == '1') {
								jQuery('#ajax-result').redirect('http://www.expertgaz.ro/parteneri/informatii-partener/');
							} 
							jQuery('#ajax-result').html(json.msg).fadeIn().idle(2000).fadeOut('slow');
						} else {
							v.resetForm();
						}	  
					}
				});
			}
		});
    }	
});

jQuery(document).ready(function() {	

	//select all the a tag with name equal to modal
	jQuery('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = jQuery(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		jQuery('#mask').fadeIn(1000);	
		jQuery('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		jQuery('#mask').hide();
		jQuery('.window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});			
});
//this, 'getLevel1', this.value
function check(oEl, sAction, iValue){
	if(iValue != '#'){
		jQuery.ajax({ url: ajaxurl + Math.random(), type:'POST', data: "action=" + sAction + "&ID=" + iValue,
			success: function(msg){
				//console.log(jQuery(oEl).find('tr:eq(1)'));
				jQuery(oEl).find('tr:eq(1)').remove();
				jQuery(oEl).append("<tr><td valign=\"top\" align=\"right\"><label for='judet'>Oras:</label></td><td valign=\"top\" align=\"left\"><select name='localitati' id='localitati'>"+ msg +
				"</select><br/><br/><input id=\"form_reset_button\" type='button' class='btn' value='Reseteaza' /></td></tr>");
				jQuery('#form_reset_button').bind('click', function(){
					jQuery(oEl).find('tr:eq(1)').remove();
					jQuery(oEl).find('tr:eq(0)').val('#');
					jQuery('#response').html('');
				});
				jQuery('#localitati').bind('change', function(i){
					if(jQuery('#localitati').val() != '#'){
						jQuery.ajax({ url: ajaxurl + Math.random(), type:'POST', data: "action=getLevel2&ID=" + jQuery(this).val(),
							success : function(msg) {
								jQuery('#response').html('<p>'+ msg +'</p>');
							}
						});
					}
				});
			}
		});
	}
}