/****************************************
 * Neoland
 * Global JavaScript
 ****************************************/

// Start closure to prevent namespace conflicts
;(function($) {

// Perform initial setup tasks when DOM is ready
$(document).ready( function() {
	$(".topMenuAction").click(function () {
			if ($("#openCloseIdentifier").is(":hidden")) {
				$("#topslider").animate({ 
					marginTop: "-137px"
					}, 500 );
				$("#topMenuImage-close").hide();
				$("#topMenuImage").show();
				$("#openCloseIdentifier").show();
			} else {
				$("#topslider").animate({ 
					marginTop: "0px"
					}, 500 );
				$("#topMenuImage").hide();
				$("#topMenuImage-close").show();
				$("#openCloseIdentifier").hide();
			}
		});  
	// ----------------------------------------------	
	            $("#topMenuImage-close").hide();
	 
    	        $(".HiddenRows").each(function() {
				  $(this).hide();
												});

    	        $('.HiddenRowsNotice').each(function() {
				  $(this).click( function() {
    	            $(this).prev('div').slideToggle("fast");	
					changeimgsrc($(this));
					
    	        });
												});
	// ----------------------------------------------					
		
	$('#logout').click(
		function(e){
		e.preventDefault();
		
        $('<div id="confirmLogout" title="Logout?">Sunteti sigur ca doriti deconectarea?</div>').dialog(
			{
			modal: true,
			resizable: false,
			height: 150, 
			width:350,
			show:"blind",
			hide: "blind",
			buttons:{
				"Da":function() {
					$.ajax({ 
						url: Path+'logout.php', 
						complete: function() {
							$('#confirmLogout').html("Va multumim ca ati ales Neoland. La revedere!");
							$('.ui-dialog-buttonpane').css('display','none');
							var dlg = $("#confirmLogout").parents(".ui-dialog:first");
							dlg.animate({ width: 200},50);
							setTimeout(function(){$("#confirmLogout").dialog("close")},3000);
							setTimeout(function(){window.open(Path,'_self');},1500);	
							
							} 
						});
					},
				"Nu":function() {
					$("#confirmLogout").dialog("close");
					}
			},
			close:function(){
				 $("#confirmLogout").remove();
			}
			});

        return false; 
	});
   // ----------------------------------------------
	
	// ----------------------------------------------					
		
	$('#logout_out').click(
		function(e){
		e.preventDefault();
		
        $('<div id="confirmLogout" title="Logout?">Sunteti sigur ca doriti deconectarea?</div>').dialog(
			{
			modal: true,
			resizable: false,
			height: 150, 
			width:350,
			show:"blind",
			hide: "blind",
			buttons:{
				"Da":function() {
					$.ajax({ 
						url: Path+'logout.php', 
						complete: function() {
							$('#confirmLogout').html("Va multumim ca ati ales Neoland. La revedere!");
							$('.ui-dialog-buttonpane').css('display','none');
							var dlg = $("#confirmLogout").parents(".ui-dialog:first");
							dlg.animate({ width: 200},50);
							setTimeout(function(){$("#confirmLogout").dialog("close")},3000);
							setTimeout(function(){window.open(Path,'_self');},1500);	
							} 
						});
					},
				"Nu":function() {
					$("#confirmLogout").dialog("close");
					}
			},
			close:function(){
				 $("#confirmLogout").remove();
			}
			});

        return false; 
	});
   // ----------------------------------------------
				
	// ----------------------------------------------		
			$('.columnEqual').equalHeight();
    // ----------------------------------------------	
	
	
	          $('a[href^=#tabs-]').click(
		      function(){
			  
			 href_tot = $(this).attr('href');
			 href = href_tot.substring(6, href_tot.length);
			 window.open(Path+href+'-categorii/','_self')
			// console.log(Path+href+'-categorii/');
			  
			  });
	
/*	place1stflash();*/
	
	


});

/*
$(function() {
$("#at-zbounce").click(function() {
$("#zbounce").effect("highlight");
           });
$("#at-ybounce").click(function() {
$("#zbounce").effect("highlight");
           });
           });
*/

// Set up main navigation mouseover menus


function changeimgsrc(div) {
	 var $img = div.find('img.menumoore');
     var src = $img.attr('src');
     var newsrc = /menu-plus\.png$/.test(src) ? src.replace('menu-plus','menu-minus') : src.replace('menu-minus','menu-plus');
     $img.attr('src',newsrc);
	
	}

/*function place1stflash() {
	$('#innerflash').flash(
        { src: Path+'swf/test.swf',
          width: 820,
          height: 290,
		  wmode: 'transparent'
		  },
        { version: 9 }
    );
	}*/

// End closure

								  
								  
})(jQuery);

function myencode(enc) {
enc2 = encodeURIComponent(enc);
enc3 = enc2.replace(/%2F/g, "%252F");
return(enc3);
	}

function alert_x(msg) {
		 $('<div id="alert" title="Alerta!">'+msg+'</div>').dialog({
			bgiframe: true,
			modal: true,
			width: 420,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}


function setLocation(url){
 window.location.href = url;
}

function setPLocation(url, setFocus){
 if( setFocus ) {
 window.opener.focus();
 }
 window.opener.location.href = url;
}

function empty(field)
{
   if(field == "")
   {
      return(true);
   }
   else
   {
      return(false);
   }    
}

function sendcautare(frm){
var _x=frm.keyword.value;
var _exp1 = new RegExp(/^[a-z0-9 _.\+-\/\\]*$/i); /* any non space */
var _test=_exp1.test(_x);
if(!_test && _x.length!=0 && _x!='') {alert_x("textul cautat nu este de tipul [a-z] [A-Z] [0-9]"); return false; frm.keyword.focus();}
else {
queryString="";
var numberElements = frm.elements.length;
for(var i = 0; i < numberElements; i++) {
if(i < numberElements-1) {
if(frm.elements[i].type != "submit"){	
if(frm.elements[i].type == "checkbox"){if(frm.elements[i].checked){queryString +=frm.elements[i].name+"/" + myencode(frm.elements[i].value)+"/";}}
else {
if(!empty(frm.elements[i].value) && !empty(frm.elements[i].name)) {queryString += frm.elements[i].name+"/" + myencode(frm.elements[i].value)+"/";}
}
}
} else {
if(frm.elements[i].type != "submit"){	
if(frm.elements[i].type == "checkbox"){if(frm.elements[i].checked) {queryString += frm.elements[i].name+"/" + myencode(frm.elements[i].value)+"/";}}
else {
if(!empty(frm.elements[i].value) && !empty(frm.elements[i].name)) {queryString += frm.elements[i].name+"/" + myencode(frm.elements[i].value)+"/";}
}
}
}
}
//alert(queryString);
document.location.href=Path+'cautare/'+queryString;
return false;
}
}

function request_update_comanda_inex (what, where) {
	if ( (what != '') && (where != '') )

        $('#'+where).load(Path+'_procescomandainex.php?getSection=' + what  , {forcePost:1})
		$('#'+where+'-alert').html('');
	//	console.log($('#mainmodules'));

}

function post_form_inex (what_type, what_to, what_prod, comofcomid) {
   switch (what_type) {
		
		case 'trimite_comanda':
				
	msg_alert = '';
	send_form = 'true';

 if (!isValidEmailAddress($('#qtyi').val())) {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati adresa de email!';
	}

	if ($('#qtzi').val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati nr. de telefon!';
	}
	
		if ($('#qtki').val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va introduceti nume produs sau descriere produs!';
	}

	
	if (send_form == 'true') {
		//submit form
         $.ajax({type: 'POST', url: Path+'_procescomandainex.php', data: $('#'+what_to).serializeArray(), success: update_comanda_inex});
		}
		
		else { alert_x(msg_alert); }
	return false;


		break;

	}
}

function update_comanda_inex(returned_response) {
		//console.log('trece');
		if(returned_response=='') {
		request_update_comanda_inex('comanda_trimisa', 'produs-comanda-diff');
		
		}
		
		else {
		obj = document.getElementById('produs-comanda-diff-alert');
		obj.innerHTML = returned_response;
	}
		
}



function isValidEmailAddress(emailAddress) {

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

return pattern.test(emailAddress);

}
