//(id of advertisement,the note of this id(it null if the action is check),action to do(note,check),mador  catid)
//var clearloadT;
var userid='';
var tmp_user='';
var path="../"
var go_ajax='';
var star_flag='';

var b_version=navigator.appVersion;
if(b_version.indexOf('MSIE 6.0')==17){
	iconHeera='iconHeera.gif';
}else{
	iconHeera='iconHeera.png';
}
//		  check_it('../','295707','','checkbox','2','1','', 'my_table')
function check_it(path, checkid, note, action, CatId, SubCatId, mode, my_table)
{
	//alert(path+','+checkid+','+note+','+action+','+CatId+','+SubCatId+','+mode+','+my_table)

if( !my_table )
	my_table='my_table';

 var total_rows="";
		if(SubCatId=='' ||SubCatId=='null'  )SubCatId=0;	
		
		//CatId=CatId+"_"+SubCatId;
			//alert(SubCatId);
 switch (action)
 {
		  
   case 'checkbox':
/*   coockiname=CatId + "_star_" + checkid;
   if(userlid != 'none')coockiname=coockiname+ "_" + userlid;*/
		if(document.getElementById('star_'+checkid))
		{
			splitadd=document.getElementById('star_'+checkid).src;
			
		}
		if(window.document.getElementById('star_'+checkid)){
			
			splitadd=window.document.getElementById('star_'+checkid).src;
		}
		try
		{
			if(window.opener && window.opener!=null && window.opener!='undefined'){
				if(window.opener.document) {
					if(window.opener.document.getElementById('star_'+checkid)){
						
						splitadd=window.opener.document.getElementById('star_'+checkid).src;
					}
				}
			}
		}
		catch(ex)
		{
		}

		splitadd=splitadd.substring(splitadd.length-18,splitadd.length)

		if(splitadd=="iconKohavWhite.jpg")
		{
			
		 
		//////////////////db//////////////
							 
		var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&action=insert_star';
		var myAjax = new Ajax.Request(
					  sendto
					,
					{
						method: 'get',
						
						onComplete: function(response) {
							//alert(response.responseText);
							if( response.responseText=="-1" || response.responseText==-1){
								alert('אין באפשרותך לסמן מעבר ל-50 מודעות במדור זה');
								star_flag=-1;
							}else
								star_flag='';

		///////////////////////////////////////////////////////////////////////
							 if(star_flag==''){
							  
							  if(document.getElementById('star_'+checkid))
							  {
							  document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg"; 
							  }
							  if(window.document.getElementById('star_'+checkid))
							  {
								
								window.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg"; 
							  }

							  try
							  {
								  if(window.opener && window.opener!=null && window.opener!='undefined'){
									  if(window.opener.document.getElementById('star_'+checkid))
									  {
									  
										window.opener.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg"; 
									  }
								  }
							  }
							  catch(ex)
							  {
							  }

							  if(document.getElementById('inner_check_'+checkid))
								document.getElementById('inner_check_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/comment_textarea/04_27B.gif"; 
							  
							  
							  if(document.getElementById('inner_check2_'+checkid))
								document.getElementById('inner_check2_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/comment_textarea/04_28b.jpg"; 
							 
							  if(document.getElementById('ifram_info'+checkid))  //assaf 13/01/2009
							  {
									if(document.frames['ifram_info'+checkid].document.getElementById('inner_check_'+checkid)){
									  document.frames['ifram_info'+checkid].document.getElementById('inner_check_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/comment_textarea/04_27B.gif";
									}	  
							  }
							  
								
																									
							
							  if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && document.getElementById('print_td_'+CatId+'_'+SubCatId))
								{
									document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
									document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
								}
								
								
								 if(window.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && window.document.getElementById('print_td_'+CatId+'_'+SubCatId))
								{
									window.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
									window.document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
								}
						  }

		///////////////////////////////////////////////////////////////////////
				}//onComplete: function(response) {
		
			  }
					 
		   );
		//////////////db end//////////////
		 
	  }else{	// if(splitadd=="iconKohavWhite.jpg")
		   
			 
			if(mode=='my')//if uncheck from private area
			{
				
			   if(confirm('?האם את/ה בטוח/ה שברצונך להסיר את המודעה \n\n   (במידה וקיימת הערה במודעה גם היא תמחק)'))
			   {
				   var total_yad1;
				   //////////////////db//////////////
					//alert(CatId+","+SubCatId+","+my_table);					 
					var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&action=delete_star';
					var myAjax = new Ajax.Request(
								  sendto
								,
								{
									method: 'get',
									asynchronous:false,
									
									onComplete: function(response) {
											//alert("response.responseText="+response.responseText+"\nCatId="+CatId+"\nSubCatId="+SubCatId);
										total_rows=response.responseText;
											//alert("total_rows="+total_rows);
										if( total_rows==0 ){
											//alert(CatId+','+SubCatId+','+my_table);
											write_no_record(CatId, SubCatId, my_table);
										}else if( CatId==3 && SubCatId==2 ){
											total_rows=total_rows.split(',');
											total_yad1=total_rows[1];
										}

									}
					
						  }
								 
					   );
					//////////////db end//////////////
					//alert(my_table);
					CatIddelnote = CatId.split('_');
					go_ajax=-1;
					check_it(path, checkid, '', 'note', CatIddelnote[0], SubCatId, '', my_table);//DELET NOTE TO
					if(document.getElementById('ifram_info'+checkid)){
							document.getElementById('ifram_info'+checkid).src=document.getElementById('ifram_info'+checkid).src;
					}
					try
					{
						if(window.opener && window.opener!=null && window.opener!='undefined'){
							location.reload();
						}
					}
					catch(ex)
					{
					}

					if(document.getElementById('star_'+checkid)){
						document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
						//document.images['star_'+checkid].src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
					}
				 
					if(document.getElementById('tr_'+checkid)){
						document.getElementById('tr_'+checkid).style.display='none';
					}
					/*if(document.getElementById('tr_Info_'+SubCatId+'_'+checkid)){
						document.getElementById('tr_Info'+SubCatId+'_'+checkid).style.display='none';
					}*/
					if(window.document.getElementById('tr_'+checkid)){
						window.document.getElementById('tr_'+checkid).style.display='none';
					}
					if(document.getElementById('InfoTr'+checkid)){
						document.getElementById('InfoTr'+checkid).style.display='none';
					}
					if(window.document.getElementById('InfoTr'+checkid)){
						window.document.getElementById('InfoTr'+checkid).style.display='none';
					}
					if(document.getElementById('star_'+checkid+"_dis"))
						document.getElementById('star_'+checkid+"_dis").src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
					if( window.document.getElementById('star_'+checkid+"_dis") ) 
						window.document.getElementById('star_'+checkid+"_dis").src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
							
							//alert("total_yad1="+total_yad1);
					if( CatId==3 && SubCatId==2 && total_yad1==0 ){
							//alert("window.document.getElementById('yad1_title')="+window.document.getElementById('yad1_title'));
						if( window.document.getElementById('yad1_title') )
							window.document.getElementById('yad1_title').style.display='none';					
						if( window.document.getElementById('yad1_details') )
							window.document.getElementById('yad1_details').style.display='none';
					}
			   }
				
			}else{//if(mode=='my')
				
		   
					   //////////////////db//////////////
				//alert(CatId+','+SubCatId+','+checkid+','+userid+','+tmp_user)						 
				var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&action=delete_star';
				var myAjax = new Ajax.Request(
						sendto
						,
						{
								method: 'get',
									
								onComplete: function(response) {
									
									//alert(total_rows);
									////////////////assaf 19/01/09/////////////////////////////////////////
									total_rows=response.responseText;
									if( total_rows==0 ){
										if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId)){
											document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='none'
											document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='none'
										}
										if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis')){
										   document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
										   document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
										}

									}else{
										if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId)){
											document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
											document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
										}
										if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis')){
										   document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').style.display='block'
										   document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').style.display='block'
										}

									}
									////////////////assaf 19/01/09/////////////////////////////////////////
									//alert(total_rows);

								}
					
						}
								 
				);
					//////////////db end//////////////
				if(document.getElementById('star_'+checkid)){
					document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
				}
				if(window.document.getElementById('star_'+checkid)){
					window.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
				}
				try
				{
					if(window.opener && window.opener!=null && window.opener!='undefined'){
						if(window.opener.document.getElementById('star_'+checkid)){
							window.opener.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";
						}
					}
					if(window.opener && window.opener!=null && window.opener!='undefined'){
						location.reload();
					}
				}
				catch(ex)
				{
				}

				CatIddelnote = CatId.split('_');
				go_ajax=-1;
				check_it(path, checkid, '', 'note', CatIddelnote[0], SubCatId, '', my_table);//DELET NOTE TO
				if(document.getElementById('ifram_info'+checkid)){
					document.getElementById('ifram_info'+checkid).src=document.getElementById('ifram_info'+checkid).src;
				}
				if(window.document.getElementById('ifram_info'+checkid)){
					 window.document.getElementById('ifram_info'+checkid).src=window.document.getElementById('ifram_info'+checkid).src;
				}

			}
		
			/*assaf 15/02/2009
			if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && document.getElementById('print_td_'+CatId+'_'+SubCatId))
			{
				  if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block')
					{
						
								for(i=0;i<starsIds.length;i++)
								 {
									splitadd=document.getElementById('star_'+starsIds[i]).src
									splitadd=splitadd.substring(splitadd.length-13,splitadd.length)
									if(splitadd=="iconKohav.jpg")
									{
										 
										  document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
										  document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
										   break;
									}else{
										document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='none'
										document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='none'
									
									}
									
								 }
								 
					 }
			} */ 
			
	  }
				 
  break ;//checkbox
		
  case 'note':
		
	
		coockiname=CatId+"_"+SubCatId+"_note_" + checkid;
		//if(userlid != 'none') coockiname=coockiname+ "_" + userlid;

		for(ii=0;ii<note.length;ii++)
					{
			        note=note.replace("'"," ");
                    note=note.replace('"'," ");
                    
					}
		          
		for(ii=0;ii<note.length;ii++)
		{
			note=note.replace("'"," ");
			note=note.replace('"'," ");
			
		}
		
		if(note!='' && note != null ) 
		{
			
			//////////////////db//////////////
			var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&note='+note+'&action=insert_note';
			var myAjax = new Ajax.Request(
						  sendto
						,
						{
							method: 'get',
							
							onComplete: function(response) {

							if( response.responseText=="-1" || response.responseText==-1){
								alert('אין באפשרותך לסמן מעבר ל-100 מודעות במדור זה');
								star_flag=-1;
							}else
								star_flag='';

		///////////////////////////////////////////////////////////////////////
							 if(star_flag==''){
								if(window.parent.document.getElementById('star_'+checkid)){
									window.parent.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg"; 
								}
								try
								{
									 if(window.opener && window.opener!=null && window.opener!='undefined'){
										if(window.opener.document.getElementById('star_'+checkid)){
											window.opener.document.getElementById('star_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg"; 
										}
									 }
								}
								catch(ex)
								{
								}

								if(document.getElementById('inner_check_'+checkid))
								{
									document.getElementById('inner_check_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/comment_textarea/04_27B.gif"; 
								}
								  
								if(document.getElementById('inner_check2_'+checkid))
								{
								
									document.getElementById('inner_check2_'+checkid).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/comment_textarea/04_28b.jpg"; 
								}

								  
								document.getElementById('innr_comment').innerHTML=note;
								if( window.parent.document.getElementById('note_txt_'+checkid) ){
									window.parent.document.getElementById('note_txt_'+checkid).value=note;
								}
								document.getElementById('note_textarea').style.display='none';
								document.getElementById('innr_comment').style.display='block';

								if(window.parent.document.getElementById('note_td_'+checkid)){
									window.parent.document.getElementById('note_td_'+checkid).innerHTML='<IMG id=\''+CatId + '_note_' + checkid+'\'  onmouseover="show_note(\''+path+'\',\''+coockiname+'\',this.id,'+checkid+')"  SRC="'+path+'imageInsidePage/'+iconHeera+'" WIDTH="20" HEIGHT="17" BORDER="0" ALT="" onmouseout="document.getElementById(\'note_div_'+checkid+'\').style.display=\'none\'">';
								}

								try
								{
									if(window.opener && window.opener!=null && window.opener!='undefined'){
										if(window.opener.document.getElementById('note_td_'+checkid)){
											window.opener.document.getElementById('note_td_'+checkid).innerHTML='<IMG id=\''+CatId + '_note_' + checkid+'\'  onmouseover="show_note(\''+path+'\',\''+coockiname+'\',this.id,'+checkid+')"  SRC="'+path+'imageInsidePage/'+iconHeera+'" WIDTH="20" HEIGHT="17" BORDER="0" ALT="" onmouseout="document.getElementById(\'note_div_'+checkid+'\').style.display=\'none\'">';
										}
									}
								}
								catch(ex)
								{
								}

								if(window.parent.document.getElementById('note_td_'+checkid+'_dis')){
									window.parent.document.getElementById('note_td_'+checkid+'_dis').innerHTML='<IMG id=\''+CatId + '_note_' + checkid+'\'  onmouseover="show_note(\''+path+'\',\''+coockiname+'\',this.id,'+checkid+')"  SRC="'+path+'imageInsidePage/'+iconHeera+'" WIDTH="20" HEIGHT="17" BORDER="0" ALT="" onmouseout="document.getElementById(\'note_div_'+checkid+'\').style.display=\'none\'" >';
								}
								try
								{
									if(window.opener && window.opener!=null && window.opener!='undefined'){
										if(window.opener.document.getElementById('note_td_'+checkid+'_dis')){
											window.opener.document.getElementById('note_td_'+checkid+'_dis').innerHTML='<IMG id=\''+CatId + '_note_' + checkid+'\'  onmouseover="show_note(\''+path+'\',\''+coockiname+'\',this.id,'+checkid+')"  SRC="'+path+'imageInsidePage/'+iconHeera+'" WIDTH="20" HEIGHT="17" BORDER="0" ALT="" onmouseout="document.getElementById(\'note_div_'+checkid+'\').style.display=\'none\'" >';
										}
									}
								}
								catch(ex)
								{
								}

								if(window.parent.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId)){
									window.parent.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
									window.parent.document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
								}
								if(window.parent.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis')){
									window.parent.document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').style.display='block'
									window.parent.document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').style.display='block'
								}
							 }else{
								document.getElementById('note_textarea').innerHTML='';
								document.getElementById('note_textarea').style.display='none';
								document.getElementById('innr_comment').style.display='block';
								//document.getElementById('note_textarea').focus();
							 }
							
		///////////////////////////////////////////////////////////////////////			
					}//onComplete: function(response) {
			
				  }
						 
			   );
			//////////////db end//////////////

			
			
			
		  }else{	// if(note!='' && note != null)
			
			if( go_ajax!=-1){					 
				//////////////////db//////////////		 
				var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&note='+note+'&action=delete_note';
				
				var myAjax = new Ajax.Request(
							  sendto
							,
							{
								method: 'get',
								
								onComplete: function(response) {
								
											
						}//onComplete: function(response) {
				
					  }
							 
				   );
				//////////////db end//////////////
			}	//if( go_ajax!=-1){
			
			go_ajax='';
			
			if(window.parent.document.getElementById('note_td_'+checkid)){
				window.parent.document.getElementById('note_td_'+checkid).innerHTML='&nbsp;';
			}
			try
			{
				if(window.opener && window.opener!=null && window.opener!='undefined'){
					if(window.opener.document.getElementById('note_td_'+checkid)){
						window.opener.document.getElementById('note_td_'+checkid).innerHTML='&nbsp;';
					}
				}
			}
			catch(ex)
			{
			}

			if(window.parent.document.getElementById('note_td_'+checkid+'_dis'))
			{
				window.parent.document.getElementById('note_td_'+checkid+'_dis').innerHTML='&nbsp;';
			}
			if(window.parent.document.getElementById('note_txt_'+checkid))
			{	
				window.parent.document.getElementById('note_txt_'+checkid).value='';
			}

		}
							

  break ;//note
 }//	switch  
}//check_it



function readCookie(name) {
	var nameEQ = name + "=";
	tmp_fromdb='';

	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) 
		{

	      	outputck=c.substring(nameEQ.length,c.length);
	      	outputck=outputck ;
	      

		return outputck;	
		}
		
	}
	return null;
}

//show_note('../','5_0_note_250695',this.id,250695)
function show_note(path, cookienoteid, BubbleImgid, checkid)
{
	var load_txt=0;

	if( document.getElementById('note_txt_'+checkid) ){
		if( document.getElementById('note_txt_'+checkid).value!='' ){
			var tmp_fromdb=document.getElementById('note_txt_'+checkid).value;
			document.getElementById('txt_note_div_'+checkid).innerHTML=tmp_fromdb;
			document.getElementById('note_div_'+checkid).style.display='block';
			load_txt=1;
		}
	}

	if( load_txt==0 ){
		namesendarr=cookienoteid.split('_');
		var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+namesendarr[0]+'&subcatid='+namesendarr[1]+'&idtocheck='+namesendarr[3]+'&userid='+userid+'&tmp_user='+tmp_user+'&action=show_note';
		var myAjax = new Ajax.Request(
			sendto
			,
			{
			method: 'get',
						
				onComplete: function(response) {
								 
					tmp_fromdb=response.responseText;
					if(tmp_fromdb!=''){	  
								
						document.getElementById('txt_note_div_'+checkid).innerHTML=tmp_fromdb;
						document.getElementById('note_div_'+checkid).style.display='block';

						if( document.getElementById('note_txt_'+checkid) )
							document.getElementById('note_txt_'+checkid).value=tmp_fromdb;
								
					}//if(tmp_fromdb!=''){			
										
				}//onComplete: function(response) {

			}		 
		   );
	}	// if( load_txt==0 ){ 
}
  

function check_on_load(path,idtocheck,CatId,SubCatId)
{
   Cat_SubCat_Cookie=readCookie('Cat_'+CatId+'_'+SubCatId);
   if(SubCatId=='' ||SubCatId=='null' )
	   SubCatId=0;	
   
	checkiftmpu=readCookie('Tmp_CustID')
	
	if(checkiftmpu!=null && checkiftmpu != '' && Cat_SubCat_Cookie){
	////////////////////////////////////start check stars///////////////////////////////////////
		var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&idtocheck='+idtocheck+'&userid='+userid+'&tmp_user='+tmp_user+'&action=check_on_load_stars';
		var myAjax = new Ajax.Request(
				  sendto
				,
				{
					method: 'get',
					
					onComplete: function(response) {
						 
						tmp_fromdb=response.responseText;
							//alert("tmp_fromdb="+tmp_fromdb);
						if(tmp_fromdb!='' && tmp_fromdb!="-1" && tmp_fromdb!=-1){	
							
							nameidarr=tmp_fromdb.split(';');
								//alert("nameidarr.length="+nameidarr.length);
							for(i=0 ; i<nameidarr.length ; i++)
							{
								tmp_nameidarr="";
								tmp_nameidarr=nameidarr[i];
								new_nameidarr=tmp_nameidarr.split('_');
								
							
								////////////////// stars ///////////////////////
								if( new_nameidarr[1]==1 && document.getElementById('star_'+new_nameidarr[0]) && document.getElementById('note_td_'+ new_nameidarr[0]) )
								{
									document.getElementById('star_'+new_nameidarr[0]).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohav.jpg";
								}
																	
								////////////////// notes ///////////////////////
								coockiname=CatId +"_"+SubCatId+"_note_" + new_nameidarr[0];
								if( new_nameidarr[2]==1 && document.getElementById('star_'+new_nameidarr[0]) && document.getElementById('note_td_'+ new_nameidarr[0]))
								{
									 
									document.getElementById('note_td_'+ new_nameidarr[0]).innerHTML='<IMG id=\''+CatId +'_note_' + new_nameidarr[0]+'\'  onmouseover="show_note(\''+path+'\',\''+coockiname+'\',this.id,'+new_nameidarr[0]+')"  SRC="'+path+'imageInsidePage/'+iconHeera+'" WIDTH="20" HEIGHT="17" BORDER="0" ALT="" onmouseout="document.getElementById(\'note_div_'+new_nameidarr[0]+'\').style.display=\'none\'">';

								}
									
							}
							if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && document.getElementById('print_td_'+CatId+'_'+SubCatId))
							{
							  document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
							  document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
							}
						}else if(tmp_fromdb=="-1" || tmp_fromdb==-1){ //if(tmp_fromdb!='' && tmp_fromdb!="-1" && tmp_fromdb!=-1){
							if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && document.getElementById('print_td_'+CatId+'_'+SubCatId))
							{
							  document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='block'
							  document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='block'
							}
						}	//}else if(tmp_fromdb=="-1" || tmp_fromdb==-1){ //if(tmp_fromdb!='' && tmp_fromdb!="-1" && tmp_fromdb!=-1){
								
					}//onComplete: function(response) {

		  }
				 
	   );	// var myAjax = new Ajax.Request(

	}
	
}


function limit_numchars()
{
	limit = 70;
	t=document.getElementById('note_textarea').value;
	if(t.length > limit)
	{	
		tex = t.substring(0,limit);
		document.getElementById('note_textarea').value=tex;
		
	}
}

//show_textarea('../',250119,'5','0')
function show_textarea(path, checkid, CatId, SubCatId, my_table)
{
	
	//alert(checkid)	
	if(window.parent.document.getElementById('path_flag'))path='../../';//if is function call from myadv

	 if(document.getElementById('innr_comment').style.display=='block' ||document.getElementById('innr_comment').style.display=='')
	 {
		document.getElementById('note_textarea').style.display='block';
		document.getElementById('innr_comment').style.display='none';
		document.getElementById('note_textarea').focus();
		return;
	 }else{
		limit_numchars();
		mov_t=document.getElementById('note_textarea').value;
		//document.getElementById('note_div_'+checkid).value=mov_t;  //assaf

		if(mov_t==''){
			
			check_it(path, checkid, '', 'note', CatId, SubCatId, '', my_table);
			all_t='כתבו הערה כאן';
			document.getElementById('innr_comment').innerHTML=all_t;
		}else{
			var notearr= mov_t.split(' ');
			 mov_t="";
		   for(ii=0;ii<notearr.length;ii++)
			{
				tempT=notearr[ii];
				if(tempT.length>20){
					tempT1=tempT.substring(0, 20);
					tempT2=tempT.substring(21,tempT.length );
					
					if(tempT2.length>20){
						
						tempT3=tempT2.substring(21,tempT2.length );
						tempT2=tempT2.substring(0,20 );
						
					}else{
						
						tempT3='';
					}
					
						
					if(tempT3.length>20){
						
						tempT4=tempT3.substring(21,tempT3.length );
						tempT3=tempT3.substring(0,20 );
					}else{
						
					   tempT4='';
					
					}
					
					notearr[ii]=tempT1+(tempT2!=''?" "+tempT2:'')+(tempT3!=''?" "+tempT3:'')+(tempT4!=''?" "+tempT4:'');
				tempT1='';
				tempT2='';
				tempT3='';
				tempT4='';
				}
				
			
				if(notearr[ii]!=' '){
					
				mov_t=mov_t+notearr[ii]+" ";
				}
				
			}
			note=mov_t;
			check_it(path, checkid, note, 'note', CatId, SubCatId, '', my_table);
				
			//check the star start

			
			/*coockiname=CatId+"_"+SubCatId+"_star_" + checkid;*/
		/*   if(userlid != 'none')coockiname=coockiname+ "_" + userlid;
			 document.cookie =coockiname + "=1" + expires + "; path=/";*/
			 
		 //check the star end
	   

			
		}
		
		return;
		
	 }
 
 
}
function insert_text(checkid,CatId,SubCatId)
{
	checkiftmpu=readCookie('Tmp_CustID')
	if(checkiftmpu!=null && checkiftmpu != ''){
    
	//////////////////db//////////////												 
	var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&adv_id='+checkid+'&userid='+userid+'&tmp_user='+tmp_user+'&action=read_note';
	var myAjax = new Ajax.Request(
		sendto
		,
		{
			method: 'get',
			onComplete: function(response) {
						
				mov_t=response.responseText;
				if(mov_t!='' && mov_t!=null){
					document.getElementById('note_textarea').value=mov_t;
					document.getElementById('innr_comment').innerHTML=mov_t;
				}	
			}	// onComplete: function(response) {
	
	    }
	             
	   );
	//////////////db end//////////////
	}	// if(checkiftmpu!=null && checkiftmpu != ''){
}

function replace_cherset_firefox(note,action)
{
	 switch (action){	
		
	 case 'incode':
		incode_set = new  Array();
		incode_set['א']=224;
		incode_set['ב']=225;
		incode_set['ג']=226;
		incode_set['ד']=227;
		incode_set['ה']=228;
		incode_set['ו']=229;
		incode_set['ז']=230;
		incode_set['ח']=231;
		incode_set['ט']=232;
		incode_set['י']=233;
		incode_set['ך']=234;
		incode_set['כ']=235;
		incode_set['ל']=236;
		incode_set['ם']=237;
		incode_set['מ']=238;
		incode_set['ן']=239;
		incode_set['נ']=240;
		incode_set['ס']=241;
		incode_set['ע']=242;
		incode_set['ף']=243;
		incode_set['פ']=244;
		incode_set['ץ']=245;
		incode_set['צ']=246;
		incode_set['ק']=247;
		incode_set['ר']=248;
		incode_set['ש']=249;
		incode_set['ת']=250;

		var Outputnum='';
									
		for(ii=0;ii<note.length;ii++)
		{
			 ck_cher=note.charAt(ii)
		
			 if(incode_set[ck_cher])
			 {
				if(Outputnum!=''){
					Outputnum=Outputnum+incode_set[ck_cher]+"^";
				}else{
					Outputnum=incode_set[ck_cher]+"^";
				} 

			 }else{

				if(Outputnum!=''){
					
					Outputnum=Outputnum+ck_cher+"#";
				}else{
					
					Outputnum=ck_cher+"^";
				}
			 }
			 
		}	
							
		return Outputnum;
		break;
				   
	case 'decode':

		decode_set = new  Array();
		decode_set[224]='א';
		decode_set[225]='ב';
		decode_set[226]='ג';
		decode_set[227]='ד';
		decode_set[228]='ה';
		decode_set[229]='ו';
		decode_set[230]='ז';
		decode_set[231]='ח';
		decode_set[232]='ט';
		decode_set[233]='י';
		decode_set[234]='ך';
		decode_set[235]='כ';
		decode_set[236]='ל';
		decode_set[237]='ם';
		decode_set[238]='מ';
		decode_set[239]='ן';
		decode_set[240]='נ';
		decode_set[241]='ס';
		decode_set[242]='ע';
		decode_set[243]='ף';
		decode_set[244]='פ';
		decode_set[245]='ץ';
		decode_set[246]='צ';
		decode_set[247]='ק';
		decode_set[248]='ר';
		decode_set[249]='ש';
		decode_set[250]='ת';
						
						
		for(g=0;g<note.length;g++){

			for (ii=224;ii<251;ii++){	

				note=note.replace(ii+'^', decode_set[ii]);
			
			}

			note=note.replace('#','');
		}	
			
			
		return note;	
		break;
	}	// switch (action){	
}
//change_mode('../','all','','2','5',starsIds_tiv, '')

function change_mode(path, mode, file, CatId, SubCatId, starsIds, PageNum, main_table, my_table)
{
	if( PageNum=='undefined' || PageNum=='' || PageNum==null)
		PageNum='1';
	switch (mode){	
	case 'all':
		if( document.getElementById('loading_'+CatId+'_'+SubCatId) )
			document.getElementById('loading_'+CatId+'_'+SubCatId).style.display='none';
		document.getElementById(my_table).innerHTML='';

		for(i=0;i<starsIds.length;i++){		
			if( document.getElementById('star_'+starsIds[i]+'_dis') ){
				  document.getElementById('star_'+starsIds[i]+'_dis').id='star_'+starsIds[i];
				  document.getElementById('note_td_'+ starsIds[i]+'_dis').id='note_td_'+ starsIds[i];
			}
			if(document.getElementById('tr_'+ starsIds[i]+'_dis')){
				document.getElementById('tr_'+ starsIds[i]+'_dis').id='tr_'+ starsIds[i];
			}
			if(document.getElementById('ifram_info'+ starsIds[i]+'_dis')){
				document.getElementById('ifram_info'+ starsIds[i]+'_dis').id='ifram_info'+ starsIds[i];
			}

			if( document.getElementById('Info'+ starsIds[i]+'_dis') )
				document.getElementById('Info'+ starsIds[i]+'_dis').id='Info'+ starsIds[i];
			if( document.getElementById('TxtID'+ starsIds[i]+'_dis') )
				document.getElementById('TxtID'+ starsIds[i]+'_dis').id='TxtID'+ starsIds[i];
			if( document.getElementById('note_div_'+ starsIds[i]+'_dis') )
				document.getElementById('note_div_'+ starsIds[i]+'_dis').id='note_div_'+ starsIds[i];
			if( document.getElementById('txt_note_div_'+ starsIds[i]+'_dis') )
				document.getElementById('txt_note_div_'+ starsIds[i]+'_dis').id='txt_note_div_'+ starsIds[i];
		}

		if(document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis') && document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis') ){
			document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').id='deleteall_td_'+CatId+'_'+SubCatId; 
			document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').id='print_td_'+CatId+'_'+SubCatId;
		}
		document.getElementById(my_table).style.display='none';
		document.getElementById(main_table).style.display='block';

		break;
	        
	case 'my':
		drawControll('loading_'+CatId+'_'+SubCatId,'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000','objFlashLayer','',100,30,path+'Flash/loading.swf','#ffffff');
		if(document.getElementById('backk')){
			clearloadT=setInterval("document.getElementById('backk').style.display='block';document.getElementById('loading_"+CatId+"_"+SubCatId+").style.display='block';",2000);
		}else{
			document.getElementById('loading_'+CatId+'_'+SubCatId).style.display='block';
		}
		if(!PageNum){
				//alert("starsIds.length="+starsIds.length+"\nstarsIds="+starsIds/*+"\nstarsIds.split(',')="+temp.length*/)
			for(i=0;i<starsIds.length;i++)
			{
				if( document.getElementById('star_'+starsIds[i]) )
					document.getElementById('star_'+starsIds[i]).id='star_'+starsIds[i]+'_dis';
				if( document.getElementById('note_td_'+starsIds[i]) )
					document.getElementById('note_td_'+ starsIds[i]).id='note_td_'+ starsIds[i]+'_dis';
				if(document.getElementById('tr_'+ starsIds[i])){
					document.getElementById('tr_'+ starsIds[i]).id='tr_'+ starsIds[i]+'_dis';
				}
			  
				if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) && document.getElementById('deleteall_td_'+CatId+'_'+SubCatId) ){
					document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).id='deleteall_td_'+CatId+'_'+SubCatId+'_dis'; 
					document.getElementById('print_td_'+CatId+'_'+SubCatId).id='print_td_'+CatId+'_'+SubCatId+'_dis';
				}
			
				  if( document.getElementById('Info'+starsIds[i]) )
					document.getElementById('Info'+ starsIds[i]).id='Info'+ starsIds[i]+'_dis';
				  if(document.getElementById('ifram_info'+ starsIds[i]))
					 document.getElementById('ifram_info'+ starsIds[i]).id='ifram_info'+ starsIds[i]+'_dis';
				   
				  if( document.getElementById('TxtID'+starsIds[i]) )
					 document.getElementById('TxtID'+ starsIds[i]).id='TxtID'+ starsIds[i]+'_dis';
				  if( document.getElementById('note_div_'+starsIds[i]) )
					 document.getElementById('note_div_'+ starsIds[i]).id='note_div_'+ starsIds[i]+'_dis';
				  if( document.getElementById('txt_note_div_'+starsIds[i]) )
					 document.getElementById('txt_note_div_'+ starsIds[i]).id='txt_note_div_'+ starsIds[i]+'_dis';
			}
		}
				
			 //change_mode('../','my','pets_getmytable','5','0',starsIds,'')   
		getMyChecks(path, file, CatId, SubCatId, userid, PageNum, main_table, my_table)
		break;
	}
}

function delete_all(path, CatId, SubCatId, file, main_table, my_table)
{
	if(confirm('האם אתה בטוח? פעולתך תסיר את כל המודעות מהרשימה')){
		
		//////////////////db//////////////				 
		var sendto=path+'ajax/get_mycomment_db.php?sid='+Math.random()+'&catid='+CatId+'&subcatid='+SubCatId+'&action=delete_all';
		var myAjax = new Ajax.Request(
			sendto,
			{
				method: 'get',
				
				onComplete: function(response) {

					ids=response.responseText;
                    checkid=ids.split(";");
                    for(i=0;i<checkid.length;i++)
                    {
						if(document.getElementById('star_'+checkid[i]+"_dis"))
							document.getElementById('star_'+checkid[i]+"_dis").src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";	
	                    if(file.lastIndexOf('main_table')!=-1 && document.getElementById('star_'+checkid[i]))
							document.getElementById('star_'+checkid[i]).src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/iconKohavWhite.jpg";	

						if(window.document.getElementById('note_td_'+checkid[i])){
							window.document.getElementById('note_td_'+checkid[i]).innerHTML='&nbsp;';
						}
						if(window.document.getElementById('note_td_'+checkid[i]+'_dis')){
							window.document.getElementById('note_td_'+checkid[i]+'_dis').innerHTML='&nbsp;';
						}
						  
					}
					if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId)){
						document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='none'
						document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='none'
					}
					if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis')){
					   document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
					   document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
					}

					if(file.lastIndexOf('main_table')==-1){
						//alert(main_table);
						setTimeout("getMyChecks('"+path+"','"+file+"',"+CatId+","+SubCatId+",'','', '"+main_table+"', '"+my_table+"')",1500);
					}
						    
				}
		
			}
		             
		);
		//////////////db end//////////////
  	
	}					
}


function HistoryMarker(CatId,SubCatId,checkid)
{
	if(SubCatId=='' ||SubCatId=='null' )SubCatId=0;	
		
	CatId=CatId+"_"+SubCatId;
	
	var date = new Date();
	date.setTime(date.getTime()+(60*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();

	document.cookie =CatId + "_HM_" + checkid + "=1"+ expires + "; path=/";

}


function write_no_record(CatId, SubCatId, my_table)
{
	var main_table;

	if(my_table=="tiv_my_table"){
		my_table="tiv_my_table";
		main_table="tiv_main_table";
	}else{
		my_table="my_table";
		main_table="main_table";
	}
	var str='<TABLE WIDTH=770 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0 dir="rtl" >';
	str+='<TR>';
	str+='	<TD colspan="19" height="40" bgcolor="#eeeff3">&nbsp;</TD>';
	str+='</TR>';
	str+='<TR>';
	//str+='	<TD align="right" WIDTH="3" bgcolor="#eeeff3" HEIGHT="36" style="height: 36px" align="top" style="background-image: url(\'http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/details_left_border.gif\'); background-repeat: repeat-y; background-position: center right; width: 3px;"><IMG SRC="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0" ALT=""><!-- <IMG SRC="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/Bottom_RightPina_02.gif" WIDTH="3" HEIGHT="36" BORDER="0" ALT=""> --></TD>';
	str+='	<TD width=767 style="padding-bottom: 0px;">';
	str+='		<TABLE WIDTH="767" BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0 dir="rtl" background="green">';
	str+='		<TR>';
	str+='			<TD colspan="19" valign="bottom" >';
	str+='			   <table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-image: url(http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/Table_Top_Tab_back.jpg); background-repeat: repeat-x; background-position: center right;height:47px">';
	str+='				<tr >';
	str+='						<td style="border-bottom: 1px solid #dddfde;">&nbsp;</td>';
	str+='						<td  width="182px" style="padding-bottom:0px;cursor: pointer;" valign="bottom"><img id=\'my_all_results_'+CatId+'_'+SubCatId+'\' src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/my_all_results_en.jpg" style="border: 0px"></td>';
	if(my_table=="my_table"){
		str+='						<td  width="182px" style="padding-bottom:0px;border-bottom: 0px;cursor: pointer;" valign="bottom"><img id=\'all_results_'+CatId+'_'+SubCatId+'\' src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/all_results_dis.jpg" style="border: 0px" onclick="change_mode(\'../\', \'all\', \'\', \''+CatId+'\', \''+SubCatId+'\' ,starsIds, \'\', \''+main_table+'\', \''+my_table+'\')"></td>';
	}else{
		str+='						<td  width="182px" style="padding-bottom:0px;border-bottom: 0px;cursor: pointer;" valign="bottom"><img id=\'all_results_'+CatId+'_'+SubCatId+'\' src="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/all_results_dis.jpg" style="border: 0px" onclick="change_mode(\'../\',\'all\',\'\',\''+CatId+'\',\''+SubCatId+'\',starsIds_tiv,\'\', \''+main_table+'\', \''+my_table+'\')"></td>';
	}
	str+='					</tr>';
	str+='				</table>';
	str+='			</TD>';
	str+='		</TR>';
	str+='		<TR>';
	str+='			 <TD colspan="19" align="center" height="30" bgcolor="#eeeff3" style="height:30px;text-align: center; font-family: arial;font-size: 20px;font-weight: bold;color:#515c62 ; ">';
	str+='				 אין מודעות מסומנות. <br>';
	str+='				<span  style="height:40px;text-align: center; font-family: arial;font-size: 15px;font-weight: bold;color:#515c62 ; ">';
	str+='				סמנו את הכוכב המופיע מימין למודעה כדי לשמור את המודעות שעניינו אתכם<br>';
	str+='				בתצוגה זו תוכלו לנהל ולעקוב אחרי המודעות ע"י כתיבת הערות לכל מודעה.';
	str+='				</span>';
	str+='			 </TD>';
	str+='		</TR>';
	str+='		<TR>';
	str+='			 <TD colspan="19" align="center" height="18" background="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/mycom_spacer5.jpg" style="height:30px;text-align:center;"></TD>';
	str+='		</TR>';
	str+='		<TR>';
	str+='			<TD colspan="19" height="26" background="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/mycom_spacer6.jpg">&nbsp;</TD>';
	str+='		</TR>';

	/*str+='      <TR>';
	str+='         <TD colspan=31 style="background-color:  #EEEFF3; background-image: url(\'http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/Bottom_bg_details_yad1.gif\'); background-repeat: repeat-x; background-position: center right;">';
	str+='				<TABLE WIDTH=100% BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0 dir="rtl">';
	str+='					<TR>';
	str+='						<TD WIDTH="38" HEIGHT="38" align="right"><IMG SRC="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/Bottom_End_Details_right_msumanot.gif" WIDTH="38" HEIGHT="38" BORDER="0" ALT=""></TD>';
	str+='						<TD>&nbsp;</TD>';
	str+='						<TD WIDTH="35" align="left" colspan=2><IMG SRC="http://images.yad2.co.il/Pic/site_images/yad2/imageInsidePage/Bottom_End_Details_left_cor_yad1.gif" WIDTH="35" HEIGHT="38" BORDER="0" ALT=""></TD>';
	str+='					</TR>';
	str+='				</TABLE>';
	str+='			</TD>';
	str+='		</TR>';*/
	str+='		</table>';
	str+='	</TD>';
	str+='</TR>';
	str+='</table>';
		
		//alert(str);
		//alert("window.parent.document.getElementById(main_table)="+window.parent.document.getElementById(main_table)+"\nstr="+str)
	if(window.parent.document.getElementById(my_table))
	{		
		window.parent.document.getElementById(my_table).innerHTML=str;
		window.parent.document.getElementById(my_table).style.display='';
		/////////////////////////////assaf 19/01/2009///////////////////////////////////////////////////
		if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId)){
			document.getElementById('deleteall_td_'+CatId+'_'+SubCatId).style.display='none'
			document.getElementById('print_td_'+CatId+'_'+SubCatId).style.display='none'
		}
		if(document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis')){
		   document.getElementById('deleteall_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
		   document.getElementById('print_td_'+CatId+'_'+SubCatId+'_dis').style.display='none'
		}
		//////////////////////////////////////////////////////////////////////////////////////
	}
}
