var $jquery = jQuery.noConflict();

var advancedOptions = "all";

/*jquery simplemodal alert box*/
function jqueryalert(message)
{ 
 $jquery('#alertBox').modal({
  closeHTML:"<a href='#' title='Close' class='modal-close'><img src='/images/close.gif' border=0></img></a>",
  position: ["40%",],
  overlayId:'confirm-overlay',
  containerId:'confirm-container', 
  onShow: function (dialog) {
    $jquery('.message', dialog.data[0]).append(message);
    $jquery('.yes', dialog.data[0]).click(function () {
      $jquery.modal.close();
    });
  }
});
}
function validateEmail(emailAddress) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   
   if(reg.test(emailAddress) == false) {
       jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'> Invalid Email Address.</img> ");
       return false;      
   }
   else
   return true;
}

function pilotUsersData()
{
  var usermail = $jquery('#pilotUserMail').val();
  if(usermail == ''){
     jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'> Please enter your email.</img> ");
     return false;
  }
     /*Email validation*/   
    var result = validateEmail(usermail);  
   if(result){     	
   $jquery.ajax({             
        url: '/hwphomepage/hwpSavePilotUsersData?email='+usermail,
        cache: false, 
        success: function(html){        	
         $jquery('#pilotUserConfirm').html(html);    
         $jquery('#pilotUserMail').val('');
       
          jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img> Thank you for Registering.");
          return false;         
        }
    });           
    }  
}

function hwpKeywordSearch()
{
  var searchFlag = "all";
  var keyword = document.getElementById('searchInput').value;
  location.href="/hwpsearch/index?keyword="+keyword+"&sFlag="+searchFlag;
}

function advancedOptionsSelect(keyword)
{ 	
  var searchCriteria=""; 
  
  if(advancedOptions == 'all')
  { 
    searchCriteria = "usertags:"+keyword+" OR url:"+keyword+" OR name:"+keyword+" OR html: "+keyword+"" ;   
  }
  else 
  {   
    var searchCrt="";
    var optionsArray=advancedOptions.split(','); 
   
    for(var i=0;i<optionsArray.length;i++)
    { 
      if(optionsArray[i]=="titleCheckbox")      
        searchCrt+="name:"+keyword+" OR ";
      else if(optionsArray[i]=="addressCheckbox")      
          searchCrt+="url:"+keyword+" OR ";      
      else if(optionsArray[i]=="metaTagCheckbox")
        searchCrt+="usertags:"+keyword+" OR meta_tag:"+keyword;
      else if(optionsArray[i]=="contentCheckbox")
          searchCrt+="html:"+keyword+" OR ";   
    }
     searchCriteria=searchCrt.substr(0,searchCrt.length-4);    
  }
  return searchCriteria;  
}

function clickAdvancedSearch()
{ 
 $jquery.ajax({             
        url: '/hwpsearch/hwpAdvancedSearch',
        cache: false, 
        success: function(html){  
        $jquery('#advancedSearchDiv').html(html);     
          
        if(advancedOptions !="all")
        {
	        var optionsArray=advancedOptions.split(',');
	        $jquery('input[name=content]').attr('checked', false);       
	        $jquery('input[name=address]').attr('checked', false);   
	        $jquery('input[name=title]').attr('checked', false);     
	        $jquery('input[name=metatags]').attr('checked', false); 
            
	        for(var i=0;i<optionsArray.length;i++)    
	        {                     
	          if(optionsArray[i]=="titleCheckbox")
	          {       
	            $jquery('input[name=title]').attr('checked', true);       
	          }         
	          else if(optionsArray[i]=="addressCheckbox")
	          {       
	            $jquery('input[name=address]').attr('checked', true);   
	          }
	         else  if(optionsArray[i]=="metaTagCheckbox")
	          { 
	            $jquery('input[name=metatags]').attr('checked', true);       
	          }     
	          else  if(optionsArray[i]=="contentCheckbox")
	          { 
	            $jquery('input[name=content]').attr('checked', true);       
	          }
	        }
	      }                  
          
        $jquery.blockUI({ message: $jquery('#advancedSearchDiv'),
        css: { 
            padding:          '1px',
            margin:             0,
            width:              '330px',                 
            top:                    '20%', 
            left:                   '39%', 
            textAlign:          '', 
            color:                '#000', 
            border:             '0px',                
            cursor:               'default'
            },
             // styles for the overlay
            overlayCSS:  { 
                backgroundColor:'#000', 
                opacity:        '0.6' 
            }           
             
      });
        $jquery('#cancelAdvncedUI').click(function() { 
          $jquery.unblockUI(); 
          return false; 
    });    
    $jquery('#closeSearch').click(function() { 
          $jquery.unblockUI(); 
          return false; 
  });                
            
        }   
    });
}

function advancedSearchClick()
{
  var sAdvancedOptions="";
  var count=0;
  var inputs = document.getElementsByTagName("input");
    for(var t = 0;t<inputs.length;t++){
     if(inputs[t].type == "checkbox")
     {
       if(inputs[t].checked)
       {
         sAdvancedOptions+=inputs[t].id+",";
         count++;
     }
     }
   }  
   if(count!=0)
    advancedOptions=sAdvancedOptions.substr(0,sAdvancedOptions.length-1);    
  $jquery.unblockUI();     
}
 

 function hwpShowAllDetails(rowid)
  {   	
    $jquery.ajax({             
        url: '/hwpsearch/hwpShowAllDetails?sid='+rowid,
        cache: false, 
        success: function(html){  
          $jquery('.showAllDetailsViewDiv').html(html);
         $jquery(".showAllDetailsViewDiv").modal({
                minHeight:400,
                minWidth: 960,
                opacity:60,
                overlayCss: {backgroundColor:"#000"}
          });
          $jquery('.cancelBtn').click(function() { 
            $jquery.modal.close();     
            return false; 
          });    
        }
     });
  }
  
  function fullDetailsView(path,flag)
  {   
    if(flag == 'imageView')
    {
      $jquery('#addToAnyDiv').hide();
      $jquery("#change_background").css('background-image','url(../images/screen_space_bg_new.jpg)');
      $jquery("#imageview a").addClass("headingtabtxtorange").removeClass("headingtabtxtwhite");
     // $jquery("#textview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
      $jquery("#websiteview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
     // var frameDiv = '<img src='+path+' width="967" height="400" />';
     var frameDiv = '<iframe src='+path+' width="967" height="444" style="border:0px solid #FFFFFF;"></iframe>';
     $jquery('.detailsViewDiv').html(frameDiv);     
    }
    if(flag == 'textView')
    { 
      $jquery('#addToAnyDiv').hide();    
      $jquery("#imageview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
      $jquery("#textview a").addClass("headingtabtxtorange").removeClass("headingtabtxtwhite");
      $jquery("#websiteview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
      $jquery("#change_background").css('background-image','url(../images/screen_space_bg_image.jpg)');
      var frameDiv ='<iframe src="../users/'+path+'" width="967" height="444" style="border:0px solid #FFFFFF;"></iframe>';         
      $jquery('.detailsViewDiv').html(frameDiv);     
    }       
    if(flag == 'websiteView')
    {     
     $jquery('#addToAnyDiv').show(); //shows the add to any
     $jquery("#imageview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
     $jquery("#textview a").addClass("headingtabtxtwhite").removeClass("headingtabtxtorange");
     $jquery("#websiteview a").addClass("headingtabtxtorange").removeClass("headingtabtxtwhite");
     $jquery("#change_background").css('background-image','url(../images/screen_space_bg_image_new.jpg)');
     //var frameDiv ='<iframe src='+path+' width="967" height="565"></iframe>';
     var frameDiv ='<iframe src='+path+' width="979" height="444" style="border:0px solid #FFFFFF;"></iframe>';
     $jquery('.detailsViewDiv').html(frameDiv);   
    }   
  }
  
  function downloadHwpToolbar()
  {  	
       $jquery.ajax({             
        url: '/hwpdownload/hwpDownloadView?hwpemail_option='+flag,
        cache: false, 
        success: function(html){  
          $jquery('#downloadToolbarViewDiv').html(html);     

	     /* Chained call with no options*/
	        $jquery("#downloadToolbarViewDiv").modal({
	           minHeight:400,
	           minWidth: 517,
	           opacity:60,
	           overlayCss: {backgroundColor:"#000"}
	     });
          
      /*     $jquery.blockUI({ message: $jquery('#downloadToolbarViewDiv'),
           css: { 
	            padding:          '1px',
	            margin:             0,
	            width:              '517px',                 
	            top:                    '20%', 
	            left:                   '30%', 
	            textAlign:          '', 
	            color:                '#000', 
	            border:             '0px',                
	            cursor:               'default'
            },
             // styles for the overlay
            overlayCSS:  { 
                backgroundColor:'#000', 
                opacity:        '0.6' 
            }                       
      });
         $jquery('.cancelBtn').click(function() { 
            $jquery.unblockUI(); 
            return false; 
          });*/
          $jquery('.cancelBtn').click(function() { 
            $jquery.modal.close();
            return false; 
          });    
          
     /* $jquery("input[name='toolbartype']").click(function(){      
          $jquery('#downLoadToolBarType').html('<a href="#" onclick="downloadToolbar();"><img src="../images/btn_downloadsmall.gif" width=72 height=29 border=0 title="download" alt="download"></img></a>');       
      })*/;      
      }
  	 });
  }
  
 function checkEmail(sEmail)
 { 	
  var emailRegEx1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/;
  if (sEmail.match(emailRegEx1))
  { 
    return true;
  }   
  else
  {
    return false;
  }   
 }

   function chkBrowserType(type)
  {  	
  if(type == "IE")
  {
   $jquery('#dwnload-instruction-IE').show();
   $jquery('#dwnload-instruction-firefox').hide();
  }
  else if(type == "Firefox")
   {
   $jquery('#dwnload-instruction-firefox').show();
   $jquery('#dwnload-instruction-IE').hide();
   }
  }

  function downloadToolbar(osType,email)
  {
   	var toolbarType="";
  	
  	if(osType=="Windows")
    {  
      if($jquery('#IEToolbar').attr('checked'))
      {
        toolbarType="ie_toolbar";
        window.location.href = "/downloads/ie/hooeeywebprintbar1.0b.exe";
      }
      else
      {
         toolbarType="windows_ff_toolbar";     
         window.location.href = "/downloads/firefox/hooeeywebprintbar1.0b.xpi";
      }             
    }
    else if(osType=="Linux")
    {
      toolbarType="linux_ff_toolbar";
      window.location = "/downloads/Linux/hooeeywebprintbar1.0b_linux.xpi";
    }
    else if(osType=="Mac")
    {
      toolbarType="mac_ff_toolbar";
      window.location.href = "/downloads/mac/hooeeywebprintbar1.0b_mac.xpi";
    }
  	
  	if(email == '')  	{
  	 mailId = $jquery('#validate').val();
  	}  	
  	else{  	
  		mailId = email;
  	}
  	
  $jquery.ajax({ 
        url: '/hwpdownload/hwpSaveToolbarDetails?email='+encodeURIComponent(mailId)+'&toolbar_type='+toolbarType,
        cache: false,                                
        success: function(html){
        
        }
	   });	
  }
    
  
  function loginCheck()
  {
  	var reminder = '';
  	var email = $jquery('#hwpplusemail').val();
  	var password = $jquery('#hwppluspassword').val();
  	
    //f($jquery("input[name='remember']:checked")==true)
   /* if(document.getElementById('remember').checked)    
     reminder=1;    
    else    
    reminder=0;*/ 	
      
  	 $jquery.ajax({             
        //url: '/hwplogin/loginCheck?email='+email+'&password='+password+'&remember='+reminder,
        url: '/hwplogin/loginCheck?email='+email+'&password='+password,
        cache: false, 
        success: function(html){  
          $jquery('#hwpplusLoginMessage').html(html);
          $jquery('#hwpplusLoginMessage').show();
        }
      });
  }

  function hwplusBetaloginCheck()
 {
  var email = $jquery('#email').val();
  var password = $jquery('#password').val();
  $jquery.ajax({
          url: '/hwplogin/loginCheck?email='+email+'&password='+password,
          cache: false,
          success: function(html){
            $jquery('#callbackMsgDiv').html(html);
            $jquery('#callbackMsgDiv').show();
           }
         });
 }
  
  function hwpForgotPassword()
  {  	
  	var email = $jquery('#userEmail').val();
  	 $jquery.ajax({             
        url: '/hwplogin/hwpResetPassword?email='+email,
        cache: false, 
        success: function(html){  
          $jquery('#errorMsgDiv').html(html);
          $jquery('#errorMsgDiv').show();
        }
      });
  }
  
  function forgotPasswordView()
  {    	 
  	 $jquery('#forgotPass').show();
  	 //$jquery("#forgotPass").animate({height: "toggle"}, 1000);
  	 $jquery('#errorMsgDiv').hide();
  	 $jquery('#hwpLoginBar').hide();
  	 $jquery("#resetPassMessage").hide()
  }
  
  function viewProfile()
  {
    $jquery.ajax({             
        url: '/hwpsettings/hwpViewProfile',
        cache: false, 
        success: function(html){  
          $jquery('#hwpViewProfileDiv').html(html);     
          
           $jquery.blockUI({ message: $jquery('#hwpViewProfileDiv'),
           css: { 
              padding:          '1px',
              margin:             0,
              width:              '400px',                 
              top:                    '16%',              
              textAlign:          '', 
              color:                '#000', 
              border:             '0px',                
              cursor:               'default'
            },
             // styles for the overlay
            overlayCSS:  { 
                backgroundColor:'#000', 
                opacity:        '0.6' 
            }                       
      });
         $jquery('.cancelBtn').click(function() { 
            $jquery.unblockUI(); 
            return false; 
          });    
        }
     });
  }
  
  function showCaptchaMessage(div_id)
  {
   $jquery('.signup_error_details').hide();
   $jquery('.signupnew_error_details').hide();
   $jquery('#'+div_id).css('display','block');
  }
  
  function hideCaptchaMessage(div_id) 
  {
    $jquery('#'+div_id).css('display','none');
  }
    
 /* function hwpKeywordLookup(inputString,moduleName)
  {
  	if(inputString.length == 0) {
        // Hide the suggestion box.
        $jquery('#suggestions').hide();
  	}
  	else
  	{
  		$jquery.ajax({             
        url: '/hwpsearch/hwpSuggestionList?queryString='+inputString+'&moduleName='+moduleName,
        cache: false, 
        success: function(html){  
        	$jquery('#suggestions').show();
          $jquery('#autoSuggestionsListDiv').html(html); 
        }
     });
  	}  
  }
  */
  
  function afterSelectListItem() 
  {   	
    //$jquery('#searchInput').val(thisValue);
    //$jquery('#suggestions').hide();
    if(moduleName == "hwpsearch")      
      hwpCloudSearch(flag);
    else if(moduleName == "hwpbrowse" || moduleName == "hwpanalysis" || moduleName == "hwpsettings")    
      hwpKeywordSearch();
  }
  
  /*Tag the links in show all details template*/
  function hwpLinkDetailsTag(shadowId)
  {  	
  	  $jquery.ajax({ 
              url: '/hwpsearch/hwpCreateTag?sid='+shadowId,
              cache: false, 
              success: function(html){
              $jquery('#hwpCreateTag').html(html);
                            
            $jquery.blockUI({ message: $jquery('#hwpCreateTag'),
            css: { 
                padding:          '1px',
                margin:             0,
                width:             '330px', 
                top:                '20%', 
                left:               '35%', 
                textAlign:        '', 
                color:              '#000', 
                border:             0, 
                backgroundColor:  'white',
                cursor:               'default'
            },
               // styles for the overlay
                overlayCSS:  { 
                    backgroundColor:'#000', 
                    opacity:        '0.6' 
                }           
       });
       
         $jquery('.hwpCancel').click(function() { 
              $jquery.unblockUI(); 
              return false; 
      });     
      
       $jquery('#hwpSaveTag').click(function (e) {                   
            $jquery.ajax({               
                          url: '/hwpsearch/hwpSaveTag?sid='+shadowId+'&tagName='+$jquery('#tagname').val(), 
                          cache: false,                                    
                          success: function(html){                
                           $jquery('#tagMessage').html(html);                                                                                                   
                          }
                      });
                });                 
     }
  });
  }
  
  /*Favorite a link in show all details template*/
  function hwpLinkDetailsFavorites(shadowId)
  {
  	 $jquery.ajax({ 
              url: '/hwpsearch/hwpSaveFavorites?sid='+shadowId,
              cache: false, 
              success: function(html){
              $jquery('#hwpAddFavoritesDiv').html(html);
           //   jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img>Added to favorites successfully !");
              }
      });
  }
  
  function hwpShowPageDetails(shadowId)
  {
  	 $jquery.ajax({ 
              url: '/hwpsearch/hwpShowPageDetails?sid='+shadowId,
              cache: false, 
              success: function(html){
              $jquery('#hwpShowPageDetailsDiv').html(html);
                            
            $jquery.blockUI({ message: $jquery('#hwpShowPageDetailsDiv'),
            css: { 
                padding:          '1px',
                margin:             0,
                width:             '402px', 
                top:                '20%', 
                left:               '35%', 
                textAlign:        '', 
                color:              '#000', 
                border:             0, 
                backgroundColor:  'white',
                cursor:               'default'
            },
               // styles for the overlay
                overlayCSS:  { 
                    backgroundColor:'#000', 
                    opacity:        '0.6' 
                }           
       });
       
         $jquery('.cancelBtn').click(function() { 
              $jquery.unblockUI(); 
              return false; 
      });     
     }
  });
  }
 
 /*Position(ie,center) the  the Ajax indicator  */ 
 function posIndicatorCenter()
{
  $jquery('#imgProg').show();
    var height = $jquery(window).height();
    var width = $jquery(document).width();
    var msg = $jquery('#imgProg'); 

    msg.css({
        'left' : width/2 - (msg.width() / 2),  // half width - half element width
        'top' : height/2 - (msg.height() / 2), // similar
        'z-index' : 15                     // make sure element is on top
    });         
    
   // $jquery('#imgProg').css({display:"none"});     
   $jquery(document).ajaxStart(function(){         
    $jquery('#imgProg').show();         
     
 }).ajaxStop(function(){
      $jquery('#imgProg').hide();
  });
}

/*hwp tutorials*/
function changeTutTab(flag)
{
	 if(flag==1)
  {   
    document.getElementById("divLeftTutInstall").className="tourcontentSelected";
    document.getElementById("divLeftTutHow").className="tourcontent";
    document.getElementById("divLeftTutPrivacy").className="tourcontent";
    document.getElementById("divLeftTutOrg").className="tourcontent";
    document.getElementById("divLeftTutExport").className="tourcontent";
    document.getElementById("divLeftTutSettings").className="tourcontent";
        
    $jquery('#divTutInstall').css('display','block');   
    $jquery('#divTutHow').css('display','none');   
    $jquery('#divTutPrivacy').css('display','none');   
    $jquery('#divTutOrg').css('display','none');   
    $jquery('#divTutExport').css('display','none');   
    $jquery('#divTutSettings').css('display','none');  
    
  }
  else if(flag==2)
  {     
  	document.getElementById("divLeftTutInstall").className="tourcontent";
    document.getElementById("divLeftTutHow").className="tourcontentSelected";
    document.getElementById("divLeftTutPrivacy").className="tourcontent";
    document.getElementById("divLeftTutOrg").className="tourcontent";
    document.getElementById("divLeftTutExport").className="tourcontent";
    document.getElementById("divLeftTutSettings").className="tourcontent"; 	
    
    $jquery('#divTutInstall').css('display','none');   
    $jquery('#divTutHow').css('display','block');   
    $jquery('#divTutPrivacy').css('display','none');   
    $jquery('#divTutOrg').css('display','none');   
    $jquery('#divTutExport').css('display','none');   
    $jquery('#divTutSettings').css('display','none');
  }
  else if(flag==3)
  {
  	document.getElementById("divLeftTutInstall").className="tourcontent";
    document.getElementById("divLeftTutHow").className="tourcontent";
    document.getElementById("divLeftTutPrivacy").className="tourcontentSelected";
    document.getElementById("divLeftTutOrg").className="tourcontent";
    document.getElementById("divLeftTutExport").className="tourcontent";
    document.getElementById("divLeftTutSettings").className="tourcontent";  
    
    $jquery('#divTutInstall').css('display','none');   
    $jquery('#divTutHow').css('display','none');   
    $jquery('#divTutPrivacy').css('display','block');   
    $jquery('#divTutOrg').css('display','none');   
    $jquery('#divTutExport').css('display','none');   
    $jquery('#divTutSettings').css('display','none');
  }
  else if(flag==4)
  {
  	document.getElementById("divLeftTutInstall").className="tourcontent";
    document.getElementById("divLeftTutHow").className="tourcontent";
    document.getElementById("divLeftTutPrivacy").className="tourcontent";
    document.getElementById("divLeftTutOrg").className="tourcontentSelected";
    document.getElementById("divLeftTutExport").className="tourcontent";
    document.getElementById("divLeftTutSettings").className="tourcontent";  
    
    $jquery('#divTutInstall').css('display','none');   
    $jquery('#divTutHow').css('display','none');   
    $jquery('#divTutPrivacy').css('display','none');   
    $jquery('#divTutOrg').css('display','block');   
    $jquery('#divTutExport').css('display','none');   
    $jquery('#divTutSettings').css('display','none');
  }
  else if(flag==5)
  {
  	document.getElementById("divLeftTutInstall").className="tourcontent";
    document.getElementById("divLeftTutHow").className="tourcontent";
    document.getElementById("divLeftTutPrivacy").className="tourcontent";
    document.getElementById("divLeftTutOrg").className="tourcontent";
    document.getElementById("divLeftTutExport").className="tourcontentSelected";
    document.getElementById("divLeftTutSettings").className="tourcontent";  
    
    $jquery('#divTutInstall').css('display','none');   
    $jquery('#divTutHow').css('display','none');   
    $jquery('#divTutPrivacy').css('display','none');   
    $jquery('#divTutOrg').css('display','none');   
    $jquery('#divTutExport').css('display','block');   
    $jquery('#divTutSettings').css('display','none');
  }
  else if(flag==6)
  {
  	document.getElementById("divLeftTutInstall").className="tourcontent";
    document.getElementById("divLeftTutHow").className="tourcontent";
    document.getElementById("divLeftTutPrivacy").className="tourcontent";
    document.getElementById("divLeftTutOrg").className="tourcontent";
    document.getElementById("divLeftTutExport").className="tourcontent";
    document.getElementById("divLeftTutSettings").className="tourcontentSelected";  
    
    $jquery('#divTutInstall').css('display','none');   
    $jquery('#divTutHow').css('display','none');   
    $jquery('#divTutPrivacy').css('display','none');   
    $jquery('#divTutOrg').css('display','none');   
    $jquery('#divTutExport').css('display','none');   
    $jquery('#divTutSettings').css('display','block');
  }
}

/*take the tour*/
function changeTab(flag)
{
   if(flag==1)
  {  	
    document.getElementById("divLeftInstall").className="tourcontentSelected";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";

  	
  	$jquery('#divEasyInstallation').css('display','block');   
  	$jquery('#divSecurity').css('display','none');   
  	$jquery('#divAutomaticCapture').css('display','none');   
  	$jquery('#divSearch').css('display','none');   
  	$jquery('#divBrowse').css('display','none');   
  	$jquery('#divStatistics').css('display','none');   
  	$jquery('#divCloud').css('display','none');   
  	$jquery('#divEasyShare').css('display','none');
  }
  else if(flag==2)
  {   	
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontentSelected";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";
    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','block');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divStatistics').css('display','none');   
    $jquery('#divCloud').css('display','none');
    $jquery('#divEasyShare').css('display','none');
  }
  else if(flag==3)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontentSelected";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";

    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','block');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divStatistics').css('display','none');   
    $jquery('#divCloud').css('display','none');
    $jquery('#divEasyShare').css('display','none');
  }
  else if(flag==4)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontentSelected";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";
    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','block');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divStatistics').css('display','none');   
    $jquery('#divCloud').css('display','none');
    $jquery('#divEasyShare').css('display','none');
  }
  else if(flag==5)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontentSelected";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";
    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','block');   
    $jquery('#divStatistics').css('display','none');   
    $jquery('#divCloud').css('display','none');
    $jquery('#divEasyShare').css('display','none');
  }
  else if(flag==6)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontentSelected";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontent";
    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divEasyShare').css('display','none');
    $jquery('#divStatistics').css('display','block');   
    $jquery('#divCloud').css('display','none');
  }
  else if(flag==7)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontentSelectedCloud";
    document.getElementById("divLeftEasyShare").className="tourcontent";
    
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divStatistics').css('display','none'); 
    $jquery('#divEasyShare').css('display','none');  
    $jquery('#divCloud').css('display','block');
  }  
   else if(flag==8)
  {
    document.getElementById("divLeftInstall").className="tourcontent";
    document.getElementById("divLeftSecurity").className="tourcontent";
    document.getElementById("divLeftAutomaticCapture").className="tourcontent";
    document.getElementById("divLeftSearch").className="tourcontent";
    document.getElementById("divLeftBrowse").className="tourcontent";
    document.getElementById("divLeftStatistics").className="tourcontent";
    document.getElementById("divLeftCloud").className="tourcontent";
    document.getElementById("divLeftEasyShare").className="tourcontentSelected";
        
    $jquery('#divEasyInstallation').css('display','none');   
    $jquery('#divSecurity').css('display','none');   
    $jquery('#divAutomaticCapture').css('display','none');   
    $jquery('#divSearch').css('display','none');   
    $jquery('#divBrowse').css('display','none');   
    $jquery('#divStatistics').css('display','none');   
    $jquery('#divCloud').css('display','none');
    $jquery('#divEasyShare').css('display','block');
  }  
} 

/*startup checkbox clicked*/
function startupCheck()
{
	$jquery.post("/hwpsearch/hwpHideStartupMessage");
}

/*jquery simplemodal alert box*/
function jqueryalert(message)
{ 
 $jquery('#alertBox').modal({
  closeHTML:"<a href='#' title='Close' class='modal-close'><img src='/images/close.gif' border=0></img></a>",
  position: ["40%",],
  overlayId:'confirm-overlay',
  containerId:'confirm-container', 
  onShow: function (dialog) {
    $jquery('.message', dialog.data[0]).append(message);
     // if the user clicks "yes"
    $jquery('.yes', dialog.data[0]).click(function () {
         // close the dialog
      $jquery.modal.close();
    });
  }
});
}

/*jquery confirm boxes*/
function confirm(message, callback) {
  $jquery('#confirm').modal({
    closeHTML:"<a href='#' title='Close' class='modal-close'><img src='/images/close.gif' border=0></img></a>",
    position: ["40%",],
    overlayId:'confirm-overlay',
    containerId:'confirm-container', 
    onShow: function (dialog) {
      $jquery('.message', dialog.data[0]).append(message);

      // if the user clicks "yes"
      $jquery('.yes', dialog.data[0]).click(function () {
        // call the callback
        if ($jquery.isFunction(callback)) {
          callback.apply();
        }
        // close the dialog
        $jquery.modal.close();
      });
    }
  });
}

   function chkAllThumbRows()
   {
     var i;
      if($jquery('#chkAllThumbRows').is(':checked')===true) 
      {          
           for(i=0;i<50;i++)
           {      
               $jquery("#checkThumb_"+i).attr('checked', true);
               //$jquery('.thumbnailtxt_'+i).css('display','block');
               //changeGridRowBackGroundColor(i,'FFFFCC');
           }    
      }
      else
      {
         for(i=0;i<50;i++)
           {
               $jquery("#checkThumb_"+i).attr('checked', false);
               //$jquery('.thumbnailtxt_'+i).css('display','none');
               //changeGridRowBackGroundColor(i,'FFFFFF');
           }    
      }
   }

      /*select all links in thumbnail view*/
   function chkAllThumbLinks()
   { 
     $jquery('#chkAllThumbRows').attr('checked', true);
     chkAllThumbRows();
   }
   
    function chkThumbRow(obj) 
    { 
      var rowid=(obj.id).split("_");
      var rownum = rowid[1];
      if($jquery('#chkAllThumbRows').attr("checked") === true)
      {         
        $jquery('#chkAllThumbRows').attr("checked", false);
      }    
    }
    
 function webprintTag()
 { 
  var sShadowId="";
  var iCount=0;
   if(flag == 'gridView' || flag == 'BwDateView')
   {        
    for(var y=0;y<20;y++)
    {
      if($jquery("#checkbox_"+y).length>0 && $jquery("#checkbox_"+y).attr("checked") === true)
      {
          sShadowId+=$jquery("#checkbox_"+y).val()+",";
          iCount++;
      }  
    }
   }
    else if(flag == 'thumbView' || flag == 'BwThumbnailView')
     {
       for(var z=0;z<50;z++)
        {         
          if($jquery("#checkThumb_"+z).length>0 && $jquery("#checkThumb_"+z).attr("checked") === true)
          {               
              sShadowId+=$jquery("#checkThumb_"+z).val()+",";      
              iCount++;
          }     
        } 
     }
    if(iCount===0)
    {
      jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img>Please select link(s) to tag.");
      return false;
    }
    sShadowId=sShadowId.substring(0,sShadowId.length-1);     
               
     $jquery.ajax({ 
              url: '/hwpsearch/hwpCreateTag?sid='+sShadowId,
              cache: false, 
              success: function(html){
              $jquery('#hwpCreateTag').html(html);
                            
            $jquery.blockUI({ message: $jquery('#hwpCreateTag'),
            css: { 
                padding:          '1px',
                margin:             0,
                width:             '330px', 
                top:                '20%', 
                left:               '35%', 
                textAlign:        '', 
                color:              '#000', 
                border:             0, 
                backgroundColor:  'white',
                cursor:               'default'
            },
               // styles for the overlay
                overlayCSS:  { 
                    backgroundColor:'#000', 
                    opacity:        '0.6' 
                }           
       });
       
         $jquery('.hwpCancel').click(function() { 
              $jquery.unblockUI(); 
              return false; 
      });     
      
       $jquery('#hwpSaveTag').click(function (e) {                   
            $jquery.ajax({               
                          url: '/hwpsearch/hwpSaveTag?sid='+sShadowId+'&tagName='+$jquery('#tagname').val()+'&viewmode=normal',  
                          cache: false,                                    
                          success: function(html){                
                           $jquery('#tagMessage').html(html);                                                                                                   
                          }
                      });
                });                 
     }
  });
} 

/*delete the selected links*/
function webprintDelete(keyword) 
  {     
    var sShadowId="";
    var iCount=0;
    
     if(flag == 'gridView' || flag == 'BwDateView')
     {        
      for(var y=0;y<20;y++)
      {       
        if($jquery("#checkbox_"+y).length>0 && $jquery("#checkbox_"+y).attr("checked") === true)
        {
            sShadowId+=$jquery("#checkbox_"+y).val()+",";      
            iCount++;
        }     
      } 
     }
     else if(flag == 'thumbView' || flag == 'BwThumbnailView')
     {
        for(var z=0;z<50;z++)
        {         
          if($jquery("#checkThumb_"+z).length>0 && $jquery("#checkThumb_"+z).attr("checked") === true)
          {               
              sShadowId+=$jquery("#checkThumb_"+z).val()+",";      
              iCount++;
          }     
        } 
     }
        sShadowId=sShadowId.substring(0,sShadowId.length-1);        
        if(iCount===0)
        {         
          // Opening animations
          //$jquery("#alertBox").modal();
          jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img>Please select link(s) to delete.");
          return false;
        }
      else
      {
          confirm("<img src='/images/icon_delete.gif' style='vertical-align: middle;'></img>Please confirm deletion of links?", function () {
               $jquery.ajax({ 
                url: '/hwpsearch/hwpDeleteLinks?sid='+sShadowId,
                cache: false, 
                success: function(html){
                  if(flag == 'gridView'){
                       hwpGridView( keyword,1,'date','DESC');
                  }
                    else if(flag == 'thumbView'){
                       hwpThumbnailView(keyword,1);
                    }  
                    else if(flag == 'BwThumbnailView'){  
                       browseByThumbnail(1);
                    }  
                    else if(flag == 'BwDateView'){  
                       browseByDate(1,"date","DESC");
                    }  
                }
           });
          });      
      }
  }

function webprintFavorites()
{
  var sShadowId="";
    var iCount=0;
    
     if(flag == 'gridView' || flag == 'BwDateView')
     {        
      for(var y=0;y<20;y++)
      {       
        if($jquery("#checkbox_"+y).length>0 && $jquery("#checkbox_"+y).attr("checked") === true)
        {
            sShadowId+=$jquery("#checkbox_"+y).val()+",";      
            iCount++;
        }     
      } 
     }
     else if(flag == 'thumbView' || flag == 'BwThumbnailView')
     {
        for(var z=0;z<50;z++)
        {         
          if($jquery("#checkThumb_"+z).length>0 && $jquery("#checkThumb_"+z).attr("checked") === true)
          {               
              sShadowId+=$jquery("#checkThumb_"+z).val()+",";      
              iCount++;
          }     
        } 
     }
    
      if(iCount===0)
      {
        jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img>Please select a link(s) to add to favorites.");
        return false;
      }
      sShadowId=sShadowId.substring(0,sShadowId.length-1);    
      $jquery.ajax({ 
              url: '/hwpsearch/hwpSaveFavorites?sid='+sShadowId,
              cache: false, 
              success: function(html){
              $jquery('#hwpAddFavoritesDiv').html(html);
              jqueryalert("<img src='/images/icon_alert.gif' style='vertical-align: middle;'></img>Added to favorites successfully !");
              }
      });
}
 
 function chkAllGridRows()
  {
    var i;
    if($jquery('#chkAllGridRows').is(':checked')===true) 
  {
       for(i=0;i<20;i++)
       {
           $jquery("#checkbox_"+i).attr('checked', true);
           changeGridRowBackGroundColor(i,'EAEAEA');
       }    
  }
  else
  {
     for(i=0;i<20;i++)
       {
           $jquery("#checkbox_"+i).attr('checked', false);
           changeGridRowBackGroundColor(i,'FFFFFF');
         }    
    }
 }

 /*check(select) all links in gridview */
 function chkAllGridLinks()
 {
   $jquery('#chkAllGridRows').attr('checked', true); 	
   chkAllGridRows();
 }
 
 function chkGridRow(obj) 
 {    
    var rowid=(obj.id).split("_");;      
    //var urlId=urlid.split("_");
    var rownum = rowid[1];      
     if(obj.checked)
     {       
        changeGridRowBackGroundColor(rownum,'EAEAEA');
     }     
    else
      {     
        changeGridRowBackGroundColor(rownum,'FFFFFF');           
        //$jquery( "#chkAllRow" + " :checkbox").attr('checked', $jquery('#' + obj).is(':checked'));
        if($jquery('#chkAllGridRows').attr("checked") === true)
          $jquery('#chkAllGridRows').attr("checked", false) ;               
      }     
  }
     
  function changeGridRowBackGroundColor(urlid,color)
  {
    $jquery('.gridTitletxt .row_'+urlid).css({backgroundColor:"#"+color});
  }
  
  
 /* hwp video tutorials */ 
function openTutorialVideo(id)
{	
  $jquery.ajax({ 
                url: '/hwptaketour/hwpTutorialVideos?tutor_id='+id, 
                cache: false, 
                success: function(html){         
                $jquery('#hwpDisplayPopupDiv').html(html);                
                  
               $jquery.blockUI({ message: $jquery('#hwpDisplayPopupDiv') ,
              css: { 
                  padding:          '1px',
                  margin:              0,
                  width:               '462px', 
                  top:                    '20%', 
                  left:                   '35%', 
                  textAlign:          '', 
                  color:                '#000', 
                  border:             0,
                  backgroundColor:  'white',
                  cursor:               'default'
              },
               overlayCSS:  { 
                    backgroundColor:'#000', 
                    opacity:        '0.6' 
                }                   
           });
           
            if(id == 'hwpinstall_1')
                $jquery("#tutTitle").html("Downloading hooeey webprint");
            else if(id == 'hwpFirefox_2')
                $jquery("#tutTitle").html("Installation of hooeey webprint for Firefox");
            else if(id == 'hwpIE_3')
                $jquery("#tutTitle").html("Installation of hooeey webprint for Internet Explorer");        
           else if(id == 'hwpOpen_4')
                $jquery("#tutTitle").html("Opening hooeey webprint");  
           else if(id == 'hwpBrowse_5')
                $jquery("#tutTitle").html("hooeey webprint browse");
           else if(id == 'hwpSearch_6')
                $jquery("#tutTitle").html("hooeey webprint search");  
           else if(id == 'hwpRecord_7')
                $jquery("#tutTitle").html("Recording by hooeey webprint");  
           else if(id == 'hwpBlock_8')
                $jquery("#tutTitle").html("Creating block list");  
           else if(id == 'hwpDelete_9')
                $jquery("#tutTitle").html("Deleting the library data");
           else if(id == 'hwpFavorite_10')
                $jquery("#tutTitle").html("Adding to favourites");
           else if(id == 'hwpExportCSV_11')
                $jquery("#tutTitle").html("Exporting your library to CSV");
           else if(id == 'hwpExportCloud_12')
                $jquery("#tutTitle").html("Exporting your library to cloud services");
           else if(id == 'hwpExportPlus_13')
                $jquery("#tutTitle").html("Exporting your library to hooeey webprint plus");  
           else if(id == 'hwpCreatePass_14')
                $jquery("#tutTitle").html("Creating password for hooeey webprint");  
           else if(id == 'hwpDisableScrShot_15')
                $jquery("#tutTitle").html("Disable screenshot capturing");  
           else if(id == 'hwpDleteAll_16')
                $jquery("#tutTitle").html("Deleting your complete library");
                   
            $jquery('#closeTutWindow').click(function() { 
                  $jquery.unblockUI();                  
          }); 
           
        }
        });
}

/*hwp overview*/
function hwpOverview()
{
           $jquery.blockUI({ message: $jquery('#hwpDisplayPopupDiv') ,
              css: { 
                  padding:          '1px',
                  margin:              0,
                  width:               '462px', 
                  top:                    '20%', 
                  left:                   '35%', 
                  textAlign:          '', 
                  color:                '#000', 
                  border:             0,
                  backgroundColor:  'white',
                  cursor:               'default'
              },
               overlayCSS:  { 
                    backgroundColor:'#000', 
                    opacity:        '0.6' 
                }                   
           });
           $jquery('#closeTutWindow').click(function() { 
                  $jquery.unblockUI();                  
          }); 
  } 

/*validate email address*/
  function isValidEmailAddress(emailAddress)
   {
     var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
     return pattern.test(emailAddress);
   }       

   function subscriptionTerms()
   {       
      $jquery("#hwpplusSubscriptionTerms").modal({
        minHeight:340,
        minWidth: 330,
        opacity:60,
        overlayCss: {backgroundColor:"#000"}
      });
           
        $jquery('.cancelBtn').click(function() { 
          $jquery.modal.close();            
          return false; 
      });
   }
   
   function refundPolicy()
   {       
      $jquery("#hwpplusRefundPolicy").modal({
        minHeight:340,
        minWidth: 330,
        opacity:60,
        overlayCss: {backgroundColor:"#000"}
      });
           
        $jquery('.cancelBtn').click(function() { 
          $jquery.modal.close();            
          return false; 
      });
   } 
  
$jquery(document).ready(function(){	
	
	/*to close the start up button*/
	$jquery("#Close-Startup").click(function(){          
      $jquery("#StartUpTip").animate({"height": "toggle"}, { duration: 1000 });
   });
			
		
    $jquery("#captchaInput").keypress(function(e){		    	
       $jquery('#captchaMessage').css('display','none');
    });
		
		
	/*jquery cycle plugin*/
	 $jquery('#s4')
  .after('<div id="nav">') 
  .cycle({ 
    fx:     'scrollRight', 
    speed:  'slow', 
    timeout: 0, 
    pager:  '#nav' ,
    prev:   '#prev2',
    next:   '#next2'    
});
	
	 $jquery("#closeResetPassMessage").click(function(){
           $jquery('#resetPassMessage').hide();
      });
	  	
   	$jquery('#hwpLoginBar').hide();
   	$jquery('#forgotPass').hide();
   	$jquery("#resetPassMessage").hide()
   	
   	$jquery(".loginClick").click(function(){   		
      $jquery("#hwpLoginBar").animate({height: "toggle"}, 1000);
      $jquery('#forgotPass').hide();
      $jquery("#resetPassMessage").hide();
       /*error msg hide*/    
      $jquery('#callbackMsgDiv').hide();
    });
   	
		  
		  /*login page close*/
		   $jquery("#closeLogin").click(function(){
            $jquery("#hwpLoginBar").animate({height: "toggle"}, 1000);
      });
      $jquery("#closeForgotPass").click(function(){
      	$jquery("#forgotPass").animate({height: "toggle"}, 1000);
      });

      // $jquery('ul').accordion(); 	
    
        /*email validation for download */
  $jquery("#validate").keyup(function(){
  var email = $jquery("#validate").val();
   
  if(email != 0)
  {
    if(isValidEmailAddress(email))
	  {   
	   /*$jquery("#validEmail").css({ "background-image": "url('../images/validYes.png')" });*/	  
	   $jquery("#downloadBtn-enabled").show(); 
	   $jquery("#downloadBtn-disabled").hide();
	  }
   else
    {   
     /*$jquery("#validEmail").css({ "background-image": "url('../images/validNo.png')" });*/
     $jquery("#downloadBtn-disabled").show();
     $jquery("#downloadBtn-enabled").hide();    
    }   
   } 
  else
   {   
    $jquery("#validEmail").css({ "background-image": "none" });   
   }
  }); 
     
   	 // $jquery('#loopedSlider').loopedSlider();   	
   	  //var Accordion1 = new Spry.Widget.Accordion("Accordion1");          	  
    
  });
