/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

     /*
      *funkcja zastpuje znak nowej lini podanym parameterm
      *@param idElemnet jest to id z outputText
      *@param elementReplace elemenet ktory bedzie zastepowal znak nowej lini
      */ 
     function replaceElement( idElemnet,  elementReplace){
         var d =$(idElemnet);
         if( d !=null){
            //alert( 'test =' + d );                                  
           //alert( (d.innerHTML).replace( /\n/g, '<br>') );
           d.innerHTML = (d.innerHTML).replace( /\n/g, elementReplace);                  
         }
     }       



    /*
     * sluzy do zamiany linkow w tabeli 
     * @param idElemnet jest to id tabeli
     */  
   function replaceLinkOnPage( idElemnet ){
             //  function replaceLinkOnPage(){
               //    var d = $('chatArea');    
               var d = $(idElemnet);                     
                    // alert( 'test =' + d );                                  
                   //  var test = '';                   
                    
                    //rerular expresion for url for scool.ro
                    var regExp = new RegExp(/(((http:\/\/)?(www\.)?)scool\.ro((\/((\w)+(-)?)*\/)*((\w)+\.jsf)?)?)/g);                   
                    
                    //regular expresion for all url
                    var regExpAllUrl = new RegExp(/(((http:\/\/)?(w{3}\.)?)(\w)+\.[a-z]{2,3}((\/((\w)+(-)?)*\/)*((\/)?(\w)+(\.[a-z]{2,3})?)?)?)/g);                   
                    
                    //regular expresion for user name 
                    var regUser = new RegExp(/^scool ro:/);
                    
                    //regular expresion for http
                    var regHttp = new RegExp( /(http:\/\/)/ );
                    
                    //value form field witch contain post text
                    
                    
                    //value form fild witch contain user nick
                    var user ='';
                    
                    //for(var i = 0 ; i < 3; i++ ){                     
                 for(var i = 0 ; i < d.rows.length; i++ ){                                                
                        
                          var tempString='';
                          var temp ='';
                          
                          temp =  (d.rows[i].cells[1].firstChild.firstChild.innerHTML);                          
                          
                          user =  (d.rows[i].cells[0].firstChild.firstChild.firstChild.lastChild.lastChild.firstChild.firstChild.innerHTML);  
                          
                          //if user is not form regUser the link will be replace only from scool.ro
                          if(regExp.test( temp) && !regUser.test( user)){                             
                              
                              tempString = temp.match( regExp );                             
                              
                              for(var j = 0; j< tempString.length; j++){
                                if( regHttp.test( tempString[j] ) ){ 
                                  temp= temp.replace( tempString[j], '<a href='+tempString[j]+'>'+ tempString[j]+'</a>' );                                 
                                }else  
                                   temp= temp.replace( tempString[j], '<a href='+'http://'+tempString[j]+'>'+ tempString[j]+'</a>' );                                 
                              }  
                              //replace elemnte
                              //d.rows[i].cells[1].firstChild.firstChild.replace(temp);      
                              d.rows[i].cells[1].firstChild.firstChild.innerHTML=temp;      
                                
                          }else{
                               
                               //fild user contain regUser
                               if(regUser.test( user) && regExpAllUrl.test(temp ) ){
                             
                                  tempString = temp.match( regExpAllUrl );                             
                                  
                                  for(var k = 0; k< tempString.length; k++){
                                    //  test +=  '\n' +  tempString[j];
                                    //check whether url contain http://
                                    if( regHttp.test( tempString[k] ) ){ 
                                     //  test+= "zawiera http " +tempString[k] + k +' \n';
                                       temp= temp.replace( tempString[k], '<a href='+tempString[k]+'>'+ tempString[k]+'</a>' );                                                                                                              
                                    }else{
                                      //test+= tempString[k] + k +' \n';
                                      temp= temp.replace( tempString[k], '<a href='+'http://'+tempString[k]+'>'+ tempString[k]+'</a>' );                                     
                                     
                                     //test+= temp +'\n';
                                    }
                                      
                                      //test+=temp;
                                    }
                                    //replace elemnte
                                    //d.rows[i].cells[1].firstChild.firstChild.replace(temp);      
                                    d.rows[i].cells[1].firstChild.firstChild.innerHTML=temp;      
                                } 
                                
                          }
                             
                      //temp = temp.replace(/(http:\/\/)?(www\.)?scool.ro((\/((\w)+(-)?)*\/)*((\w)+\.jsf)?)?/g, "   <a href=''>test</a>  ");                           
                      //test +='\n'+ temp+ '\n';
                      //test+= '\n\n';                            
                    }
                       //alert( test );
                     
               }
      