
var currentPage = 'welcome';
var lastAbout  = 'spa';
var lastService  = '1';
var lastClient = 'list';
var lastNews = 'press';
var lastForum = 'index';
var idComment = 0;
var lastGrup = '1';
var lastContact = '1';

 $(document).ready(function(){
	 // <schimbare de limba>	 
	  $.each( ['en','fr','de','sp','it'], function(i, n){        
         $('img#'+n).bind("click", function(){
         changeLanguage(n);
	      });	 
      });	    
    // </schimbare de limba>
    // <schimbare pagina>     
		$.each( ['welcome','about','services','clients','news','forum','contacts','survey'], function(i, n){        
        $('img#'+n+'_img').bind("click", function(){       
    //change the image src	
        $(this).attr('src',str_replace('_off','_on',$(this).attr('src')));        
//-----passage survey en haut ------if ( (n!=currentPage) && (currentPage!='survey') && (currentPage!='privacy') )
		if ( (n!=currentPage) && (currentPage!='grup') && (currentPage!='privacy'))
          {
             $('img#'+currentPage+'_img').attr('src',str_replace('_on','_off',$('img#'+currentPage+'_img').attr('src')));             	         
          }
         schimbarePagina(n);
	     });
	 
      });	      
     // </schimbare pagina>
     
     

    
    // <footer link>    
    $.each( ['welcome','privacy','contacts','grup'], function(i, n){        
         $('li#footer_'+n).bind("click", function(){         	        	
          schimbarePagina(n);
          changeMenu(n);
	     });
	 
      });
    // </footer link>
    
     //prima oara la intrare afisam  welcome
     populate_welcome();
       
 });
 
 function changeMenu(which){      
        currentPage = which;
      //	$.each( ['welcome','about','services','clients','news','forum','contacts','grup'], function(i, n){             		
       	//$.each( ['welcome','about','services','clients','news','contacts','grup','survey'], function(i, n){    
		$.each( ['welcome','about','services','clients','news','contacts','survey'], function(i, n){             		

        $('img#'+n+'_img').attr('src',str_replace('_on','_off',$('img#'+n+'_img').attr('src')));
//         if ( (n!=currentPage) && (currentPage!='privacy') )  $('img#'+currentPage+'_img').attr('src',str_replace('_off','_on',$('img#'+currentPage+'_img').attr('src')));    
if ( (n!=currentPage) && (currentPage!='privacy') && (currentPage!='grup') )  $('img#'+currentPage+'_img').attr('src',str_replace('_off','_on',$('img#'+currentPage+'_img').attr('src')));             	         

	  });	
 }
 
		 
 function changeLanguage(limba){   

    $.ajax({
	    type: "GET",
	    url: "php/change_language.php",	   
	    data: 'lg='+limba,  
  	    dataType : "json",
        success: function(lg){ 
        	updateMenuButtons(lg.old_lg,lg.new_lg);        	
        	updateFooter(lg.footer);
         	$('span#choose_language').html(lg.change);
          }    
	  });  	
	 schimbarePagina(currentPage); 	  
 }
 
 function  schimbarePagina(which){ 
   changeBackgrounds(which);    
   currentPage = which;
   eval('populate_'+which+'();'); // executes the function populate_welcome ....     
}

function changeBackgrounds(which){

   switch(which){
 	 	case 'welcome'  :	 { 	index = 1; 	break; }
 	 	case 'about'    :	 { 	index = 2; 	break; }
 	 	case 'services' :	 { 	index = 3; 	break; }
 	 	case 'clients'  :	 { 	index = 4; 	break; }
 	 	case 'news'     :	 { 	index = 5; 	break; }
 	 	case 'forum'    :	 { 	index = 6; 	break; }
 	 	case 'contacts' :	 { 	index = 7; 	break; }
 	 	case 'grup'     :	 { 	index = 8; 	break; }
 	 	case 'survey'   :	 { 	index = 9; 	break; }
 	 	default         :  	 { 	index = 1; 	break; }	 
 	 	 
   } //end switch   
    $('div#bg_header').removeClass().addClass('bg_header'+index);
 	$('div#content').removeClass().addClass('bg'+index);
 	$('div#bg_content').removeClass().addClass('bg_content'+index);
 	$('div#about').removeClass().addClass('bg_content'+index);	
}

/*
 *  Change the images of the menu when the language is changed
 */
function updateMenuButtons(lg_old,lg_new){	
       $.each( ['welcome','about','services','clients','news','forum','contacts','survey'], function(i, n){      	                        	        	 
          $('img#'+n+'_img').attr('src',str_replace('_'+lg_old+'_','_'+lg_new+'_',$('img#'+n+'_img').attr('src')));                
      });	      
}

function updateFooter(footer){

    $.each( ['welcome','privacy','contacts','grup','copy'], function(i, n){        
         $('li#footer_'+n).html(eval('footer.'+n));
    });	      	
}


function populate_welcome(){
	var address ='<div class="cleft"  style="overflow: auto; height:440px">' +
			'<span class="t1" style="color: #4C4B49">Hopscotch Europe In One</span><br/>' +
			'<span class="t2" style="color: #4C4B49">22 Kildare Street  - Dublin 2 - Republic of Ireland - T:  +353(0)1 639 88 81<br/></span>' +
'<a href="mailto:information@hopscotch.eu ">'+
			'<span class="t4" style="color: #B8370C">@:  information@hopscotch.eu </a><br/></span><br/>'+
		
			'<span class="t1" style="color: #4C4B49">Call us direct on our international numbers: </span><br/>' +
'<span class="t2" style="color: #4C4B49">AUS: +61 390016606 - BE: +32 280 80 883  - CA: +1 (647) 722 55 61<br/>' +
'CH: +41 (0)22 533 01 11 - DE: +49 511 260 98 22 41 - ES: +34 93 390 61 38 <br/>' +
'FR: +33 (0)1 70 61 83 81 - IT: +39 02 40 70 84 82 - UK: +44 (0)208 133 3140<br/>' +
'US: +1 253 777 0019 - BRA: +55 11 3711 9145 </span><br/><br/>' +
			
			'<img src="images/wnews.gif">'; 
			
			
	var rest = //' <div class="clear"></div>' +
			     //'<div class="flash"></div> '+
			     '<table width=400><tr>'+
				 '<td><img src="images/client.gif"></td><td><img src="images/europr.gif"></td>'+
				 '</tr><tr><td>'+
				 '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="89" height="57" id="map" align="middle">'+
			   '<param name="allowScriptAccess" value="sameDomain" />'+
			   '<param name="movie" value="logos.swf" /><param name="quality" value="high" />'+
			   '<param name="wmode" value="transparent"/>'+
			   '<embed src="logos.swf" quality="high" width="89" height="57" name="map" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
			   '</object>'+
				 '</td><td class="europrsurvey"><b>Are you interested </b> in the latest trends in pan European PR management ? The results of our Euro PR Survey 2008 are now available. Warm thanks to the 150 respondents who allowed us to provide this in-depth analysis of European PR !'+
				 '<br><div align="right" style="cursor: pointer"><img src="images/ready.gif" onClick="populate_survey()"></div>'+
				 '</td></tr></table>'+
					     '<div class="clear"></div>'+
  		        '</div> ';
		
	var cright='<div class="cright">'+
			   '<img src="images/prelations.gif" alt="" />'+
			   '<div class="bar"></div>'+
			   '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="450" height="275" id="map" align="middle">'+
			   '<param name="allowScriptAccess" value="sameDomain" />'+
			   '<param name="movie" value="eumap.swf" /><param name="quality" value="high" />'+
			   '<param name="wmode" value="transparent"/>'+
			   '<param name="bgcolor" value="#ffffff" />'+
			   '<embed src="eumap.swf" quality="high" bgcolor="#ffffff" width="450" height="275" name="map" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
			   '</object>'+
			   '</div>';
        		
     $.ajax({
	   type: "GET",
	   url: "php/index_news.php",	   
	   success: function(stire){    		     	    
           $('div#bg_content').html(address+stire+rest+cright);        		
           
           
                    //actiuni de pe pagina respectiva   
		           	$('div#survey').bind("click", function(){
				         populate_survey();
					 });
					
	    }    
	  }); 
}

function populate_about(what){	
	
    if (what==undefined) what = lastAbout;
	$.ajax({
	   type: "GET",
	   data: 'what='+what,
	   url: "php/index_aboutus.php",	   	   
	   success: function(about){    		     	    
           	$('div#bg_content').html(about);                        	 
           	
           	  //actiuni de pe pagina respectiva
           	    $('img#spa').bind("click", function(){
				        populate_about('spa');
				        //lastAbout = 'spa';
					 });
				$('img#people').bind("click", function(){
				        populate_about('people');
				       // lastAbout = 'people';
					 });	 
			    $('img#download').bind("click", function(){
				         populate_about('download');
				        // lastAbout = 'download'; 
					 });	 
	    }    
	  }); 
	  
}


function populate_services(type){	
	
    //if (type==undefined) what = lastService;
	$.ajax({
	   type: "GET",
	   data: 'type='+type,
	   url: "php/index_services.php",	   	   
	   success: function(services){    		     	    
           	$('div#bg_content').html(services);                        	 
           	   $('#content li img').bind("click", function(){
           	    	 populate_services($(this).attr('alt'));
					 });
					 
			   $('tr').bind("click", function(){
           	       var as = $(this).attr('id').split('_');           	      
        	       populate_clients('detail',as[1]);       	     
        	       changeMenu('clients');
        	       changeBackgrounds('clients');
			   });	 
	    }    
	  }); 
	  
}

function populate_clients(what,value){	
	
    if (what==undefined) { 
		what = 'list'; 
		date= 'what='+what;
	} else   if (what=='country') { 
		date = 'what='+what+'&country='+value
	} else   if ( (what=='detail') && (value!=undefined)) {
		date = 'what='+what+'&id='+value
	} else  {
		date = 'what=list'; 
	}
     //alert(what+'  '+value+'  => '+date);
    
    
	$.ajax({
	   type: "GET",
	   data: date,
	   url: "php/index_clients.php",	   	   
	   success: function(clients){    	
	       	   	
             	$('div#bg_content').html(clients);                  	            	

             	             	
             	$('#cleft img').bind("click", function(){
				          var tara = $(this).attr('alt');				          			        
				          populate_clients('country',tara); 
				          lastClient = 'country';
					 })							
				$('#flags img').bind("click", function(){
				          var tara = $(this).attr('alt');				          			        
				          populate_clients('country',tara); 
				          lastClient = 'country';
					 })							
					 	 
				
				$('#leservice h1').bind("click", function(){				        			  	     
			  	        //var sv =  $(this).attr('id').split('_');
						//alert($(this).attr('alt'));
				        populate_services($(this).attr('alt'))	
				        changeMenu('services');
				        changeBackgrounds('services');
					 })	
				
				
				
				$('#back').bind("click", function(){	
						 var client = $(this).attr('s_1');				          			        
				         //populate_clients('detail',client); 
				         //lastClient = 'detail';						  
						 populate_clients('list'); 
				         lastClient = 'list'; 
					 })	
					 
 				 $('td span').bind("click", function(){
				         var client = $(this).attr('id');				          			        
				         populate_clients('detail',client); 
				         lastClient = 'detail';
					 })		
					 	 
	     }    
	  }); 	  
}

function populate_clients_fromFlash(country){		        
	$.ajax({
	   type: "GET",
	   data: 'country='+country,
	   url: "php/flash_clients.php",	   	   
	   success: function(clients){    		     	    	   	
             	$('div#cleft').html(clients);
             	
             	$('#cleft img').bind("click", function(){
				          var tara = $(this).attr('alt');				          			        
				          populate_clients('country',tara); 
				          lastClient = 'country';
					 })							
				$('#flags img').bind("click", function(){
				          var tara = $(this).attr('alt');				          			        
				          populate_clients('country',tara); 
				          lastClient = 'country';
					 })							
					 	 
			   $('h1').bind("click", function(){				        			  	     
			  	        var sv =  $(this).attr('id').split('_');
				         populate_services(sv[1]); 				         
				         changeMenu('services');
					 })	
			   
			   
					 
				$('#back').bind("click", function(){				        
				          populate_clients('list'); 
				          lastClient = 'list'; 
					 })	
					 
 				 $('td span ').bind("click", function(){
				         var client = $(this).attr('id');				          			        
				         populate_clients('detail',client); 
				         lastClient = 'detail';
					 })		 
					                   	            	
	     }    
	  }); 	  
}

function populate_news(type){	
	
    if (type==undefined) what = lastNews;
	$.ajax({
	   type: "GET",
	   data: 'type='+type,
	   url: "php/news.php",	   	   
	   success: function(news){    		     	    
	   	
	   	  $('div#bg_content').html(news);                 
	   	         	            	
           	  //actiuni de pe pagina respectiva
           	    $('img#press').bind("click", function(){
           	    	populate_news('press');
           	   });
           	   
           	  $('img#media').bind("click", function(){
           	    	populate_news('media');
           	   });
	    }   
	  }); 
	  
}

function populate_forum(what,value,comm){	
	
    if (what==undefined) { what = lastForum; date= 'what='+what;}
    else if (what=='post') { date = 'what='+what+'&id='+value}    
    else if (what=='comment') { date = 'what='+what+'&id='+value+comm}    
    else if (what=='index')  { date = 'what='+what;}    
    else date = 'what='+what;
    
    
	$.ajax({
	   type: "GET",
	   data: date,
	   url: "php/forum.php",	   	   
	   success: function(clients){    		     	    	   	
              	$('div#bg_content').html(clients);                  	 
                   
                   
					 
				  $('div.putpost').bind("click", function(){             	 	    
				         populate_forum('index');
				   }) 
				   
				   $('#react').bind("click", function(){
				         tb_show('','',false);				         					         
					    $('div.seepost').bind("click", function(){
             	 	     idComment  = $(this).attr('title');
				         populate_forum('post',idComment);
  					   }) 	 					    	 	 				
					 }) 
					    
              	   $('div.seepost').bind("click", function(){
             	 	     idComment  = $(this).attr('title');
				         populate_forum('post',idComment);
					 }) 
				 	 
	     }    
	  }); 	  
}
function populate_grup(type){	
	
    if (type==undefined) what = lastGrup;
	$.ajax({
	   type: "GET",
	   data: 'type='+type,
	   url: "php/grup.php",	   	   
	   success: function(grup){    		     	    
           	$('div#bg_content').html(grup);                        	            	
           	  //actiuni de pe pagina respectiva          	   
	    }    
	  }); 	  
}

function populate_contacts(){	
	$.ajax({
	   type: "GET",
	   url: "php/contacts.php",	   	   
	   success: function(contact){    		     	    
           	$('div#bg_content').html(contact);                        	            	
           	  //actiuni de pe pagina respectiva          	   
           	  
           	 $('input#send_contact').bind("click", function(){
             	 	    
             	 	  
           	
           	if ($('input[@name=famname]').val()=='')
           	 {
           	       alert('You must enter your famility name');	
           	 }
           	  else 	if ($('input[@name=firstname]').val()=='')
           	   {
           	   	 alert('You must enter your first name');
           	   } else if ($('input[@name=company]').val()=='')
           	    {
           	    	alert('You must enter the company name');
           	    } else if ($('input[@name=email]').val()=='')
           	     {
           	     	alert('You must enter your email');
           	     } 
           	    else if ($('textarea[@name=message]').val()=='')
           	      {
           	      	  alert('You must enter the message')
           	      }
           	      else
           	      {
           	      	
           	        //data proccessing is ok
           	        
		 			  var date1 =  $('input[@type=text]').serialize(); 			      			  
		 			  var date2 =  $('textara[@name=message]').serialize(); 			      			  
  		 			  var date = date1+'&'+date2;                      		 			  
		 			        $.ajax({
							   type: "POST",
							   url: "php/add_contact.php",	   
							   data:date,
							   success: function(raspuns){    		     	    			           
							   	  //surveyul a fost comeplatat cu success
							   	  $('span#thank').html(raspuns);
							   	  $('table#contact_table').hide('slow');
							    }    
							  }); 
           	      } 
            
             
					 })  
           	  
	    }    
	  }); 
	  
}


function populate_survey(what,value){
/*	var error_famname = '';
	var error_firstname = '';
	var error_company = '';
	var error_email = '';
    $.ajax({
    	 type :"GET",
    	 url  :"php/survey_error.php" ,
    	 dataType : "json",
    	 success : function(error){
    	     error_famname   = error.famname;
			 error_firstname = error.firstname;
			 error_company   = error.company;
			 error_email     = error.email;
    	 }
    })
	*/
	$.ajax({
	   type: "GET",
	   url: "php/survey.php",	 
	   data:'lechoix='+what+'&le_id='+value,
	   success: function(survey){    		     	    
	   	

          $('div#bg_content').html(survey);        		
           changeBackgrounds('survey');
           
           $('#lenom span').bind("click",function(){
	          var tara = $(this).attr('id');
			  //alert(tara);
			 populate_survey('resultat',tara);
			});
		   
           $('#leretour').bind("click",function(){
				 populate_survey('');
			});
	          
	   /*
           
           $('input#submit_survey').bind("click", function(){
           	
           	if ($('input[@name=famname]').val()=='')
           	 {
           	       alert(error_famname);	
           	 }
           	  else 	if ($('input[@name=firstname]').val()=='')
           	   {
           	   	 alert(error_firstname);
           	   } else if ($('input[@name=company]').val()=='')
           	    {
           	    	alert(error_company);
           	    } else if ($('input[@name=email]').val()=='')
           	     {
           	     	alert(error_email);
           	     } else
           	      {
           	        //data proccessing is ok
           	        

           	        
		 			  var date1 =  $('input[@type=text]').serialize(); 			      			  
		 			  var date2 =  $('input[@type=checkbox][@checked]').serialize(); 			      			  
  		 			  var date3 =  $('input[@type=radio][@checked]').serialize(); 			   
  		 			  var date = date1+'&'+date2+'&'+date3;                                            		 			  
		 			        $.ajax({
							   type: "POST",
							   url: "php/add_survey.php",	   
							   data:date,
							   success: function(raspuns){    		     	    			           
							   	  //surveyul a fost comeplatat cu success
                                     $('#survey_table').hide('slow');
                                     $('#survey_thank').html(raspuns);
							    }    
							  }); 
           	      } 
            })*/;
           
	    }    
	  }); 
}

function populate_privacy(){
	var address ='<div class="cleft">';			
			
	var rest = ' <div class="clear"></div>' +			     
			     '<div class="clear"></div>'+
  		        '</div> ';
		
	var cright='<div class="cright">'+
			   '<img src="images/prelations.gif" alt="" />'+
			   '<div class="bar"></div>'+
        		'</div>';
        		
     $.ajax({
	   type: "GET",
	   url: "php/index_privacy.php",	   
	   success: function(stire){    		     	    
           $('div#bg_content').html(address+stire+rest+cright);        		 
	    }    
	  }); 
}




function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

