 $j = jQuery.noConflict();
 
function videoWin()
 {
 	  $j.ajax({ 
                url: '/hooeeyTutorials/hooeeyOverview',
                cache: false, 
                success: function(html){  
                $j('#hooeeyOverviewDiv') .html(html);
                $j.blockUI({ message: $j('#hooeeyOverviewDiv') ,
                  css: { 
                  padding:          '1px',
                  margin:              0,
                  width:               '445px', 
                  top:                    '20%', 
                  left:                   '35%', 
                  textAlign:          '', 
                  color:                '#000', 
                  border:             '2px solid #FF9933',
                  backgroundColor:  'white',
                  cursor:               'default'
              }
            
           });
    
    /*JQUERY HOVER EFFECT*/
          $j('#videoClose').click(function() { 
                  $j.unblockUI(); 
                  return false; 
          });
          
          $j('#videoClose').hover(function() {
          $j(this).attr("src","/images/icon_close0_o.gif");
        }, function() {
        $j(this).attr("src","/images/icon_close0.gif");
    });    
        }
        });
 }

/*downloads toolbar*/
function chkVersion(version)
{
	if(version==1)
  {
  	$j('#firefoxToolbar').attr("href","/downloads/firefox/hooeeybar.xpi");
  	$j('#firefoxButton').attr("href","/downloads/firefox/hooeeybutton.xpi");    
  }
  else if(version==3)
  {  	
    $j('#firefoxToolbar').attr("href","/downloads/firefox/hooeeybar_f3.xpi");
    $j('#firefoxButton').attr("href","/downloads/firefox/hooeeybutton_f3.xpi");    
  }	
   else if (version == 3.5) {
        $j('#firefoxToolbar').attr("href", "/downloads/firefox/hooeeybar_f3_6.xpi");
        $j('#firefoxButton').attr("href", "/downloads/firefox/hooeeybutton_f3_6.xpi");
    }    
}

function chkos(version)
{
	if($j('#browFf2').is(':checked')==true)
	  var brow=0;
	else if($j('#browFf3').is(':checked')==true) 
	  var brow=1;  
	else if($j('#browFf3_5').is(':checked') == true)
	  var brow = 2;
	  
  if (version == 1)
    {         
	 $j('#imgOs').css('display', 'block');      
        if (brow == 1) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_fe_f3.xpi");
        else  if(brow == 2) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_fe_f3_6.xpi");
        else $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_fe.xpi");
    }     

  if (version == 2) 
  {
      $j('#imgOs').css('display','block');           
      if(brow==1)
      $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_mn_f3.xpi");            
      else if(brow == 2) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_mn_f3_6.xpi");
      else $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_mn.xpi");   
    }       
  if (version == 3) 
  {
      $j('#imgOs').css('display','block');           
      if(brow==1)$j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_ub_f3.xpi");            
      else if(brow == 2) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_ub_f3_6.xpi");	
      else $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_ub.xpi");
    }
} 

function chkLinuxBrowserVersion(version)
{
  if($j('#osMandriva').is(':checked')==true) 
   var os=0;      
  else if($j('#osUbuntu').is(':checked')==true) 
      var os=1;
  else
      var os=2;
  if(version==2)
  {
    if(os==0)
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_mn.xpi");    
    else if(os==1)
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_ub.xpi");
    else
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_fe.xpi");     
  }
  else if(version==3)
  {
    if(os==0)
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_mn_f3.xpi");
    else if(os==1)
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_ub_f3.xpi");      
    else
    $j('#ahrefOs').attr("href","/downloads/firefox/hooeeybar_fe_f3.xpi");
  }     
  else if (version == 3.5)
  {
    if (os == 0) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_mn_f3_6.xpi");
    else if (os == 1) $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_ub_f3_6.xpi");
    else $j('#ahrefOs').attr("href", "/downloads/firefox/hooeeybar_fe_f3_6.xpi");
  }
}

function chkMacVersion(version)
{
   if (version == 2) {
        $j('#Mactoolbar').attr("href", "/downloads/firefox/hooeeybar_mac.xpi");
        $j('#textORDiv').css('display', 'none');
        $j('#Macbutton').css('display', 'none');
    }
    else if (version == 3) {
    	 $j('#Mactoolbar').attr("href", "/downloads/firefox/hooeeybar_mac_f3.xpi");
    	 $j('#Macbutton').attr("href", "/downloads/firefox/hooeeybutton_mac_f3.xpi");
        $j('#textORDiv').css('display', 'block');
        $j('#Macbutton').css('display', 'block');
    }
    else if (version == 3.5) {
    	 $j('#Mactoolbar').attr("href", "/downloads/firefox/hooeeybar_mac_f3_6.xpi");
       $j('#Macbutton').attr("href", "/downloads/firefox/hooeeybutton_mac_f3_6.xpi");
        $j('#textORDiv').css('display', 'block');
        $j('#Macbutton').css('display', 'block');
    }
}



function getBookmarkIndex(select)
{
  getBookmarksData(select.selectedIndex+1);  
}
function getBookmarksData(page)
{
 $j.ajax({ 
                url: '/settings/getBookmarksData?pagenum='+page, 
                cache: false,
                success: function(html){                
                   $j('#bookmarksData') .html(html);
                   $j('#submitUploadIndicator').css('display','none');        
                   $j('#submitUploadImage').css('display','block');           
                   checkSelected();                                                          
                }            
            });  	
  }
function checkSelected()
  {    
    for(var i=0; i<aChecked.length; i++)
    {
    	
    	if(aChecked[i] && aChecked[i] [0]==1)
    	  $j("#bms_"+i).attr('checked', true);
    	else
    	   $j("#bms_"+i).attr('checked', false);
    }
  }
function selectAllBookmarks()
    {	                    
      for(var i=0; i<aChecked.length; i++)
	    {
	    	if($j('#selectAllBookmarks').attr('checked')==true)
	    	{
	        aChecked[i][0] =1;
	        if($j("#bms_"+i))
	          $j("#bms_"+i).attr('checked', true);
	    	}						 
	     else
	     {
	        aChecked[i][0] =0;
	        if($j("#bms_"+i))
            $j("#bms_"+i).attr('checked', false);
	     }     
	    }
      }
function selectBookmark(id)
	{	             
      var checked_status = $j('#'+id).attr('checked');
      var index=id.split("_")[1];
        if(checked_status == true)
        aChecked[index][0]=1;
      else     
       aChecked[index][0]=0;      
	}
	
function saveBookmarks()
	{
		var sUrlStr = "";		
	  for(var i=0; i<aChecked.length; i++)
	  {
	      if(aChecked[i] && aChecked[i][0] == 1)
	      {
	      sUrlStr += aChecked[i][1]+",";
	      }
	  }
	  sUrlStr=sUrlStr.substring(0,(sUrlStr.length-1));  
	  var date = new Date();
	  var tsDate = (date.getTime())/1000;
	  
	  $j.ajax({ 
                url: '/settings/saveBookmarksData?bookmarkId='+sUrlStr+'&date='+tsDate, 
                cache: false,                             
                success: function(html){               
                	aChecked = new Array; 
                   $j('#bookmarksData') .html('');                                                 $j('#message_saved') .html(html);
				
                }
            
            });   	  		
	}



/*share RemoveLinks*/
/*function removeElement(id)   {
   var Node = document.getElementById(id);
   Node.parentNode.removeChild(Node);
}*/


/*Add imported contacts*/
function addImported()
{
	var sImportedContacts = $j("#custom").val();
	sImportedContacts = sImportedContacts.replace(/^\s+|\s+$/g, '');
	sImportedContacts = sImportedContacts.replace(/\"/g, "");
	if(sImportedContacts == "")
	{
		alert("No contacts to import!\nPlease click on the above button to import contacts.");
		return false;
	}
	var aContactsSplit = sImportedContacts.split(",");
	var sContacts = "";	
	var tempContact = '';

 	var emailRegEx1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/;
	var emailRegEx2 = /(([-\w \.]+)|(""[-\w \.]+"") )?<([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))>$/;
	for(var i=0; i<aContactsSplit.length; i++)
	{
		tempContact = aContactsSplit[i].replace(/^\s+|\s+$/g, '');		
		sContacts += tempContact+"\n";
		  if (tempContact.match(emailRegEx1)) {			
			continue;
		  } 
		  else if(tempContact.match(emailRegEx2)){			
		  	continue;
		  }
		  else{
			alert("Email address is not valid. Please retry.");
			return;
		  }
	}
	var sUrlString = "contacts="+encodeURIComponent(sImportedContacts);
	
	$j.ajax({					
	    		  type: "POST",   
			  url: '/settings/saveImportedContacts?'+sUrlString,
		    	  cache: false,	    	   
			  success: function(html){
			  $j("#contactsSavedMesssageDiv").html(html);		
			   getContacts(1);	  			  			   
			  }
	});		
			
}

/*
 * Retrieving the contacts details
 */
 
 function getContacts(page)
 {
 	 	
 	$j.ajax({					
			  url: '/settings/getContacts?pagenum='+page,
	    	  cache: false,	    	   
			  success: function(html){
			  $j("#dynamicContactsDataDiv").html(html);	
			  $j('#addButton').hover(function() {
		    	$j(this).attr("src","/images/bu_add_o.gif");
				}, function() {
				$j(this).attr("src","/images/bu_add.gif");
		});    
		
		$j('#deleteButton').hover(function() {
		    	$j(this).attr("src","/images/bu_delete_o.gif");
				}, function() {
				$j(this).attr("src","/images/bu_delete.gif");
		});    		  			   
			  }
	});		
	
 }
 
 function contactsList(select)
{
	getContacts((select.selectedIndex+1));
}

 
 /*
  * Select all contacts checkbox items
  * @param Integer id  checkbox id
  */
  
  function selectAllContacts(id)
			{			
				//Select all check boxes
				$j( "#checkboxContainer" + " :checkbox").attr('checked', $j('#' + id).is(':checked'));			
			}			
			
			
/*
 * checkbox unchecked
 * @param Integer obj  checkbox id
 */
	function contactOneSelect(obj) 
	{		
		var urlid=obj.id;
		var urlId=urlid.split("_");
		var urlid_id=urlId[1];			
		$j( "#mycontacts" + " :checkbox").attr('checked', $j('#' + obj).is(':checked'));
	}			
 
 /*
  * Edit contacts details and save it into the database
  */
  
 function addEditContact(id) {		
 	var sUrl='';
	sUrl = '/settings/addEditContactDetailsUI?id='+id;		
	
      $j.ajax({ 
                url: sUrl,
                cache: false, 
                success: function(html){  
                $j('#editContactDetailsDiv') .html(html);
              	$j.blockUI({ message: $j('#editContactDetailsDiv') ,
                	css: { 
					        padding:       		'1px',
					        margin:        			 0,
					        width:			         '250px', 
					        top:              			'20%', 
					        left:             			'35%', 
					        textAlign:      		'', 
					        color:           			'#000', 
					        border:         		'2px solid #FF9933',
					        backgroundColor:	'white',
					        cursor:         			'default'
    					}
    				
           });
    
    /*JQUERY HOVER EFFECT*/
	        $j('#closeContactsUI').click(function() { 
	                $j.unblockUI(); 
	                return false; 
	        }); 
	     
	         $j('#exitContatctsBlockUI').click(function() { 
	                $j.unblockUI(); 
	                return false; 
	        }); 
			     
		  $j('#saveContactUI').hover(function() {
	    	$j(this).attr("src","/images/bu_save_o.gif");
			}, function() {
			$j(this).attr("src","/images/bu_save.gif");
		});    

		$j('#exitContatctsBlockUI').hover(function() {
		    	$j(this).attr("src","/images/bu_cancel_o.gif");
				}, function() {
				$j(this).attr("src","/images/bu_cancel.gif");
		});    
		    
        }
        });
	}
	


/*Saving the edit contacts*/
function saveContactDetails(contactId)
{			
	var emailRegEx1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/;

	if($j('#e-mail').val() == "")
	{
		alert("Please enter email");
		$j("#e-mail").focus();
		return;
	}

	  if ($j('#e-mail').val().match(emailRegEx1)) {		
	  }else
	  {
		alert("Invalid email. Please correct.");
		return;
	  } 
	  
	  	$j.ajax({					
			  url: '/settings/saveContactDetails?contactId='+contactId,
	    	  cache: false,	    	   
	    	  data: "fname="+$j('#fName').val()+"&lname="+$j('#lName').val()+"&email="+$j('#e-mail').val(),       
			  success: function(html){
			  $j('#editandAddContactDetailsDiv') .html(html);
			  $j.unblockUI(); 
			  getContacts(1);			  			   
			  }
	});		
	
}

/*Delete selected contact details*/

function deleteContactsDetails()
{		
		var sContactId = "";
		var deleteCount = 0;
		for(var y=0;y<10;y++)
		{
			
			if ($j("#contactsCheckbox_"+y).attr("checked") == true) 
      		  {         
		          sContactId+=$j("#contactsCheckbox_"+y).val()+",";
		          deleteCount++;
		  }	
		}		 
		
		if(deleteCount==0)
		{
			alert("Please select the contact(s) to delete");
			return false;
		}
		else
		{
				if(confirm("Please confirm deletion of contact(s)?"))
				    {
		    		var sContactId=sContactId.substring(0,sContactId.length-1);		    	
		    		
    				  $j.ajax({	 
       				       url: '/settings/deleteContactDetails?contactId='+sContactId, 
         			       cache: false,          			    
           			       success: function(html){  
           			       getContacts(currentPage);
           			               			    
    				    }
     		   });
      	  }
 
     	   else
		{
		return;
		}
		
     }  
	
}



/*Settings page validations: save Remainder*/
function saveRemPref()
{
	var sRemAfter = 0;
	var sRemRecur = 0;
	
	if(document.getElementById("reminder").checked)
	{
		sRemAfter = $j("#remAfter").val().replace(/^\s+|\s+$/g, '');
		sRemRecur = $j("#remRecur").val().replace(/^\s+|\s+$/g, '');

		if(!(/^\d+$/.test(sRemAfter)))
		{
			alert("Invalid number of days! Please correct.");
			$j("#remAfter").focus();
			return;
		}	
		
		if(!(/^\d+$/.test(sRemRecur)))
		{
			alert("Invalid number of days! Please correct.");
			$j("#remRecur").focus();
			return;
		}
	}	
	
	if(!(document.getElementById("reminder").checked))
		var sUrl = "rem=0&remAfter=0&remRecur=0";
	else
		var sUrl = "rem=1&remAfter="+sRemAfter+"&remRecur="+sRemRecur;	
		
	$j.ajax({					
			  url: '/settings/saveReminderPref?'+sUrl,
	    	  cache: false,	    	   
			  success: function(html){
			  $j("#prefSaved").html(html);			  			   
			  }
	});		
		
}


/*Save Stored Preferences*/

function saveStorePref()
{
	if(document.getElementById("hooeey").checked)
		sUrl = "hooeey=1";	
	else
		sUrl = "hooeey=0";	
		
	if(document.getElementById("https").checked)
		sUrl += "&https=1";	
	else
		sUrl += "&https=0";	

	if(document.getElementById("ftp").checked)
		sUrl += "&ftp=1";	
	else
		sUrl += "&ftp=0";	

	if(document.getElementById("email").checked)
		sUrl += "&email=1";	
	else
		sUrl += "&email=0";	

	if(document.getElementById("errorpage").checked)
		sUrl += "&errorpage=1";	
	else
		sUrl += "&errorpage=0";	

		
		/*Email validation*/
		
	/*	if($j("#custom").val()=="")
		{
			alert('Please fill in the email address');
			return false;
		}
		if(checkEmail($j("#custom").val())==false)
		{
			alert('Invalid email. Please correct');
			return false;
		}	*/
		
		var	sCustom = $j("#custom").val().replace(/^\s+|\s+$/g, '');
		sUrl += "&custom="+encodeURIComponent(sCustom);
		
		$j.ajax({					
			  url: '/settings/saveStorePref?'+sUrl,
	    	  cache: false,	    	   
			  success: function(html){
			 $j("#typeOfWebsitesDiv").html(html);		
			  //Retrieving the contacts details
			 	   
			  }
	});		
}


/*Forgot password	*/

function getForgotPwd()
{
	var sForgot = $j('#forgotpass').val();
	sForgot = sForgot.replace(/^\s+|\s+$/g, '');

	if(sForgot == "")
	{
		document.getElementById("errmsgTd").innerHTML = "Please enter your user name or email address";
		$j('#forgotpass').focus();
		return;
	}	
	
	 $j('#forgotSubmit').click(function () {	       
				$j.ajax({ 
                url: '/loginPage/getForgotPassword?forgot='+sForgot, 
                cache: false,                                              
                success: function(html){                
                 	$j('#errmsgTd') .html(html);      	
                }
           });
	});	  
}


/*Delete user account*/

function deleteAccount()
{	
	if(!confirm("Deleting account will delete all your links,tags,folders and webtours completely.\n\n"+
			"Do you still wish to continue?"))
			return false;
		else
		{
	    $j.ajax({ 
	                url: '/settings/deleteAccount',
	                cache: false, 
	                success: function(html){  
	                $j('#deleteAccountDiv') .html(html);         
	               	
	             	$j.blockUI({ message: $j('#deleteAccountDiv') ,
	             	css: { 
						        padding:       		'1px',
						        margin:        			 0,
						        width:			         '250px', 
						        top:              			'20%', 
						        left:             			'35%', 
						        textAlign:      		'', 
						        color:           			'#000', 
						        border:         		'2px solid #FF9933',
						        backgroundColor:	'white',
						        cursor:         			'default'
	    					}
	    				
	    });
			    /*JQUERY HOVER EFFECT*/
			             	 
			        $j('#closeDeleteUI').click(function() {
			                $j.unblockUI(); 
			                return false;               
			        }); 
			        
			         $j('#cancelUI').click(function() {
			                $j.unblockUI(); 
			                return false;               
			        }); 
			        
			                     
			        
	       $j('#okButton').hover(function() {
			   	$j(this).attr("src","/images/bu_ok_o.gif");
					}, function() {
					$j(this).attr("src","/images/bu_ok.gif");
					
			}); 
			
			$j('#cancelUI').hover(function() {
			    	$j(this).attr("src","/images/bu_cancel_o.gif");
					}, function() {
					$j(this).attr("src","/images/bu_cancel.gif");
			});  
			
			$j('#deleteOk').click(function () {	
				
				var sYourpass   = $j('#accountPassword').val();			
				sYourpass =  sYourpass.replace(/^\s+|\s+$/g, '');

					if(sYourpass == "")
					{			
						$j('#accountPassword').focus();		
						return false;
					}					
				       
						$j.ajax({ 
			                url: '/settings/deleteUserAccount?password='+sYourpass, 
			                cache: false,                         
			                success: function(html){                
			                   $j('#deleteMessage') .html(html); 
			                   //folderList(1);                                      	
			                }		                
		            });                 
			});			    
  		}
     });
}
  /*Delete Account ends*/
}	

/*function getOtherSearches(area)
{			
	$j.ajax({					
			  url: '/searchHistory/otherSearchResults?area='+area,
	    	  cache: false,
	    	  data: "keywords="+$j('#searchMyHistoryField').val(),   
			  success: function(html){
			  $j("#otherSearchResultsId").html(html);			  			   
			  }
	});
}*/




 /*COMMENT TAG CLICK EVENT*/
 
/*function toggleid(flag)
{
	
	if(flag=='closeTagUI')
	{
		$j('#closeTagUI').click(function() { 
		                $j.unblockUI(); 
		                return false; 
		                 
		        });
	 }      
}
*/

 /*COMMENT TAG CLICK EVENT ENDS*/

/****************************
 * Call jquery when page loads 
 *****************************/
$j(document).ready(function(){
	 
	 /*Open a link in a new window*/
	 $j(function(){
     $j('.quicktourLink').click(function(){
        this.target = "_blank";
   });
  });	
  $j("#what").click(function () {
    $j("#col2").toggle();      
  });
	

/*	$j('#hooeeyimage').click(function(){
		$j('#hooeeyimage').attr({src:"../../images/bu_my_folders_o.gif"});
	});  
	*/
	
	$j(':input:visible:enabled:first').focus();  	
	/*MYHOOEEY SECTION  */
/*	$j('#bumyfolders').click(function(){
 	$j('#bufolderimage').attr({src : "../../images/bu_my_folders_o.gif"});
	});*/    
	/* MYHOOEEY SECTION ENDS*/	
});
	
                




