$(document).ready(
	function() 
	{
		$('div#help').height( $('body').height()+250).fadeTo("slow", 0.9);
		$('div#helpBar').css("margin-left", ($('body').width() - 500)/2);
		$('div#helpContent').css("margin-left", ($('body').width() - 500)/2);
		$(".menuLink").mouseover( 
			function() 
			{
				idValue=$(this).attr("id");
				if ((idValue == 1) || (idValue == 3))
				{
					$("#menuLinkDisplay").show("fast");
					//alert(idValue);
//					$.post('/lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
					$.post('lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
					{
						  $('#menuLinkDisplay').html(data);
					});
				}
				else
				{
					$("#menuLinkDisplay").hide("fast");
				}
			}
		);

		$(".menuLink_on").mouseover( 
			function() 
			{
				idValue=$(this).attr("id");
				if ((idValue == 1) || (idValue == 3))
				{
					$("#menuLinkDisplay").show("fast");
					//alert(idValue);
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
//					$.post('/lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
					$.post('lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
					{
						  $('#menuLinkDisplay').html(data);
					});
				}
				else
				{
					$("#menuLinkDisplay").hide("fast");
				}
			}
		);

		$(".content-text").mouseover( 
			function() 
			{
				idValue=$(".menuLink_on").attr("id");
				if ((idValue == 1) || (idValue == 3))
				{
					$("#menuLinkDisplay").show("fast");
					//alert(idValue);
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
//					$.post('/lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
					$.post('lib/contentMenuSecondAction.php',{txtLink: idValue}, function(data) 
					{
						  $('#menuLinkDisplay').html(data);
					});
				}
				else
				{
					$("#menuLinkDisplay").hide("fast");
				}
			}
		);
		
		$(".actionOptAdd").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Add","Search");
				curSelector="txtProjectPR_"+idCurent;
				p_pr=$("input[name="+curSelector+"]").val();
				curSelector="txtProjectPRHome_"+idCurent;
				p_prhome=$("input[name="+curSelector+"]").val();
				p_current=idCurent.replace("Search_","");
//				linkRank = $("input.ProjectLinkTitle"+idCurent).val();
				p_txtProjectHomeLink=$("input.ProjectHomeLink"+idCurent).val();
				p_txtProjectDescription1=$("textarea.ProjectDescription1"+idCurent).val();
//				alert(p_txtProjectDescription1);
//				p_txtProjectPageLink=$("input.ProjectPageLink1"+idCurent).val();
				curSelector="txtProjectPageLink1_"+idCurent;
				p_txtProjectPageLink=$("input[name="+curSelector+"]").val();
//				alert(p_txtProjectPageLink);
				curSelector="txtProjectLinkTitle1_"+idCurent;
				p_txtProjectLinkTitle1=$("input[name="+curSelector+"]").val();
//				alert(p_txtProjectLinkTitle1);
				p_txtProjectRemark=$("textarea.ProjectRemark"+idCurent).val();
				p_txtProjectContact=$("textarea.ProjectContact"+idCurent).val();
//				alert(p_txtProjectRemark);
//$(this).attr("selectedIndex") //$("select[name='dllViewSelector'] option:selected")
				curSelector="dllViewSelector_"+idCurent;
  				p_viewSelector=$("select[name="+curSelector+"] option:selected").val();
				curSelector="dllProjectName_"+idCurent;
  				p_dllProjectNameVal=$("select[name="+curSelector+"] option:selected").val();
  				p_dllProjectNameText=$("select[name="+curSelector+"] option:selected").text();
//				p_dllProjectName=$("input.dllProjectName"+idCurent).val();
//				alert('p_dllProjectName:'+p_dllProjectName);//blank
				curSelector="selProjectPageLink1_"+idCurent;
//				p_selProjectPageLink1=$("input.selProjectPageLink1"+idCurent).val();
  				p_selProjectPageLink1=$("select[name="+curSelector+"] option:selected").val();
//				alert(p_selProjectPageLink1);//select //blank
				curSelector="txtProjectName_"+idCurent;
				p_txtProjectName=$("input[name="+curSelector+"]").val();
//				alert('p_txtProjectName: '+p_txtProjectName); 
//				p_viewSelector=$("select[name='dllViewSelector_Search_0'] option:selected").text(); //WORKS!!
//				p_txtProjectEmailAddress=$("input.ProjectEmailAddress"+idCurent).val();
				curSelector="txtProjectEmailAddress_"+idCurent;
				p_txtProjectEmailAddress=$("input[name="+curSelector+"]").val();
//				alert('p_txtProjectEmailAddress: '+p_txtProjectEmailAddress);
				curSelector="selProjectPageLink2_"+idCurent;
				p_selProjectPageLink2=$("select[name="+curSelector+"] option:selected").val();
//				alert('p_selProjectPageLink2: '+p_selProjectPageLink2);
//				curSelector="txtSaveSwitch_"+idCurent;
//				p_saveswitch=$("input[name="+curSelector+"]").val();
//				alert('p_saveswitch: '+p_saveswitch);
				curSelector="txtProjectPageLink2_"+idCurent;
				p_txtProjectPageLink2=$("input[name="+curSelector+"]").val();
//				alert('1: '+p_txtProjectPageLink2);
				p_txtProjectLinkTitle2=$("input.ProjectLinkTitle2"+idCurent).val();
//				alert('2: '+p_txtProjectLinkTitle2);//OK
				curSelector="txtProjectDescription2_"+idCurent;
				p_txtProjectDescription2=$("textarea[name="+curSelector+"]").val();
//				alert('3: '+p_txtProjectDescription2);
				curSelector="txtProjectPageLink3_"+idCurent;
				p_txtProjectPageLink3=$("input[name="+curSelector+"]").val();
//				alert('4: '+p_txtProjectPageLink3);
				curSelector="txtProjectHomeTitle2_"+idCurent;
				p_ProjectHomeTitle2=$("input[name="+curSelector+"]").val();
//				alert('6: '+p_ProjectHomeTitle2);
				curSelector="txtProjectHomeDescrip_"+idCurent;
				p_projecthomedescrip=$("textarea[name="+curSelector+"]").val();
//				alert('7: '+p_projecthomedescrip);//undefined
				curSelector="selProjectPageLink3_"+idCurent;
				p_selProjectPageLink3=$("select[name="+curSelector+"] option:selected").val();
//				alert('8: '+p_selProjectPageLink3);
				curSelector="txtb";
				p_b=$("input[name="+curSelector+"]").val();
				curSelector="dllnhits_Search_0";
				p_nhits=$("select[name="+curSelector+"] option:selected").val();
				$.getJSON('lib/addToProj.php',
				{txtProjectPageLink: p_txtProjectPageLink,
				txtProjectName: p_txtProjectName,
//				current: p_current,
				dllProjectNameText: p_dllProjectNameText,
				dllProjectNameVal: p_dllProjectNameVal
				}, function(data) 
				{
				   $.each(data, function(i,item)
				   {
           			    if ( i == "message" )message=item;
           			    if ( i == "status" )status=item;
           			    if ( i == "idProject" )idProject=item;
           			    if ( i == "insertid" )insertid=item;
           			    if ( i == "oldprojectname" )oldprojectname=item;
           			    if ( i == "newprojectname" )newprojectname=item;
           			    if ( i == "project" )project=item;
				   });
				   $.getJSON('lib/addToLinks.php',
				   {txtStatus: status,
				    viewSelector: p_viewSelector,
				    pr: p_pr,
				    prhome: p_prhome,
				    txtmessage: message,
				    txtoldprojectname: oldprojectname,
				    txtnewprojectname: newprojectname,
				    txtproject: project,
				    txtidProject: idProject,
				    txtinsertid: insertid,
				    txtProjectRemark: p_txtProjectRemark,
				    txtProjectContact: p_txtProjectContact,
				    txtProjectHomeLink: p_txtProjectHomeLink,
				    txtProjectPageLink: p_txtProjectPageLink,
				    selProjectPageLink1: p_selProjectPageLink1,
				    txtProjectLinkTitle1: p_txtProjectLinkTitle1,
				    txtProjectDescription1: p_txtProjectDescription1,
				    txtProjectEmailAddress: p_txtProjectEmailAddress,
				    selProjectPageLink2: p_selProjectPageLink2,
				    txtProjectPageLink2: p_txtProjectPageLink2,
				    txtProjectLinkTitle2: p_txtProjectLinkTitle2,
				    txtProjectDescription2: p_txtProjectDescription2,
				    txtProjectPageLink3: p_txtProjectPageLink3,
				    selProjectPageLink3: p_selProjectPageLink3,
				    ProjectHomeTitle2: p_ProjectHomeTitle2,
				    projecthomedescrip: p_projecthomedescrip,
				    b: p_b
//				nhits: p_nhits
					}, function(data) 
					{
					   var project;
					   var oldprojectname;
					   var date;
					   var memberid;
					   var insertid;
//					   var nhitsval;
					   var message;
//					   var current;
					   $.each(data, function(i,item)
					   {
//					    console.log(data);
	           			    if ( i == "project" )project=item;
//   	        			    if ( i == "current" )current=item;
        	   			    if ( i == "message" )message=item;
           				    if ( i == "oldprojectname" )oldprojectname=item;
           				    if ( i == "newprojectname" )newprojectname=item;
 	          			    if ( i == "date" )date=item;
//        	   			    if ( i == "memberid" )memberid=item;
//           				    if ( i == "nhitsval" )nhitsval=item;
        	   			    if ( i == "insertid" )insertid=item;
					   });
				   
//					   var drps = new Array();
					   var drp;
//					   var intnhits = parseInt(nhits);				   
					   for (i=0;i<=p_nhits;i++)
				   	{
					   // PENDING a) What to do if project is blank b) Only write message for current pane c) Put more detail in message d) Disable stuff when LITE e) Test for when link already added to project etc. etc.
				   		   if (project!="")
				   	   	{
//						   $('#philtest_Search_'+i).val("It got successfully added");
							   drp = $('#dllProjectName_Search_'+i);
						  	 drp.children().each(function() 
							   { $(this).removeAttr("selected"); 
							   }).end().append("<option value='"+insertid+"' selected='selected'>"+project+"</option>"); 
//							   $('#Add_'+current).children().html("<br/>"+status+"The link was successfully added to "+newprojectname);
							   $('#Add_'+p_current).children('span').html("<br />"+message);
						   }
						   else if (oldprojectname!="")
						   {
							   drp = $('#dllProjectName_Search_'+i);
							   drp.children().each(function() 
							   { $(this).removeAttr("selected"); 
							   }).end().append("<option value='"+insertid+"' selected='selected'>"+oldprojectname+"</option>"); 
//						   	$('#Add_'+current).children().html("<br/>"+message+"The link was successfully added to "+oldprojectname);
						   	$('#Add_'+p_current).children('span').html("<br />"+message);
						   }
					   }

					});
				});

			}
		);		
		$(".actionOptRefresh").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Refresh","Search");
//				linkRank = $("input.ProjectLinkTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				foundPage = $("input.ProjectPageLink1"+idCurent).val();
				homeRank = $("input.ProjectHomeLink"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				linkRank = $("input.ProjectPageLink1"+idCurent).val();
//				curSelector="txtProjectPageLink1_"+idCurent;
//				linkRank=$("input[name="+curSelector+"]").val();
				$.post('lib/calculateRankPR.php',{txtLink: foundPage}, function(data) 
//				$.post('/lib/calculateRankPR.php',{txtLink: linkRank}, function(data) 
				{
					$('#rank_GooglePR_'+idCurent).html(data);
					$('#txtProjectPR_'+idCurent).val(data.replace("/10","")); //write to hidden field
				});
//PMM see above			$.post('/lib/calculateRankPR.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateRankPR.php',{txtLink: foundPage,flag: 1}, function(data) 
				{
					$('#rank_GooglePR_Home_'+idCurent).html(data);
					$('#txtProjectPRHome_'+idCurent).val(data.replace("/10","")); //write to hidden field
				});
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
				   $.each(data, function(i,item)
				   {
//				    if ( i == "link" )$("a.actionOptNavigate").attr("href",item);
				    if ( i == "link" )$('#link1_'+idCurent).attr("href",item);
            			    if ( i == "descr" )$('#txtProjectDescription1_'+idCurent).val(item);
//           			    if ( i == "descr" )$('#txtProjectDescription2_'+idCurent).val(item);
           			    if ( i == "title" )$('#homedata_title_'+idCurent).val(item);
//           			    if ( i == "title" )$('#homedata_title2_'+idCurent).val(item);
           			    if ( i == "title" )$('#txtProjectLinkTitle1_'+idCurent).val(item);
//           			    if ( i == "title" )$('#txtProjectLinkTitle2_'+idCurent).val(item);
//           			    if ( i == "link" )$('#txtProjectPageLink2_'+idCurent).val(item);
           			    if ( i == "home" )$('#homelink_'+idCurent).attr("href",item);
           			    if ( i == "short" )$('#homelink_'+idCurent).html(item);
//				    if ( i == "link" )$("a.actionOptNavigate").attr("href",item);
//            			    if ( i == "descr" )$('#txtProjectDescription1_'+idCurent).val(item);
//          			    if ( i == "title" )$('#txtProjectLinkTitle1_'+idCurent).val(item);
//				    if ( i == "link" )$("a.actionOptNavigate").attr("href",item);
//				    curSelector="txtProjectDescription1_"+idCurent;
//            			    if ( i == "descr" )$("textarea[name="+curSelector+"]").val(item);
//				    curSelector="txtProjectLinkTitle1_"+idCurent;
//				    if ( i == "title" )$("input[name="+curSelector+"]").val(item);
          			   });
				});
				$.post('lib/calculateRankAlexa.php',{txtLink: linkRank}, function(data) 
				{
					  $('#rank_Alexa_'+idCurent).html(data);
					  //alert(data+'#GooglePR'+idCurent);
				});
				
				//calculate number of links to domain, comming from dmoz
//PMM see above			$.post('/lib/calculateDMOZLinks.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateDMOZLinks.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_DMOZ_'+idCurent).html(data);
				});
				
				//calculate number of links to domain, comming from Wikipedia
//PMM see above			$.post('/lib/calculateWikipediaLinks.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateWikipediaLinks.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_Wikipedia_'+idCurent).html(data);
				});
				
				//calculate number of links to the current page
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: linkRank}, function(data) 
				$.post('lib/calculateLinksNumber.php',{txtLink: linkRank}, function(data) 
				{
					  $('#rank_pageLinks_'+idCurent).html(data);
				});
				//calculate number of links to the current page
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: linkRank}, function(data) 
				$.post('lib/calculateLinksNumber.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_siteLinks_'+idCurent).html(data);
				});
				//calculate number of links to homepage
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateLinksDomain.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_domainLinks_'+idCurent).html(data);
				});
			}

		);	
		$(".actionOptRefresh2").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Refresh","Search");
//				linkRank = $("input.ProjectLinkTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				foundPage = $("input.ProjectPageLink2"+idCurent).val();
//				homeRank = $("input.ProjectHomeLink"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				linkRank = $("input.ProjectPageLink2"+idCurent).val();
//				curSelector="txtProjectPageLink1_"+idCurent;
//				linkRank=$("input[name="+curSelector+"]").val();
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
				   $.each(data, function(i,item)
				   {
				    if ( i == "link" )$('#link2_'+idCurent).attr("href",item);
            			    if ( i == "descr" )$('#txtProjectDescription2_'+idCurent).val(item);
           			    if ( i == "title" )$('#txtProjectLinkTitle2_'+idCurent).val(item);
          			   });
				});
			}
		);	
		$(".actionOptRefresh3").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Refresh","Search");
//				linkRank = $("input.ProjectLinkTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				foundPage = $("input.ProjectPageLink3"+idCurent).val();
//				homeRank = $("input.ProjectHomeLink"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				linkRank = $("input.ProjectPageLink3"+idCurent).val();
//				curSelector="txtProjectPageLink1_"+idCurent;
//				linkRank=$("input[name="+curSelector+"]").val();
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
				   $.each(data, function(i,item)
				   {
				    if ( i == "link" )$('#link3_'+idCurent).attr("href",item);
            			    if ( i == "descr" )$('#txtProjectHomeDescrip_'+idCurent).val(item);
           			    if ( i == "title" )$('#txtProjectHomeTitle2_'+idCurent).val(item);
          			   });
				});
			}
		);	
		$(".actionOptExplore1").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Explore","Search");
				curSelector="txtProjectPageLink1_"+idCurent;
				foundPage=$("input[name="+curSelector+"]").val();
				if (foundPage.substring(7,0) != "http://")
				{
					foundPage = "http://"+foundPage;
				}
				window.open(foundPage);
			}
		);	
		$(".actionOptExplore2").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Explore","Search");
				curSelector="txtProjectPageLink2_"+idCurent;
				foundPage=$("input[name="+curSelector+"]").val();
				if (foundPage.substring(7,0) != "http://")
				{
					foundPage = "http://"+foundPage;
				}
				window.open(foundPage);
			}
		);	
		$(".actionOptExplore3").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Explore","Search");
				curSelector="txtProjectPageLink3_"+idCurent;
				foundPage=$("input[name="+curSelector+"]").val();
				if (foundPage.substring(7,0) != "http://")
				{
					foundPage = "http://"+foundPage;
				}
				window.open(foundPage);
			}
		);	
		$(".actionOptExplorep").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Explore","Search");
				curSelector="txtProjectPageLinkp_"+idCurent;
				foundPage=$("input[name="+curSelector+"]").val();
				if (foundPage.substring(7,0) != "http://")
				{
					foundPage = "http://"+foundPage;
				}
				window.open(foundPage);
			}
		);	
		$(".actionOptRefreshp").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Refresh","Search");
				curSelector="txtProjectPageLinkp_"+idCurent;
				foundPage=$("input[name="+curSelector+"]").val();
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
				   desc_selector="txtProjectLinkDescription_"+idCurent;
//				   link_selector="linkp_"+idCurent;
				   title_selector="txtProjectLinkTitle_"+idCurent;
				   $.each(data, function(i,item)
				   {
				    if ( i == "link" )$('#txtProjectPageLinkp_'+idCurent).attr("href",item);
            			    if ( i == "descr" )$("textarea[name="+desc_selector+"]").val(item);
           			    if ( i == "title" )$("input[name="+title_selector+"]").val(item);
          			   });
				});
			}
		);	
		$(".actionOptClear").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Clear","Search");
				$("input.ProjectPageLink1"+idCurent).val("");
				$('#txtProjectDescription1_'+idCurent).val("");
				$('#txtProjectLinkTitle1_'+idCurent).val("");
			}
		);	
		$(".actionOptClear2").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Clear","Search");
				$("input.ProjectPageLink2"+idCurent).val("");
				$('#txtProjectDescription2_'+idCurent).val("");
				$('#txtProjectLinkTitle2_'+idCurent).val("");
			}
		);	
		$(".actionOptClear3").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Clear","Search");
				$("input.ProjectPageLink3"+idCurent).val("");
				$('#txtProjectHomeDescrip_'+idCurent).val("");
				$('#txtProjectHomeTitle2_'+idCurent).val("");
			}
		);	
		$(".actionOptClearp").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Clear","Search");
				$("input.ProjectPageLinkp"+idCurent).val("");
//				$('#txtProjectLinkDescription_'+idCurent).val("");
//				$('#txtProjectLinkTitle_'+idCurent).val("");
//				$('#txtProjectPageLinkp_'+idCurent).val("");
            			$("textarea[name="+desc_selector+"]").val("");
           			$("input[name="+title_selector+"]").val("");
			}
		);	
		$(".actionOptPrefill").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Prefill","Search");
				idCurent=idCurent.replace("Search_","");
				foundPage = $("input.ProjectPageLink1"+idCurent).val();
				homeRank = $("input.ProjectHomeLink"+idCurent).val();
				linkRank = $("input.ProjectPageLink1"+idCurent).val();
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
	  				$.each(data, function(i,item)
				   	{
					   curSelector="txtProjectRadio_"+idCurent;
//					   alert("curSelector: "+curSelector);
					   selector=$("input[name="+curSelector+"]:checked").val();
				    	   if ( i == "descr" )
				    	   {
	 				      curSelector="txtProjectDescription2_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectDescription1_"+idCurent;
		 				  newVal=$("textarea[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("textarea[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("textarea[name="+curSelector+"]").val(item);
    				              }  
    				           }   
				    	   if ( i == "title" )
				    	   {
		 			      curSelector="txtProjectLinkTitle2_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectLinkTitle1_"+idCurent;
		 				  newVal=$("input[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("input[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }
    				           }   
				    	   if ( i == "link" )
				    	   {
		 			      curSelector="txtProjectPageLink2_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectPageLink1_"+idCurent;
		 				  newVal=$("input[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("input[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }  
          			           }
 				    	   if ( i == "home" )
				    	   {
		 			      curSelector="txtProjectPageLink2_"+idCurent;
				    	      if (selector=="b")
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }  
          			           }
   				        });
			});

		});	
		$(".actionOptPrefill2").bind("click",
			function() 
			{ 
				idCurent=$(this).attr("id");
				idCurent=idCurent.replace("Prefill","Search");
				idCurent=idCurent.replace("Search_","");
				foundPage = $("input.ProjectPageLink1"+idCurent).val();
				homeRank = $("input.ProjectHomeLink"+idCurent).val();
				linkRank = $("input.ProjectPageLink1"+idCurent).val();
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
	  				$.each(data, function(i,item)
				   	{
					   curSelector="txtProjectRadio2_"+idCurent;
//					   alert("curSelector: "+curSelector);
					   selector=$("input[name="+curSelector+"]:checked").val();
				    	   if ( i == "descr" )
				    	   {
	 				      curSelector="txtProjectHomeDescrip_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectDescription1_"+idCurent;
		 				  newVal=$("textarea[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("textarea[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("textarea[name="+curSelector+"]").val(item);
    				              }  
    				           }   
				    	   if ( i == "title" )
				    	   {
		 			      curSelector="txtProjectHomeTitle2_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectLinkTitle1_"+idCurent;
		 				  newVal=$("input[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("input[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }
    				           }   
				    	   if ( i == "link" )
				    	   {
		 			      curSelector="txtProjectPageLink3_"+idCurent;
				    	      if (selector=="a")
				    	      {
		 				  curSelector2="txtProjectPageLink1_"+idCurent;
		 				  newVal=$("input[name="+curSelector2+"]").val();
//		 				  alert("newVal: "+newVal);
					          $("input[name="+curSelector+"]").val(newVal);
				    	      }
				    	      else
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }  
          			           }
 				    	   if ( i == "home" )
				    	   {
		 			      curSelector="txtProjectPageLink3_"+idCurent;
				    	      if (selector=="b")
				    	      {
    				                $("input[name="+curSelector+"]").val(item);
    				              }  
          			           }
   				        });
			});

		});	
		$(".expanderOptSearch").toggle( 
			function() 
			{ 
				idCurent=$(this).attr("id");
//				alert('idCurent: '+idCurent);
				$("#opt"+idCurent).show("slow");
				$(this).children("img").attr("src","images/bullet_minus.gif");
				$(this).children("span").html("Click here to close");
				foundPage = $("input.ProjectPageLink1"+idCurent).val();
//				alert('foundPage: '+foundPage);
//				foundPage = $("input.ProjectPageLink1"+idCurent).text();
//				alert('foundPage: '+foundPage);
//				foundPage = $("input.Abc"+idCurent).val();
//				alert('foundPage: '+foundPage);
//				foundPage = $("input.Abc"+idCurent).text();
//				alert('foundPage: '+foundPage);
				homeRank = $("input.ProjectHomeLink"+idCurent).val();
//				homeRank = $("input.ProjectHomeTitle"+idCurent).val();
				linkRank = $("input.ProjectPageLink1"+idCurent).val();
//				linkRank = $("input.ProjectLinkTitle"+idCurent).val();
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
				$.post('lib/calculateRankPR.php',{txtLink: foundPage}, function(data) 
//				$.post('/lib/calculateRankPR.php',{txtLink: linkRank}, function(data) 
				{
					$('#rank_GooglePR_'+idCurent).html(data);
					$('#txtProjectPR_'+idCurent).val(data.replace("/10","")); //write to hidden field
//					newVal=$('#txtProjectPR_'+idCurent).val();
//					alert(data);
					  //alert(data+'#GooglePR'+idCurent);
				});
//PMM see above			$.post('/lib/calculateRankPR.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateRankPR.php',{txtLink: homeRank}, function(data) 
				{
					$('#rank_GooglePR_Home_'+idCurent).html(data);
					$('#txtProjectPRHome_'+idCurent).val(data.replace("/10","")); //write to hidden field
//					newVal=$('#txtProjectPRHome_'+idCurent).val();
//					alert(data);
				});
//				$.post('lib/getHomepageData.php',{txtLink: homeRank}, function(data) 
//				{
//					  $('#rank_pmm_'+idCurent).html(data);
//				});
//				$.post('lib/getHomepageData.php',{txtLink: homeRank}, function(data) 
//				{
//					  $('#homedata_descrip_'+idCurent).html(data);
//				});
//				$.post('lib/getHomepageData.php',{txtLink: homeRank}, function(data) 
//				{
//					  $('#homedata_title'+idCurent).html(data);
//				});
				$.getJSON('lib/getHomepageData.php',{txtLink: foundPage}, function(data) 
				{
				   $.each(data, function(i,item)
				   {
				    if ( i == "link" )$('#link1_'+idCurent).attr("href",item);
				    //link2 is blank by default.
           			    if ( i == "home" )$('#link3_'+idCurent).attr("href",item);
//				    if ( i == "link" )$("a.actionOptNavigate").attr("href",item);
// temporarily remove next 2 lines -----------------
//            			    if ( i == "descr" )$('#homedata_descrip_'+idCurent).val(item);
//            			    if ( i == "descr" )$('#txtProjectDescription1_'+idCurent).val(item);
//---------------------------
           			    if ( i == "title" )$('#homedata_title_'+idCurent).val(item);
//           			    if ( i == "title" )$('#homedata_title2_'+idCurent).val(item);
           			    if ( i == "title" )$('#txtProjectLinkTitle1_'+idCurent).val(item);
				    // Also fill in reciprocal link details by default
				    curSelector="txtProjectHomeTitle2_"+idCurent;
//    				    alert('curSelector: '+curSelector);
				    if ( i == "title" )$("input[name="+curSelector+"]").val(item);
				    curSelector="txtProjectDescription1_"+idCurent;
//    				    alert('curSelector: '+curSelector);
    				    desc1 = $("textarea[name="+curSelector+"]").val();
//    				    alert('desc1: '+desc1);
				    curSelector="txtProjectHomeDescrip_"+idCurent;
				    if ( i == "descr" )$("textarea[name="+curSelector+"]").val(desc1);
//            			    if ( i == "descr" )$('#homedata_descrip_'+idCurent).html(item);
//            			    if ( i == "title" )$('#homedata_title_'+idCurent).html(item);
//            			    if ( i == "descr" )$('textarea#homedata_descrip_'+idCurent).text(item);
//            			    if ( i == "title" )$('textarea#homedata_title_'+idCurent).text(item);
//            			    if ( i == "descr" )$('#homedata_descrip_'+idCurent).append(item);
//            			    if ( i == "title" )$('#homedata_title_'+idCurent).append(item);
//            			    if ( i == "descr" )$("textarea[name='homedata_descrip_'+idCurent]").val(item);
//            			    if ( i == "title" )$("textarea[name='homedata_title_'+idCurent]").val(item);
          			   });
				});
//PMM see above			$.post('/lib/calculateRankAlexa.php',{txtLink: linkRank}, function(data) 
				$.post('lib/calculateRankAlexa.php',{txtLink: linkRank}, function(data) 
				{
					  $('#rank_Alexa_'+idCurent).html(data);
					  //alert(data+'#GooglePR'+idCurent);
				});
				
				//calculate number of links to domain, comming from dmoz
//PMM see above			$.post('/lib/calculateDMOZLinks.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateDMOZLinks.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_DMOZ_'+idCurent).html(data);
				});
				
				//calculate number of links to domain, comming from Wikipedia
//PMM see above			$.post('/lib/calculateWikipediaLinks.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateWikipediaLinks.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_Wikipedia_'+idCurent).html(data);
				});
				
				//calculate number of links to the current page
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: linkRank}, function(data) 
				$.post('lib/calculateLinksNumber.php',{txtLink: linkRank}, function(data) 
				{
					  $('#rank_pageLinks_'+idCurent).html(data);
				});
				//calculate number of links to homepage
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateLinksNumber.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_siteLinks_'+idCurent).html(data);
				});
				//calculate number of links to homepage
//PMM see above			$.post('/lib/calculateLinksNumber.php',{txtLink: homeRank}, function(data) 
				$.post('lib/calculateLinksDomain.php',{txtLink: homeRank}, function(data) 
				{
					  $('#rank_domainLinks_'+idCurent).html(data);
				});
			},
			function() 
			{ 
//				alert('Hide Search');
//				alert('close_Search');
				id2=$(this).attr("id");
//				alert(id2);
				id2a=id2.replace("Inner2","Inner2a");
				id2b=id2.replace("Inner2","Inner2b");
				id4=id2.replace("Inner2","Inner4");
//				id2c=id2.replace("Inner2","Inner2c");
				$("#opt"+id2).hide("slow");
				$("#opt"+id2a).hide("fast");
				$("#opt"+id2b).hide("fast");
				$("#opt"+id4).hide("fast");
//				$("#opt"+id2c).hide("fast");
				$(this).children("img").attr("src","images/bullet_plus.gif");
				$(this).children("span").html("Open pane to view link details + save this link prospect");
			}
		);

		$(".expanderOptInner").toggle( 
			function() 
			{ 
// if id is 2, just show 2; if id is 3 show 2 and 3
//				alert('open_Inner');
				id2=$(this).attr("id");
//				alert(id2);
				id2a=id2.replace("Inner2","Inner2a");
				id2b=id2.replace("Inner2","Inner2b");
				id3=id2.replace("Inner2","Inner3Div");//new
				id4=id2.replace("Inner2","Inner4");
//				idCurent=id2.replace("Inner2","");
//				curSelector="dllViewSelector"+idCurent;
//  				if ($("select[name="+curSelector+"] option:selected").val() == 'two')
//  				{
					$("#"+id3).show("fast");
//  				}
//				id2c=id2.replace("Inner2","Inner2c");
				$("#opt"+id2).show("fast");
				$("#opt"+id2a).show("fast");
				$("#opt"+id2b).show("fast");
				$("#opt"+id4).show("fast");
//				$("#opt"+id2c).hide("fast");
				$(this).children("img").attr("src","images/bullet_minus.gif");
//				$(this).children("span").html("<tr><td>Less</td></tr>");
//				saveswitch="txtSaveSwitch_Search"+id2.substr(id2.lastIndexOf('_'));
//				alert(saveswitch);
//				$(this).children("span").html("Close extended pane<input type=\"hidden\" name=\""+saveswitch+"\" value=\"on\">");
				$(this).children("span").html("Close extended pane");
			},
			function() 
			{ 
//				alert('Inner hide');
				id2=$(this).attr("id");
//				alert('close_Inner');
//				alert(id2);
				id2a=id2.replace("Inner2","Inner2a");
				id2b=id2.replace("Inner2","Inner2b");
				id3=id2.replace("Inner2","Inner3Div");//new
				id4=id2.replace("Inner2","Inner4");
//				id2c=id2.replace("Inner2","Inner2c");
				$("#opt"+id2).hide("fast");
				$("#opt"+id2a).hide("fast");
				$("#opt"+id2b).hide("fast");
				$("#opt"+id4).hide("fast");
				$("#"+id3).hide("fast");
//				$("#opt"+id2c).hide("fast");
//				$(this).children("img").attr("src","images/bullet_plus.gif");
//				$(this).children("span").html("<tr><td>More</td><td>&nbsp;</td></tr>");
//				saveswitch="txtSaveSwitch_Search"+id2.substr(id2.lastIndexOf('_'));
//				alert(saveswitch);
//				$(this).children("span").html("Click to extend pane<input type=\"hidden\" name=\""+saveswitch+"\" value=\"off\">");
				$(this).children("span").html("Click to extend pane");
			}
		);
		
		$("input.fillProjectName").keypress( 
			function()
			{
				idCurent=$(this).attr("name");
				if (!window.event) 
				{
					valueCurent = $(this).val();
					var noCharInsert = valueCurent.length;
					if (noCharInsert > 1)
					{
						$.post('lib/autofillProject.php', { Keyword: valueCurent , Field: idCurent }, 
							function(data) 
							{
								$("#display_"+idCurent).show("fast").html(data);
							}
						);
					} else {
						$("#display_"+idCurent).hide("fast");
					}
					
				} else {
					
					var newKeyPress;
					newKeyPress = window.event.keyCode;
					if (newKeyPress == 27)
					{
						$("#display_"+idCurent).hide("fast");
					} else {
						valueCurent = $(this).val() + String.fromCharCode(newKeyPress);
						var noCharInsert = valueCurent.length;
						if (noCharInsert > 1)
						{
							$.post('lib/autofillProject.php', { Keyword: valueCurent , Field: idCurent }, 
								function(data) 
								{
									$("#display_"+idCurent).show("fast").html(data);
								}
							);
						} else {
							$("#display_"+idCurent).hide("fast");
						}
					}
					
				}
			}
		);
		
		$("input.fillMyProjectName").keypress( 
			function()
			{
				if (!window.event) 
				{
					//on mozilla isn't work the function event.keyCode
					valueCurent = $(this).val();
					var noCharInsert = valueCurent.length;
					if (noCharInsert > 1)
					{
						$.post('lib/autofillProject.php', { Keyword: valueCurent }, 
							function(data) 
							{
								$("#display_txtSearchProject").show("fast").html(data);
							}
						);
					} else {
							$("#display_txtSearchProject").hide("fast");
					}
					
				} else {
					
					var newKeyPress;
					newKeyPress = event.keyCode;
					if (newKeyPress == 27)
					{
						$("#display_txtSearchProject").hide("fast");
					} else {
						valueCurent = $(this).val() + String.fromCharCode(newKeyPress);
						var noCharInsert = valueCurent.length;
						if (noCharInsert > 1)
						{
							$.post('lib/autofillProject.php', { Keyword: valueCurent }, 
								function(data) 
								{
									$("#display_txtSearchProject").show("fast").html(data);
								}
							);
						} else {
							$("#display_txtSearchProject").hide("fast");
						}
					}
					
				}
				
			}
		);
		
		$(".expanderWebsite").toggle( 
			function() 
			{ 
				idCurent=$(this).attr("id");
				//alert(idCurent);
				$("#opt"+idCurent).show("slow");
				$(this).children("img").attr("src","images/bullet_minus.gif");
			},
			function() 
			{ 
				idCurent=$(this).attr("id");
				//alert(idCurent);
				$("#opt"+idCurent).hide("slow");
				$(this).children("img").attr("src","images/bullet_plus.gif");
			}
		);
		
		$("input.expanderWebsiteTick").click( 
			function() 
			{ 
				idCurent=$(this).attr("name");
				idCurent = idCurent.replace("chk", "opt");
				idCurent = idCurent.replace("Type", "Parent");
				//alert(idCurent);
				$("#"+idCurent).show("slow");
				$(this).children("img").attr("src","images/bullet_minus.gif");
			}
		);
		
		$(".expanderWebsiteRoot").toggle( 
			function() 
			{ 
				idCurent=$(this).attr("id");
				//alert(idCurent);
				$("#opt"+idCurent).show("slow");
				$(this).children("img").attr("src","images/bullet_minus.gif");
				$(this).children("span").html("Click here to close");
			},
			function() 
			{ 
				idCurent=$(this).attr("id");
				//alert(idCurent);
				$("#opt"+idCurent).hide("slow");
				$(this).children("img").attr("src","images/bullet_plus.gif");
				$(this).children("span").html("Click here to view website types");
			}
		);

}
);

// help system for search module


//PMM: Used in help system to set a cookie value
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

//PMM: Used in help system to read a cookie value
function get_cookie (cookie_name)
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
  {
    set_cookie(cookie_name,'');
    return null;
  }  
}

//PMM: Used in help system to 'pop' a value from a cookie which is acting as a stack of values
// (the implementation is that the stack stores indexes into the help system, so the user can
// go back through his/her help history
function pop_cookie (name)
{
  var the_string = get_cookie (name);
//        alert ('popa:'+the_string);
//        alert ('popb:'+the_string.substring(0,(the_string.lastIndexOf("|"))));
  the_string = the_string.substring(0,(the_string.lastIndexOf("|")));
//        alert ('popc:'+the_string);
  set_cookie (name,the_string);
//        alert ('popc:'+the_string);
  return (the_string.substring(the_string.lastIndexOf("|") + 1));
}

//PMM: Used in help system to 'push' a value onto a cookie which is acting as a stack of values
// (the implementation is that the stack stores indexes into the help system, so the user can
// go back through his/her help history
function push_cookie (name,item)
{
  set_cookie (name,get_cookie (name) + '|' + item);
//  alert('push:'+get_cookie(name));
  return (get_cookie(name));
}

//PMM
function test_cookie (name)
{
  var the_string = get_cookie (name);
  return (the_string.indexOf("|"));
}

//PMM
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function loadHelp(tag, nopush) 
{		
	if(tag=='Index')
	{
//		set_cookie("help_stack",""); //PMM Clear the cookie
		set_cookie("help_stack","|Index"); //PMM Clear the cookie, apart from keeping |Index at the head of the stack.
		$('div#help').css('height','2000px');
	}	
	$('div#help').fadeIn("fast");
//	$.post('/lib/help.php', { txtTag: tag}, function(data) {
// PMM 22/1/09: Remove forward slash so this is a relative URL e.g. it did not work in my test
//      environment (www.alcander.com/app/)
	$.post('lib/help.php', { txtTag: tag}, function(data) {
	//PMM Replace window.location... with window.scroll to make sure help always goes at top, otherwise
	// it will be off the page when the link to the help is low down on the page
    //window.location.hash = '#top';
    window.scroll(0,0);
	 $('#helpContent').html(data);
	});
	if (!(nopush))
	{
		push_cookie("help_stack",tag);
	}	
}

function HelpBack(){
        var the_string = pop_cookie("help_stack");
        if (test_cookie("help_stack") != -1)
        {
		loadHelp (the_string,true);
	}
	else
	{
		set_cookie("help_stack","|Index");
		//PMM: Keep this at the top of the stack rather than let the stack go empty
	}
}

// help system for search module

function closeHelpSearch(){
	$('div#help').fadeOut("fast");
}


function loadHelpSearch(searchType,tag) 
{		
	$('div#help').fadeIn("fast");
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
//	$.post('/lib/helpSearch.php', { txtSearch: searchType}, function(data) {
	$.post('lib/helpSearch.php', { txtSearch: searchType}, function(data) {
	//PMM Replace window.location... with window.scroll to make sure help always goes at top, otherwise
	// it will be off the page when the link to the help is low down on the page
    //window.location.hash = '#top';
    window.scroll(0,0);
	  $('#helpContent').html(data);
	});
}

//help system

function closeHelp(){
	$('div#help').fadeOut("fast");
}


//categorize selected functions

function loadCategories(id)
{
	$('div#help').fadeIn("fast");
//PMM 22/01/09 Make the path relative so it works when root is e.g. www.whatever.co.uk/something/
//	$.post('/lib/categorizeSelected.php', { ProjectId: id}, function(data) {
	$.post('lib/categorizeSelected.php', { ProjectId: id}, function(data) {

	//PMM Replace window.location... with window.scroll to make sure help always goes at top, otherwise
	// it will be off the page when the link to the help is low down on the page
    //window.location.hash = '#top';
    window.scroll(0,0);
	  $('#helpContent').html(data);

	});
}

function noCategory()
{
	$('#ddlCategorizeCategories').val(0);
}

function submitSelection()
{
	if($('#txtNewCategory').val())
	{
		categ = $('#txtNewCategory').val();
	}
	else
	{
		categ = '';	
	}
	if(($('#ddlCategorizeCategories').val()==0  || !$('#ddlCategorizeCategories').val()) &&  categ.length == 0)
	{
		$('#errorSpan').show();
	}
	else
	{
		if($('#ddlCategorizeCategories').val()==0 || !$('#ddlCategorizeCategories').val()) 
		{
			raiseEvent('AddToNew',categ);
		}
		else
		{
			raiseEvent('AddToCurrent',$('#ddlCategorizeCategories').val());
		}
	}
}
// 
function addUrlCheck()
{
	if($('#dllSelectedProject').val()>0)
		raiseEvent('AddURLtoProject');
	else
		$('#errorMsg').show();
}
//header functions
function showChecker()
{
	if($('#checker').css("display")=='none')
		$('#checker').show(500);
}

function closeChecker()
{
	$('#checker').hide(500);
}
// Tell a friend functions
function reset() {
document.tellafriend.name.value="";
document.tellafriend.email.value="";
document.tellafriend.friendmail1.value="";
document.tellafriend.friendmail2.value="";
document.tellafriend.friendmail3.value="";
}

function validate() {


if (document.tellafriend.friendmail1.value.length==0) {
alert("please enter your friend's email address");
return false;
}

if (document.tellafriend.email.value.length==0) {
alert("please enter your email address");
return false;
}
if (document.tellafriend.name.value.length==0) {
alert("please enter your name");
return false;
}

document.tellafriend.submit();
return true;
}
//PMM - Function which I'll implement to refresh the div containing the online support javascript i.e.
// so that it will show when support comes on line and goes offline etc.
function writeDivContent () {
    var myDiv = document.getElementById("left-block-middle");
//    myDiv.innerHTML = "<div><script language=\"javascript\" src=\"http:\/\/www.alcander.co.uk\/support\/visitor\/index.php?_m=livesupport&_a=htmlcode&departmentid=0\"><\/script><\/div>";
}

function doit (fred) {
alert(fred);
return true;
}
