 /////// Global extensions on strings///////////////
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
///////////////////////////////////

$(document).ready(function() { 
						   
						   
 ///////////////////// DEFAULT MODAL REGISTER EVENTS///////////////					   
/*
		$("#dialog_login").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 360,
			width: 690,
			resizable: false,
			modal: true,
			buttons: {
				Anuleaza: function() {
					$(this).dialog('close');
				},
				Autentificare: function() {
					$("#login_form").submit();
				}				
			}
		});
		
		$('#login_link').click(function() {
			$('#dialog_login').dialog('open');
		});
		
		$("#register_dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 650,
			width: 700,
			resizable: false,
			modal: true
		});
		
		$('#register_link').click(function() {
			$('#register_dialog').dialog('open');
		});	 */	
///////////////////////////////////////////////////////////////////////////////////////////////

	var options = { 
        beforeSubmit:  validate,  
        success:       showResponse  
        }; 
    var options_avatar = { 
	    beforeSubmit:  testavatar,  
        success:  showavatar  
        }; 
     var options_crop = { 
        success:  updateCroppedImage  
        }; 
	var options_friend_request = { 
	    beforeSubmit:  validateFriendRequest,  
        success:       showFriendRequestResponse  
    }; 
   var options_pending_friends = { 
        beforeSubmit:  validatePendingFriends,  
        success:        pendingFriendsResponse  
    }; 
    	var options_comment = { 
       // target:        '#comments',   
        beforeSubmit:  validateCommentForm,  
        success:       showCommentResponse,  
	    clearForm: true	
    }; 

	   var options_login = { 
        beforeSubmit:  validateLoginForm,  
        success:        LoginResponse  
    }; 

		   var options_add_favorite = { 
       // beforeSubmit:   validateLoginForm,  
        success:        AddFavoriteResponse  
    }; 
        var options_form_trimite = { 
        beforeSubmit:   validateFormTrimite,  
        success:        succesFormTrimite  
    }; 
// BEGIN SLIDER //
			$(".btn-slide").click(function(){
			$("#panel").slideToggle("slow");
			$(this).toggleClass("active"); return false;
			});
			$(".btn-slide2").click(function(){
			$("#panel").slideToggle("slow");
			$(".btn-slide").toggleClass("active"); return false;
			});
// END SLIDER //


// BEGIN LINK FUNCTIONS //
function removehref() {
	   return false;
	} 
///	$('a#post_comment_form').click(removehref); 
//$('a#nr_comentarii').click(removehref); 
	$("#post_comment_form").click(function() {
	$(".hidden#post_comment").slideToggle("slow");
	$(this).toggleClass("active"); return false;
	});
	$("#nr_comentarii").click(function() {
	$(".hidden#comment_item").slideToggle("slow");
	$(".hidden#comment_spacer").slideToggle("slow");
	$(this).toggleClass("active"); return false;
	});	
// END LINK FUNCTIONS //

// BEGIN FORM FUNCTIONS //
	        $("#loading").ajaxStart(function(){
           $(this).show("slow"); 
			//$("#listaproduse").fadeOut("fast");
			$("#listaproduse").animate({opacity:0.30});
			$("#lista_produse_friends").animate({opacity:0.30});
            });
	        $("#loading").ajaxStop(function(){
            $(this).hide("slow"); 
			//$("#listaproduse").fadeIn("slow");
		$("#listaproduse").animate({opacity:1});
			$("#lista_produse_friends").animate({opacity:1});
            });		
    ///// for spry pannels there is more then one loading pages///////////////////////////	
		  $("#loading2").ajaxStart(function(){
          $(this).show("slow"); 
		//$("#listaproduse").fadeOut("fast");
			$("#lista_produse_self").animate({opacity:0.30});
            });
		    $("#loading2").ajaxStop(function(){
            $(this).hide("slow"); 
			//$("#listaproduse").fadeIn("slow");
			$("#lista_produse_self").animate({opacity:1});
            });		
		///////////////////////////////////////////////////////////////////////////////////////////////	
			$('#friend_request_form').ajaxForm(options_friend_request);
            $('#my_newsletter').ajaxForm(options);
			$('#send_comment').ajaxForm(options_comment);
			$('#login_form').ajaxForm(options_login);
			$("#guru_crop_form").ajaxForm(options_crop);
			$('#upload_avatar').ajaxForm(options_avatar);
			$('#form_trimite').ajaxForm(options_form_trimite);
			$('#add_to_favorite').ajaxForm(options_add_favorite);
			$('#pending_friends').ajaxForm(options_pending_friends);
			$('#send_comment_store').ajaxForm(options_comment); 
	//// delete elements from favorite \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\		
			$( ".test" ).each(
		  	function( intIndex ){
					   $( this ).bind ("click",function(){
						 if(customConfirm(this.id,'favorite')==true){								
                           $(this).parents("#produsblock").animate({ opacity: 'hide' }, "slow");;
						     doAjax("pages/jq_delete_page.php","id="+this.id);
                                   }
							   	}
                              );

                             }

                            );

	////////////////////////// end delete \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

	//// creaza garderopa incepand de la un produs favorit \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\		
			$( ".creaza	" ).each(
			  	function( intIndex ){
					   $( this ).bind ("click",function(){
						 if(customConfirm(this.id,'favorite_add')==true){								
                             doAjax("pages/jq_favorite_page.php","start_tinuta="+this.id);
                                      }
							    	}
                                 );
                              }
                       );

	////////////////////////// end delete \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

	
		//// delete elements from friends \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\		

		$( ".sterge_prieten" ).each(
			  	function( intIndex ){
					   $( this ).bind ("click",function(){
		                  if(customConfirm(this.id,'friends')==true){		
                           $(this).parents(".prieten").animate({ opacity: 'hide' }, "slow");;
						           doAjax("pages/jq_delete_friend_page.php","id="+this.id);
						              }
                                    }
                                );
                          }

                    );

	////////////////////////// end delete \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

	
		//// delete tinuta \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\		
			$( ".tinuta_cancel" ).each(
			  	function( intIndex ){
					   $( this ).bind ("click",function(){
		                  if(customConfirm(this.id,'tinuta_delete')==true){		
                           $(this).parents(".item").animate({ opacity: 'hide' }, "slow"); 
                                    doAjax("pages/jq_delete_page.php","id_tinuta="+this.id);
					             }
                             }
             );

             }

         );

	////////////////////////// end delete \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        }); 
function doRefresh()
{
	window.location.reload();
	}
//////// INITIATE A AJAX TRANSACTION /////////////////////////////////
function doAjax($url,$params)
{ 
$.ajax({
   url: $url,
   type: "POST",
   data: $params,
   success:function($msg)	
    { 
 	 if($msg.indexOf("*delete*")!=-1)
	 { // on delete 

	 }
	 else if($msg.indexOf("Offer Action :")!=-1)
	  {  
	       //////////// responce from the server, for the last offer ////////////////////////
		     $info=$msg.split(":");
			 if($info[1]!="")
			   {
				    document.getElementById("error_text").innerHTML=$info[1]+'!';
	                tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
				   }
			else
			  {
				  
				  }
		   document.getElementById("auction").style.display="block";		  
		   document.getElementById("loader").style.display="none";		
		  ////////////////////////////////////////////////////////////////////////////////////////
		 }
	 else if($msg.indexOf("Auction security:")!=-1)
	  {
		  $msg=$msg.replace("Auction security:",""); 
		  				    document.getElementById("error_text").innerHTML=$msg+'!';
	                        tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		  }
	 else if($msg.indexOf("Auction Update:")!=-1	)
	 {
	  
	  ////////////// Auction update ajax responce from server ////////////////////////////////////
	     $msg=$msg.replace("Auction Update:",""); 
		 var feed=$msg.split("(*)");
		 if(document.getElementById("last_offer_user")!=null)
		 document.getElementById("last_offer_user").innerHTML=feed[1];
		  if(document.getElementById("last_offer_catmani")!=null)
		 document.getElementById("last_offer_catmani").innerHTML=feed[0]+" catmani";
		   if(document.getElementById("user_credit")!=null)
		 document.getElementById("user_credit").innerHTML=feed[2]+" catmani";
		  if(document.getElementById("personal_catmani")!=null)
		 document.getElementById("personal_catmani").value=feed[2];
		  if(document.getElementById("auction_top_offer")!=null)
		 document.getElementById("auction_top_offer").value=feed[0];
		  auctionLiveUpdate(feed[1],feed[0],feed[3]); //alert(feed[4]); 
		  if(parseInt(feed[0])>0)
		    {
				 if(document.getElementById("container1")!=null){
				document.getElementById("container1").style.display="inline";
				document.getElementById("container2").style.display="block";
				document.getElementById("container3").style.display="block";
				document.getElementById("containerAlternativ1").style.display="none";
				 }
				}
		if(feed[4]!=null && feed[4].trim()!=""){
		var $bloks;	
		$bloks=feed[4].split("(-)");
		 for($i=0;$i<=$bloks.length-1;$i++)
		    {    
			    $blok=$bloks[$i].split(",");
				$id_blok="catmani_offer_label_"+$blok[0];
				$id_blok_value="catmani_offer_"+$blok[0];
				$id_offerd="offered_label_"+$blok[0];
				$no_offer="no_offer_"+$blok[0];
				$user_offer="offered_"+$blok[0];
				if(document.getElementById($id_blok)!=null)
				  {//alert($id_blok);
					  document.getElementById($id_blok).style.display="block";
					  document.getElementById($id_offerd).style.display="block";
					  document.getElementById($no_offer).innerHTML="";
					  document.getElementById($id_blok_value).innerHTML=$blok[1]+" catmani";
					  document.getElementById($user_offer).innerHTML=$blok[2]; 
					  }
				}
		}
		/////////////////////////////////////////////////////////////////////////////////////////////
		 }
	 else if($msg.indexOf("Auction msg*")!=-1)
	  {
		  $break=$msg.split("*");
		  $txt=$break[1]; 
		  if(document.getElementById("container1")!=null)
		    {
				document.getElementById("container1").style.display="block";
				document.getElementById("container2").style.display="block";
				document.getElementById("container3").style.display="block";
				document.getElementById("containerAlternativ1").style.display="none";
				}
		  }	
	 else if($msg.indexOf("Auction*")!=-1)
	  {
		/////////////// Register to auction responce from server //////////////////////////////////////////  
		  $break=$msg.split("*");
		  $id=$break[1]; 
		  document.location.href="http://www.catman.ro/index.php?page=auction&id="+$id;
		////////////////////////////////////////////////////////////////////////////////////////////////////  
		  }
	  
      else if($msg.indexOf("*puzzle_finish*")!=-1)
	 { // on puzzle success 
    
	 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	  pageTracker._trackPageview('/puzzle-terminat'); 
	  document.getElementById("but_controls").style.display='none';
	  if(document.getElementById("succes_message").value.trim()=="")
	 setTimeout("doRefresh()",5000);

	 }
	 else 	 if($msg.indexOf("*start*")!=-1)
	 { // on start tinuta from a favorite product 
	   $id_produs=$msg.split("*start*"); 
	   $id_produs=trim($id_produs[0]); 
	   document.location.href="index.php?page=create&id="+$id_produs;
	 } 
	  else 	 if($msg.indexOf("*grab_tinuta*")!=-1)
	 { // on grab tinuta from anathot user
	   $msg=$msg.replace("*grab_tinuta*","");
	   document.getElementById("error_text").innerHTML=$msg+'!';
	   tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
       doAjax("pages/jq_tinuta_page.php","id_tinuta=1&mod=&pagenr=1&nr_pag=9");
	 } 
	 else 
	 { // on paginare
		   $msg=$msg.split("**@**");  
		   if($msg.length>1)
          {  
        	  /////////////////////////////// messages for pages /////////////////////////////////////////////////////
	         if($msg.length==2){  
			        document.getElementById('filtru').innerHTML=$msg[0]; 
		    }
		    else
		     {  
			     if($msg[2].indexOf("All Create Tinuta")!=-1)
				    {
						document.getElementById('tinuta_toate').innerHTML=$msg[1];
			            		$w=new Wardrobe();
								$w.addPlusListeners("all");
						}
                 else   if($msg[2].indexOf("Create Tinuta")!=-1)
				    {
						document.getElementById('tinuta_favorite').innerHTML=$msg[1];
			            		$w=new Wardrobe();
								$w.addPlusListeners("favorite");
						}
				   
			       if($msg[0]==null) $msg[0]="other";
					 $msgg=$msg[0].split("**#**");
			         $msg[0]=$msg[0].replace("**#**","");
				  switch(trim($msg[2])){ 
		            case "tinuta" :          document.getElementById('filtru_self').innerHTML=$msg[0];  break;
					case "tinuta_friends" :  document.getElementById('filtru_friends').innerHTML=$msg[0]; break;
					case "*comments*" :      document.getElementById('filtru').innerHTML=$msg[0]; break;
					case "All Create Tinuta" :   $msg[0]=$msg[0].replace("Produsele","");
					                             document.getElementById('filtru_pag2').innerHTML=$msg[0]; break;
					case "Create Tinuta" :       $msg[0]=$msg[0].replace("Produsele","");
					                             document.getElementById('filtru_pag').innerHTML=$msg[0]; break;
					default:                     document.getElementById('filtru_pag').innerHTML=$msgg[0];  break;
		  }
 	    }
                if($msg[1].indexOf("*store_flag*")!=-1)
		          {
	         	  $msg[1]=$msg[1].replace("*store_flag*",""); 
		          document.getElementById('lista_magazine').innerHTML=$msg[1];
		     	  }
			      else
			     { 
			      if($msg[2]==null) $msg[2]="other";
					switch(trim($msg[2])){
					 case "tinuta" :         document.getElementById('lista_produse_self').innerHTML=$msg[1]; break; 
					 case "tinuta_friends" : document.getElementById('lista_produse_friends').innerHTML=$msg[1]; break;
					 case "*comments*" : document.getElementById('comments').innerHTML=$msg[1]; break;
					  case "Create Tinuta" :  break;
					   case "All Create Tinuta" :  break;
		             default :               document.getElementById('listaproduse').innerHTML=$msg[1]; break;
					}
				   }
				   if($msg[2]==null) $msg[2]="other";
				   switch(trim($msg[2])){
			        case "tinuta" :         document.getElementById('filtru_bottom_self').innerHTML=$msg[0]; break; 
					 case "tinuta_friends" : document.getElementById('filtru_bottom_friends').innerHTML=$msg[0]; break; 
					 case "*comments*" : document.getElementById('filtru_bottom_pag').innerHTML=$msg[0]; break; 
					  case "All Create Tinuta" :  break;
					   case "Create Tinuta" :  break;
					 default:  document.getElementById('filtru_bottom').innerHTML=$msg[0];
				   } 
			   //////////////// refresh listeners \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
			   
	   if(trim($msg[2])=="favorite"){ 
		$( ".test" ).each(
			function( intIndex ){
				  $( this ).bind ("click",function(){
					 if(customConfirm(this.id,'favorite')==true){								
                          $(this).parents("#produsblock").animate({ opacity: 'hide' }, "slow");;
						     doAjax("pages/jq_delete_page.php","id="+this.id);
                                       }
						        	}
                                );
                          }
                     );
		$( ".creaza	" ).each(
			  	function( intIndex ){
					   $( this ).bind ("click",function(){
					 if(customConfirm(this.id,'favorite_add')==true){								
                             doAjax("pages/jq_favorite_page.php","start_tinuta="+this.id);
                                  }
						    	}
                              );
                            }
                      );

		 } else   if(trim($msg[2])=="tinuta"){ 
			//// delete tinuta \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\		
			$( ".tinuta_cancel" ).each(
			  	function( intIndex ){ 
					   $( this ).bind ("click",function(){
		                  if(customConfirm(this.id,'tinuta_delete')==true){		
                           $(this).parents(".item").animate({ opacity: 'hide' }, "slow"); 
                                    doAjax("pages/jq_delete_page.php","id_tinuta="+this.id);
					             }
                             }
             );

             }

         );
	////////////////////////// end delete \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	
		////////////////////////////////End LISTENERS /////////////////////////////////////////////////			
	        }
		}////////////////////////////////////////////////////////////////////////////////////////////
	else { 
			////// update comments from security entry//////////////////////
		   document.getElementById("comments").innerHTML=$msg;
		 ///////////////////////////////////////////////////////////////////  
			}
         }  
	} 
})

	} 
//////////////////////// END AJAX TRANSACTION AN PROCESSING///////////////////////////////////////////////////////////////


	
function puzzle_succes(obj)
 {
	 
	  doAjax("pages/jq_puzzle_end_page.php","id="+document.getElementById("current_puzzle").value);
	 	 document.getElementById("error_text").innerHTML='Felicitari, ai terminat puzzle-ul in '+obj.seconds+" secunde si "+obj.moves+" miscari.<br>"+document.getElementById("succes_message").value;
	  
	 }
function customConfirm($arg,$arg2)
 {   
        if($arg=="yes"){
     	//////////////////////////daca sa confirmat , ia id-u si sterge produsu///////////////////////
			$arg2=$('#deleted_id').val(); 
			switch($("#confirm_zone").val())
			{
				case "favorite" :$('#'+$arg2).parents("#produsblock").animate({ opacity: 'hide' }, "slow");
				                 doAjax("pages/jq_delete_page.php","id="+$arg2); 
				                  break;
				case "friends"  : $('#'+$arg2).parents("#produsblock").animate({ opacity: 'hide' }, "slow");
				                  doAjax("pages/jq_delete_friend_page.php","id="+$arg2);
				                  break;
				case "favorite_add":  doAjax("pages/jq_favorite_page.php","start_tinuta="+$arg2); 
				                 break;
				case "auction":  doAjax("pages/jq_auction.php","auction_id="+$arg2);
				                 break;		
				case "reenter_auction":  document.location.href="index.php?page=auction&id="+$arg2;
				                 break;					 
				case "tinuta_delete":    $('#'+$arg2).parents(".item").animate({ opacity: 'hide' }, "slow"); 
          					          doAjax("pages/jq_delete_page.php","id_tinuta="+$arg2);
								  break;
				}
		 	 tb_remove();
			    if($("#check").val()==1)
				  {
					   doAjax("pages/jq_delete_page.php","update_flag=1");
					   $("#has_confirm").val("0");
                  }			 
          return true;
		}
		else if($arg=="no")
	   {  
		    /////////////////////////////daca apasa nu////////////////////////////////////////////////////////
			    if($("#check").val()==1)
				  {
					   doAjax("pages/jq_delete_page.php","update_flag=1");
					   $("#has_confirm").val("0"); 
				  }
			    tb_remove();
				 return false;
			   }
		 if($('#has_confirm').val()=="0")
		   {  ////////////////////////// daca nu este mesaj de confirmare//////////////////
			   return true;
			   }
			   else {
				   ///////////////////daca este mesaj de confirmare seteaza id produs in container/////////////////
				    $('#deleted_id').val($arg);
			    	$("#confirm_zone").val($arg2);
					switch($arg2)
					 {

					case "favorite_add" : 
			           tb_show("Doriti sa incepeti o garderoba cu aces produs?", "#TB_inline?height=155&amp;width=300&amp;inlineId=confirm_notice&amp;modal=false", false);
					   break;
					case "auction" : 
    		           tb_show("Doriti sa va inregistrati la aceasta licitatie?", "#TB_inline?height=155&amp;width=300&amp;inlineId=confirm_notice&amp;modal=false", false);
					   break;
					case "reenter_auction" : 
			           tb_show("Doriti sa ofertati la aceasta licitatie?", "#TB_inline?height=155&amp;width=300&amp;inlineId=confirm_notice&amp;modal=false", false);
					   break;		   
				    case "tinuta_delete" : 
			           tb_show("Doriti sa stergeti aceasta tinuta?", "#TB_inline?height=155&amp;width=300&amp;inlineId=confirm_notice&amp;modal=false", false);
					   break;		   
					default :
                       tb_show("Sunteti sigur ca vreti sa stergeti ?", "#TB_inline?height=155&amp;width=300&amp;inlineId=confirm_notice&amp;modal=false", false);
				      break;
					   }
	                 }
	 }

function grab($tinuta)
 {
	 doAjax("pages/jq_grab_tinuta_page.php","id="+$tinuta);
 }
function switch_check()
 {
	 if($('#check').val()==0)$('#check').val(1); else $('#check').val(0); 
 }
function showFriendRequestResponse(responseText, statusText)
{
			 document.getElementById("error_text").innerHTML='Cererea de prietenie a fost trimisa';
			 tb_show("Cerere prietenie", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
			 document.getElementById("friend_request").innerHTML='<font color="green">Cererea de prietenie a fost trimisa</font>';
}

function validateFormTrimite(formData)
 {
  var objRegExp  = /([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)([.][0-9a-z]{3})$)|([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)(\.[0-9a-z]{2})(\.[0-9a-z]{3})*$)/i;
   for (var i=0; i < formData.length; i++) {  
			if (formData[i].name=="nume1"  && formData[i].value=="") {  
          	  document.getElementById("error_text").innerHTML='Va ruram introduceti un nume!';
			  tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
			  return false;
	}
	    if(formData[i].name=="email1" && formData[i].value=="")
		 {
		   document.getElementById("error_text").innerHTML='Va rugam introduceti un Email';
		 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		 return false;
		 }
        if (formData[i].name=="email1"  && objRegExp.test(formData[i].value.trim())==false) {  
           	  document.getElementById("error_text").innerHTML='Formatul pentru "Email" necesar este : email@sitemail.ro';
			  tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
			  return false;
		}
	}
 	return true;
	 }

 function succesFormTrimite(responseText)
 {
	  document.getElementById("error_text").innerHTML=responseText;
	  tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
       top();
	  return false;
	 }
function validateFriendRequest(formData, jqForm, options)
{  
 return true; 
}
function showCommentResponse(responseText, statusText)
 { 
 /////////////////////////////// genereaza  imagini de adunare captcha/////////////////////////////////////////////////
   if(responseText.indexOf("captcha")!=-1) 
    {   
	    var $rand1=Math.floor( Math.random ( ) * 9 + 1 );
		var $rand2=Math.floor( Math.random ( ) * 9 + 1 );
		var $result=$rand1+$rand2;
		var $enc=$rand1.toString()+' plus '+$rand2.toString()+" = "; 
		document.getElementById("secure_answer").value=$result;
		document.getElementById("security_image").src="GuruFactor/factors/captcha.php?enc="+$enc;
		tb_show("Security pass", "#TB_inline?height=155&amp;width=300&amp;inlineId=security&amp;", false);
         top();
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
		}
   else
    {  
    	document.getElementById("comments").innerHTML=responseText;
        top();
		}
 }   
function top() {
  if (document.body.scrollTop!=0 || document.documentElement.scrollTop!=0){
    window.scrollBy(0,-60);
    t=setTimeout('top()',20);
  }
  else clearTimeout(t);
}
function AddFavoriteResponse(responseText, statusText) 
{
	 document.getElementById("error_text").innerHTML=responseText;
	 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
      top();
	}
function validatePendingFriends(formData, jqForm, options)
{ 
	}
function FAV()
 {
	  document.getElementById("error_text").innerHTML="Produsul a fost adaugat la  Favorite!";
   	 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	 top();
	 }
function pendingFriendsResponse(responseText, statusText)
{
 	$msg=responseText.split("**&**");
    $victim_block="req_"+$msg[1];
    document.getElementById($victim_block).style.display='none';
	document.getElementById("error_text").innerHTML=$msg[0];
	 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	}
function validateSecureForm()
{ 

   var input=document.getElementById("security_input_in_remote").value;
   var answer=document.getElementById("secure_answer").value;
   if(input!=answer){ 
 alert("Raspuns incorect ! Mai inceRCATI");
	 return false;
	}
	else
	 { 
	 tb_remove();
	 doAjax("jqcomment.php","security=1");
		 }
	}
function SecureResponse()
{ 
	}
function saveTinuta() 

 {

	 //////////////////////////i-a idu fiecarui produs din containerul droppable si copiaza in formular////////////////////////

	$( ".img_trash" ).each(

			  	function( intIndex ){

					if(intIndex==0)

					 document.getElementById("saved_images").value=this.id;

					else

					  document.getElementById("saved_images").value+=","+this.id;

					   

                             }

                 

                       ); 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(document.getElementById('saved_images').value=="")

        {       

			 document.getElementById("error_text").innerHTML='Trebuie sa aveti cel putin un produs in tinuta';

			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

			return false;

		}

if(document.getElementById('nume_tinuta').value=="")

     {

		 			 document.getElementById("error_text").innerHTML='Va rugam, introduceti un nume pentru noua tinuta';

			       tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

			       return false;

		 }

if(document.getElementById('descriere_tinuta').value=="")

     {

		 			 document.getElementById("error_text").innerHTML='Va rugam, introduceti o descriere pentru noua tinuta';

			       tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

			       return false;

		 }	

		 return true; 

	 }

function showResponse(responceText)
{           
                   document.getElementById("error_text").innerHTML='Ati fost adaugat la lista noastra de newsletter !';

			       tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
				   
				   top();

	}

function LoginResponse(response)    
{
  if(response.indexOf("script")!=-1)
    {
		 response=response.substr(response.indexOf("</span>")+7,response.length-1);
		 document.location.href=response.trim();
		}
   else
    {
		document.getElementById("login_error_message").innerHTML=response.trim();
		}
	}	

function validateCommentForm(formData, jqForm, options)

{

	 var objRegExp  = /([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)([.][0-9a-z]{3})$)|([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)(\.[0-9a-z]{2})(\.[0-9a-z]{3})*$)/i;

    for (var i=0; i < formData.length; i++) { 

	    if(formData[i].name=="nume" && formData[i].value=="")

		 {

			 document.getElementById("error_text").innerHTML='Va rugam introduceti un Pseudonim';

			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

			 return false;

			 }

			 

        if (formData[i].name=="email" && objRegExp.test(formData[i].value.trim())==false ) { 

			  document.getElementById("error_text").innerHTML='Formatul pentru "Mail" necesar este : email@sitemail.ro';

			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

            return false; 

        } 

		if(formData[i].name=="subiect" && formData[i].value=="")

		 {

			  document.getElementById("error_text").innerHTML='Va rugam introduceti un Subiect';

			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

			 return false; 	 

			 }

	   if(formData[i].name=="comentariu" && formData[i].value=="")

		 {

			  document.getElementById("error_text").innerHTML='Va rugam introduceti un comentariu';

			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

		     return false;

			 }

    } 

	

	}

function validateLoginForm(formData, jqForm, options)
{

	return true;        
}

function validate(formData, jqForm, options)
{ 
 
    var objRegExp  = /([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)([.][0-9a-z]{3})$)|([0-9a-z]([0-9a-z_\.]*)@([0-9a-z_\.]*)(\.[0-9a-z]{2})(\.[0-9a-z]{3})*$)/i;
    for (var i=0; i < formData.length; i++) {  
	    if(formData[i].name=="Email" && formData[i].value=="")
		 {
		   document.getElementById("error_text").innerHTML='Va rugam introduceti un Email';
			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
			 return false;
			 }

		  if (formData[i].name=="Email" && objRegExp.test(formData[i].value.trim())==false ) {  
           	  document.getElementById("error_text").innerHTML='Formatul pentru "Email" necesar este : email@sitemail.ro';
			  tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
			  return false;
	}
	}
	return true;

	}
function activateSucces()
 {
	 		   document.getElementById("error_text").innerHTML='Contul dumneavoastra a fost activat!';
			   tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	 }
 function guestArrived()
 {             
               pageTracker._trackPageview('/raspuns-chemare-inviter'); 
	 		   document.getElementById("error_text").innerHTML='Raspunsul la invitatie a fost inregistrat! Pentru a-ti creea un cont <a onclick="gotocont()" style="cursor:pointer">click aici!</a>';
			   tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	 }
function gotocont()
{
	window.parent.preemptAction();
    window.parent.tb_remove();
 }
function preemptAction(){

	 setTimeout ( "contAction()", 2000 );

	} 
function contAction()

{  

	tb_show("ALERTA", "creaza_cont.php?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=680&width=710&modal=true", false);

	}
function validareContact()
{
	 document.getElementById("error_text").innerHTML='Contul dumneavoastra a fost activat!';
	 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
	return false;	
	}
function select_av($id)
{
  $imgs=document.getElementsByTagName('img');
  for($i=0;$i<=$imgs.length-1;$i++)
   { 
	   if($imgs[$i].id!=$id) $imgs[$i].className="avatar";
	                   else  
					     { 
						   $imgs[$i].className="selected";
						   $("#avatar_id").val($imgs[$i].id);
						 }
	   }
	}
function search_field()
{
	document.getElementById("search_form").action="index.php?q="+$("#search").val();
	document.getElementById("search_form").submit();
	return true;
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function selectAll($id)
{
	if($id!="Toate magazinele")
	document.location.href='http://www.catman.ro/index.php?page=categories&all_p=1&store='+$id;
	else document.location.href='http://www.catman.ro/Magazine.html';
	}

function rtrim(str, chars) {

    chars = chars || "\\s";

    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}	

//////////////////// COUNTERS Class////////////////////////////////////////////////////////
Counters=new Function();
Counters.prototype.initiate=function()
{
 this.counters=[];
}
Counters.prototype.register_countdown=function(yr,m,d,ore,minute,secunde,yrf,mf,df,oref,minutef,secundef,$id)
{
	this.counters[this.counters.length]={
		       year_end:yr,
			   month_end:m,
			   day_end:d,
			   hours_end:ore,
			   minutes_end:minute,
			   seconds_end:secunde,
			   year_start:yrf,
			   month_start:mf,
			   day_start:df,
			   hours_start:oref,
			   minutes_start:minutef,
			   seconds_start:secundef,
			   id:$id
		};
	}
Counters.prototype.countdown=function(){

var current="Licitatia s-a terminat";
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
for($i=0;$i<=this.counters.length-1;$i++)
{
theyear=this.counters[$i].year_end;themonth=this.counters[$i].month_end;theday=this.counters[$i].day_end;theyearf=this.counters[$i].year_start;themonthf=this.counters[$i].month_start;
thedayf=this.counters[$i].day_start;
var todayy=this.counters[$i].year_start;
var todaym=this.counters[$i].month_start;
var todayd=this.counters[$i].day_start;
var todayh=this.counters[$i].hours_start;
var todaymin=this.counters[$i].minutes_start;
var todaysec=this.counters[$i].seconds_start;
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
futurestring=montharray[this.counters[$i].month_end]+" "+this.counters[$i].day_end+", "+this.counters[$i].year_end+" "+this.counters[$i].hours_end+":"+this.counters[$i].minutes_end+":"+this.counters[$i].seconds_end;
dd=Date.parse(futurestring)-Date.parse(todaystring);
dday=Math.floor(dd/(60*60*1000*24)*1);
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
	$target_id=this.counters[$i].id;
    document.getElementById($target_id).innerHTML="Licitatia s-a finalizat!";
	  if(document.getElementById("pending_auction").value==0 && document.getElementById("main_auction_id").value==$target_id.replace("time",""))
	  {  
	   setTimeout("doRefresh()",5000);
	  }
	  else setTimeout("counter.countdown()",1000); 
	 
return;
}
else{ 
$target_id=this.counters[$i].id;
document.getElementById($target_id).innerHTML=dday+ " zile, "+dhour+" ore, "+dmin+" minute, si "+dsec+" secunde";
}  
this.counters[$i].seconds_start++;
if(this.counters[$i].seconds_start>59)
  {
	   this.counters[$i].seconds_start=0;
	   this.counters[$i].minutes_start++;
	     if(this.counters[$i].minutes_start>59)
		   {
			   this.counters[$i].minutes_start=0;
			   this.counters[$i].hours_start++
			     if(this.counters[$i].hours_start>23)
				   {
					   this.counters[$i].hours_start=0;
					   this.counters[$i].days_start++;
					   }
			   }
  }

}

setTimeout("counter.countdown()",1000);
}
/////////////////////////////////////////// END COUNTER CLASSS////////////////////////////////////////////////////////////////////////


///////////////////////// AUCTION OPERATIONS ////////////////////////////////////////////////////
function auction($id,$type)
{ 
	 if($type==0){
	  customConfirm($id,'auction');		
	 }
	 else
	 {
	  customConfirm($id,'reenter_auction');
	 }
                      
}
function auction_offer()
  {

	//$kids=$("#items").children("<li>");
	/*if($kids.length>0)
	 {
		 $max=0;
		 for($i=0;$i<=$kids.length-1;$i++)
		   {  
			    $element=$kids[$i].id;
				$element=$element.replace("item","");
				$element=parseInt($element);
				if($element>$max) $max=$element;
			   }
    	var   $target=document.getElementById("item"+$max).innerHTML; 
	 } else { var $target=""; } //alert($target);
	if($target!="" && $target.indexOf($("#my_user_link").val())!=-1)
	{
		document.getElementById("error_text").innerHTML='Imi pare rau, nu poti sa ofertezi de 2 ori consecutiv!';
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		}*/
	if($("#auction_value").val()=="")
	{
		document.getElementById("error_text").innerHTML='Te rugam sa introduci suma pe care doresti sa o licitezi';
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		}
	if(!isInteger($("#auction_value").val()))
	{
		document.getElementById("error_text").innerHTML='Suma licitata de tine trebuie sa fie un numar intreg, fara zecimale.';
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		}
		if($("#auction_value").val()==0)
	{
		document.getElementById("error_text").innerHTML='Suma licitata de tine trebuie sa fie un numar pozitiv.';
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		}
/*	if(parseInt($("#auction_top_offer").val())>=parseInt($("#auction_value").val())) 
	 {
		document.getElementById("error_text").innerHTML='Suma licitata trebuie sa fie mai mare de '+$("#auction_top_offer").val();
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		 }
	if(Math.abs(parseInt($("#auction_top_offer").val())-parseInt($("#auction_value").val()))>30) 
	 {
		 document.getElementById("error_text").innerHTML='Suma oferita de tine este prea mare. Valoarea maxima per oferta: +30 catmani.';
	    tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		return false;
		 }	 
	if(parseInt($("#auction_value").val())<=parseInt($("#personal_catmani").val())) 
	 {
		 doAjax("pages/jq_auction.php","offer_id="+$("#auction_id").val()+"&sum="+$("#auction_value").val()); 
		 return false;
		 }
     else 
	  {
		  	 document.getElementById("error_text").innerHTML='Nu ai suficienti catmani! Suma maxima pe care o potii oferi este de <b>'+$("#personal_catmani").val()+' catmani</b>';
	         tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);
		  }*/
			document.getElementById('auction').style.display="none";
			  document.getElementById("loader").style.display="block";
      	doAjax("pages/jq_auction.php","offer="+$("#auction_value").val()+"&for_auction="+$("#auction_id").val());  
	  
	  }
function auction_slider()
{
	            $('#items').prepend('<li style="display:none" id="item' + counter + ">Test test</li>");
     		    $('#item' + counter).fadeIn();

	}
function auctionUpdate($main)
{
	 doAjax("pages/jq_auction_update.php","feed=1&main="+$main); 
	}

function auctionLiveUpdate($user,$catmani,$user_simple)
{
	$kids=$("#items").children("<li>");
	if($kids.length>0)
	 {
		 $max=0;
		 for($i=0;$i<=$kids.length-1;$i++)
		   {  
			    $element=$kids[$i].id;
				$element=$element.replace("item","");
				$element=parseInt($element);
				if($element>$max) $max=$element;
			   }
    	var   $target="item"+$max; 
	try{
		var   $string=document.getElementById($target).innerHTML; 
		$catmani_temp=$catmani+" catmani";
		  if($string.indexOf($user_simple)==-1 || $string.indexOf($catmani_temp.trim())==-1 )
		    addItem($user,$catmani);
	}catch(e)
	{
		}
		 }
	else addItem($user,$catmani);	 
	}
//////////////////END AUCTION OPERATIONS/////////////////////////////////////////////////////////////////////

function upload_device()
{
	 $("#upload_zone").hide("fast");
	 $("#upload_form").show("fast");
	}
function updateCroppedImage($msg)
{
	$("#upload_zone").html("Avatarul a fost taiat!");
	$("#uploaded_image").hide("slow");
	$("#fresh_cropped").attr("src",	$msg.trim());
	//$("#cropbox").css("display","visible");
	//$("#cropbox").attr("src",$msg.trim());
	$("#uploaded_fresh_cropped").show("slow");
	}
function CropUpdateCoords(c)
{
	jQuery('#x').val(c.x);
	jQuery('#y').val(c.y);
	jQuery('#w').val(c.w);
	jQuery('#h').val(c.h);
};
	
function showavatar($msg)
{
	//alert($msg);
	if($msg.indexOf("ERROR")!=-1) 
	    {
			$("#upload_zone").html("S-a intampinat o eroare la incarcarea fisierului!Va rugam incercati dinou.");
			return false;
			}
    $("#upload_zone").html("Avatarul a fost incarcat!");
	$("#cropbox").attr("src","images/avatars/"+$msg.trim());
	$("#tobecropped").attr("value","images/avatars/"+$msg.trim());
	$("#avatar_list").hide("slow");
	$("#uploaded_image").show("slow");
	    jQuery(function() {
        jQuery('#cropbox').Jcrop({
            bgColor:     'black',
            bgOpacity:   .4,
            setSelect:   [ 100, 100, 50, 50 ],
            aspectRatio: 16 / 9,
			maxSize:[100,100],
			onSelect: CropUpdateCoords

        });
    });

	}
function testavatar()
{
	$("#upload_form").hide("slow");
	$("#upload_zone").show("slow");
	$("#upload_zone").html("Avatarul se incarca ... <img src='images/ajax-loader.gif'>");
	}
////////////////TEST IF IS INTEGER NUMBER///////////////////////////////////////////////////////////////////
function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }
function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }
  ////////////////////////////////////////////////////////////////////////////////////// 

function redirectParent($link)
 {
	 parent.document.location.href="http://www.catman.ro/"+$link;
	 }
function tinuta_warning($text)
{                document.getElementById("error_text").innerHTML=$text;
      			 tb_show("ALERTA", "#TB_inline?height=155&amp;width=300&amp;inlineId=error&amp;modal=false", false);

	}
function linkme($link)
{
	document.location.href="http://"+document.location.host+"/"+$link;
	}
function helpme()
{
	 document.getElementById("error_text").innerHTML="Ai in cont 5600 de catmani si ai invitat 40 de prieteni. 28 dintre ei au decis sa-si deschida un cont";
	  document.getElementById("error_text").innerHTML+=" pe acest site si sa participe la licitatie. Fiecare dintre cei 28 de noi useri vor primi in conturile";
	   document.getElementById("error_text").innerHTML+="lor cate 2800 de catmani, iar soldul tau va creste cu 28x100=2800 catmani. Asadar, ai in cont ";
	    document.getElementById("error_text").innerHTML+="5600+2800=8400 catmani.Invita-ti cat mai multi prieteni. Soldul tau va creste, iar sansele de castig se anmulsesc! Bafta!";
      			 tb_show("Exemplu", "#TB_inline?height=255&amp;width=400&amp;inlineId=error&amp;modal=false", false);

	}
