home *** CD-ROM | disk | FTP | other *** search
/ Mundo do CD-ROM 118 / cdrom118.iso / internet / webaroo / WebarooSetup.exe / Webaroo.msi / _24B2CDBAE9D9477CA1C33EF5F7128377 < prev    next >
Encoding:
Text File  |  2006-03-20  |  10.9 KB  |  355 lines

  1. // i18n issue
  2. function ShowAddFavorite(addToHistory)
  3. {
  4.     var keys = new Array();
  5.     var values = new Array();
  6.     var rowkeys = new Array();
  7.     var rowvalues = new Array();
  8.     AdjustPageElements("favorite");
  9.     AbortPendingRequests();
  10.     
  11.     if(addToHistory)
  12.     {
  13.         dhtmlHistory.add("favorite","");
  14.     }
  15.     
  16.     var favoriteTable = document.getElementById('favoriteTable');
  17.     var htmlData;
  18.     // Clear the table first
  19.     ClearTable('favoriteTable');
  20.     
  21.     // Zeroth => 0 Row , First Cell
  22.     rowkeys[0] = "bgcolor";
  23.     rowvalues[0] = "#FFFFFF";
  24.     //rowkeys[1] = "height";
  25.     //rowvalues[1] = "20px";
  26.     keys[0]="innerHTML"
  27.     values[0]="<font class=\"FavoriteTitle\">Add Web site</font>";
  28.     keys[1]="colspan"
  29.     values[1]="2";
  30.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  31.         
  32.     // 1 Empty Row
  33.     values[0]="";
  34.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  35.     
  36.     // 2 Row Favourite Name Element
  37.     keys[1]="align"
  38.     values[1]="left";
  39.     keys[2]="width"
  40.     values[2]="130";
  41.     values[0]="<font class=\"FavoriteLabel\">Name</font>"; 
  42.     // First Cell
  43.     var row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  44.     // Second Cell
  45.     values[0]="<input type=\"text\" size=\"15\" class=\"styled_input\" maxlength=\"20\" id=\"favoriteName\" name=\"favoriteName\" />";
  46.     AddCellToRow(row,keys,values);
  47.     
  48.     // Empty Row
  49.     keys[1]="colspan"
  50.     values[1]="2";
  51.     values[0]="";
  52.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  53.     
  54.     // Favorite URL Element
  55.     keys[1]="align";
  56.     values[1]="left";
  57.     values[0]="<font class=\"FavoriteLabel\">URL</font>";
  58.     // First Cell
  59.     row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  60.     values[0]="<input type=\"text\" size=\"40\" class=\"styled_input\" id=\"favoriteUrl\" name=\"favoriteUrl\"/>";
  61.     //Second Cell
  62.     AddCellToRow(row,keys,values);
  63.  
  64.     // Empty Row
  65.     keys[1]="colspan"
  66.     values[1]="2";
  67.     values[0] = "";
  68.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  69.     
  70.     // Link Depth Element
  71.     var desc = "Select <b>0</b> to download only the Web page that you specify. <br> Select <b>1</b> to also download all the Web pages linked to the Web page that you specify.";
  72.     keys[1]="align";
  73.     values[1]="left";
  74.     values[0]="<font class=\"FavoriteLabel\">Link Depth</font>";
  75.     // First Cell
  76.     row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  77.     
  78.     values[0]="<select name=\"linkDepth\" id=\"linkDepth\" onchange=\"LinkDepthChange()\" style=\"border:1px solid gray\"><option value=\"0\" selected>0<option value=\"1\">1</select>   <font style=\"font-family:Verdana, 'Times New Roman', Times, serif; font-weight:normal; font-size:10px;\" onMouseover=\"ddrivetip('" + desc + "', 355)\" onMouseout=\"hideddrivetip()\"  border=\"0\"/>(What is this?) </font>";
  79.     keys[1]="verticalAlign";
  80.     values[1]="middle";
  81.     //Second Cell
  82.     AddCellToRow(row,keys,values);
  83.     
  84.     // Empty Row
  85.     keys[1]="colspan";
  86.     values[1]="2";
  87.     values[0] ="";
  88.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  89.     
  90.     // Images Element
  91.     desc = "Select <b>No</b> if you do not want to download images.<br>";
  92.     keys[1]="align";
  93.     values[1]="left";
  94.     values[0]="<font class=\"FavoriteLabel\">Images</font>";
  95.     // First Cell
  96.     row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  97.     values[0]="<font class=\"FavoriteLabel\"><input name=\"images\" checked=\"checked\" type=\"radio\">Include images <br><input  name=\"images\" type=\"radio\">Exclude images</font>";
  98.     keys[1]="verticalAlign";
  99.     values[1]="middle";
  100.     //Second Cell
  101.     AddCellToRow(row,keys,values);
  102.     
  103.     // Empty Row
  104.     keys[1]="colspan";
  105.     values[1]="2";
  106.     values[0] = "";
  107.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  108.     
  109.     //Domain Filter Element
  110.     desc = "Select <b>On</b> if you do not want to download Web pages linked to a domain name different from the one you specify. (Applicable if you select link depth 1) ";
  111.     keys[1]="align";
  112.     values[1]="left";
  113.     keys[2] = "width";
  114.     values[2]="130";
  115.     values[0]="<font class=\"FavoriteLabel\">Domain Filter</font><br><font style=\"font-family:Verdana,arial, sans-serif; font-weight:normal; font-size:10px;\">(Only for link depth 1)</font>";
  116.     // First Cell
  117.     row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  118.     
  119.     values[0]="<font style=\"font-family:Verdana, 'Times New Roman', Times, serif; font-weight:normal; font-size:12px;\"><input id=\"DomainFilter1\" disabled=\"true\" name=\"domainFilter\" checked=\"checked\" value=\"0\" type=\"radio\">Download all links<br><input id=\"DomainFilter2\" name=\"domainFilter\" disabled=\"true\" value=\"1\" type=\"radio\">Download links only from the specified web site</font>";
  120.     keys[1]="verticalAlign";
  121.     values[1]="middle";
  122.     //Second Cell
  123.     AddCellToRow(row,keys,values);
  124.     
  125.     //Empty Row
  126.     keys[1]="colspan";
  127.     values[1]="2";
  128.     values[0] = "";
  129.     AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  130.     
  131.     // Button Element Row
  132.     keys[1]="align";
  133.     values[1]="left";
  134.     // First Cell
  135.     row = AddRowToTable('favoriteTable', rowkeys,rowvalues,keys,values);
  136.     values[0]="<button type=\"button\" id=\"addURL\" name=\"addURL\" title=\"Add Web Site to My Library\" onclick=\"AddFavorite()\">Add To My Library</button>     <button type=\"button\" id=\"cancelFavorite\" name=\"cancelFavorite\" title=\"Cancel\" onclick=\"CancelFavorite()\">Cancel</button>";
  137.     //Second Cell
  138.     AddCellToRow(row,keys,values);
  139.     
  140.     
  141. }
  142.  
  143. function CancelFavorite()
  144. {
  145.     ShowMyLibrary(0);
  146. }
  147.  
  148. // Alerts User if the site getting added is already present 
  149. function CheckNotDouble(sUrl)
  150. {
  151.     var count = document.mysiteList.sitecount.value;
  152.     var siteurllist = document.mysiteList.siteurl;
  153.  
  154.     if(count==1)
  155.     {
  156.         if(siteurllist.value.indexOf(sUrl)!=-1)
  157.             return confirm("The site is already present in your list. Do you still want to add it?");        
  158.     }
  159.     else
  160.     {
  161.         for(i=0;i<count;i++)
  162.         {
  163.             if(siteurllist[i].value.indexOf(sUrl)!=-1)
  164.                 return confirm("The site is already present in your list. Do you still want to add it?");        
  165.         }
  166.     }
  167.     return true;
  168. }
  169.  
  170. function checkSupportExtensions()
  171. {
  172.     var Url = document.getElementById('favoriteUrl');
  173.     var sUrl = Url.value;
  174.     var trimUrl = trim(sUrl);
  175.     
  176.     var parts = trimUrl.split('.');
  177.     if(parts.length <= 1)
  178.         return true;
  179.                 
  180.     var ext = parts[parts.length-1];    
  181.     ext = ext.toLowerCase();
  182.     if((ext == "jpg") || (ext == "png") || (ext == "jpeg") 
  183.         || (ext == "gif") || (ext == "exe") || (ext == "pdf")
  184.         || (ext == "ps") 
  185.         || (ext == "avi") || (ext == "mp3") || (ext == "dat")
  186.         || (ext == "dll") || (ext == "doc") || (ext == "gz")
  187.         || (ext == "image") || (ext == "rtf") || (ext == "tgz")
  188.         || (ext == "tar") || (ext == "zip")
  189.        )
  190.        return false;
  191.      
  192.      return true;
  193. }
  194.  
  195. function validateSiteName()
  196. {
  197.     // Check site name is given, if not given then put url as name
  198.     var siteName = document.getElementById('favoriteName');
  199.     var trimSiteName = trim(siteName.value);
  200.     if(trimSiteName=="")
  201.         return false;
  202.     //    validate the site url here
  203.     regularexp=/[^\w\.\s]/; // Check for special character here. Dots are allowed.
  204.     if (regularexp.test(trimSiteName)) 
  205.     {
  206.         return false;
  207.     }
  208.     else
  209.     {
  210.         return true;
  211.     }
  212. }
  213.  
  214.  
  215. function validatesURL(sUrl)
  216. {
  217.     //    validate the site url here
  218.     httpregex=/^(http:[\/\/,\\\\])/;
  219.     regularexp = /^[^\.]+[\.]{1}[^\.]*[\.]?.+$/;
  220.     
  221.     if(sUrl.indexOf("http:\\")==0)
  222.     {
  223.         // replace \\ with //
  224.         sUrl = sUrl.replace("http:\\\\", "http://");
  225.         var favoriteForm = document.favoriteForm;
  226.         favoriteForm.favoriteUrl.value = sUrl;
  227.     }
  228.     
  229.     if(sUrl.indexOf("http://")!=0)
  230.     {
  231.         sUrl ="http://" + sUrl;
  232.         var favoriteForm = document.favoriteForm;
  233.         favoriteForm.favoriteUrl.value = sUrl;
  234.     }
  235.     // break the initial http://
  236.     var urlField = sUrl.substr(7,sUrl.length-7);
  237.     // This would get the "www.ac.com" portion of the url
  238.     // if original url is say www.ac.com/~dko
  239.     var mainUrlField = urlField.indexOf("/");
  240.     if(mainUrlField!=-1)
  241.     {
  242.         urlField = urlField.substr(0,mainUrlField);
  243.     }
  244.     if(httpregex.test(sUrl)&®ularexp.test(urlField)) 
  245.     {
  246.         return true;
  247.     }
  248.     return false;
  249. }
  250.  
  251. function ValidateURLField()
  252. {
  253.     var Url = document.getElementById('favoriteUrl');
  254.     var sUrl = Url.value;
  255.     var trimUrl = trim(sUrl);
  256.     return validatesURL(trimUrl);
  257. }
  258.  
  259. function AddFavorite()
  260. {
  261.     var status = "";
  262.  
  263.     if(checkSupportExtensions())
  264.     {
  265.         if(validateSiteName())
  266.         {
  267.             if(ValidateURLField())
  268.             {
  269.                 var sitesXml = CreateSitesXml();
  270.                 var url = "/webaroo/e29f1fe6/savemysubs?request=add";
  271.                 sendXMLData(url, "XMLData=" + sitesXml);
  272.             
  273.                 var siteAddStatus = GetOperationStatus(xmlContent);
  274.                 status = siteAddStatus;
  275.                 ClearFavoriteForm();        
  276.             }
  277.             else    // i18n issue
  278.                 status = "Please enter a valid URL.";            
  279.         }
  280.         else    // i18n issue
  281.             status = "Please enter a name shorter than 20 alphanumeric characters.";
  282.     }
  283.     else    // i18n issue
  284.         status = "Entered URL type is not supported. Refer to Web Site FAQs for details.";        
  285.     
  286.     SetOperationStatus('favoriteBanner', status);
  287. }
  288.  
  289. function CreateSitesXml()
  290. {
  291.     var favoriteForm = document.favoriteForm;
  292.     var selectedIndex = favoriteForm.linkDepth.selectedIndex;
  293.     
  294.     var sitesXml = '<XmlData>\n';
  295.     //sitesXml += '<storeID>' + storeID + '</storeID>\n';
  296.     sitesXml += '<Response>\n';
  297.     sitesXml += '<Favorites>\n';
  298.     sitesXml += '<Favorite>\n';
  299.     
  300.     var encodedSiteName = '<![CDATA[' + escape(favoriteForm.favoriteName.value) + ']]>';
  301.     sitesXml += '<SiteName>' + encodedSiteName + '</SiteName>\n';
  302.     // Needs to encode the SiteURL before passing
  303.     var encodedSiteURL = '<![CDATA[' + doubleUrlEncode(favoriteForm.favoriteUrl.value)+ ']]>';
  304.     sitesXml += '<SiteURL>' + encodedSiteURL + '</SiteURL>\n';
  305.     sitesXml += '<SiteLinkLevel>' + favoriteForm.linkDepth.options[selectedIndex].value + '</SiteLinkLevel>\n';
  306.     
  307.     if(favoriteForm.images[0].checked)
  308.         sitesXml += '<ImageCopyFlag>0</ImageCopyFlag>\n';
  309.     else
  310.         sitesXml += '<ImageCopyFlag>1</ImageCopyFlag>\n';
  311.     
  312.     if(favoriteForm.domainFilter[0].checked)        
  313.         sitesXml += '<DomainFilterFlag>0</DomainFilterFlag>\n';
  314.     else
  315.         sitesXml += '<DomainFilterFlag>1</DomainFilterFlag>\n';
  316.         
  317.     sitesXml += '</Favorite>\n';
  318.     sitesXml += '</Favorites>\n';
  319.     sitesXml += '</Response>\n';
  320.     sitesXml += '</XmlData>\n';
  321.  
  322.     return sitesXml;
  323. }
  324.  
  325. function ClearFavoriteForm()
  326. {
  327.     var favoriteForm = document.favoriteForm;
  328.     favoriteForm.favoriteName.value = "";
  329.     favoriteForm.favoriteUrl.value = "";
  330.     // Also Set the Link Depth back to 0
  331.     favoriteForm.linkDepth.selectedIndex = 0;
  332.     // Also set the default option for Image and Filter
  333.     favoriteForm.images[0].checked = true;
  334.     favoriteForm.domainFilter[0].checked = true;
  335.     favoriteForm.domainFilter[0].disabled = true;
  336.     favoriteForm.domainFilter[1].disabled = true;    
  337. }
  338.  
  339. function LinkDepthChange()
  340. {
  341.     var favoriteForm = document.favoriteForm;
  342.     var selectedIndex = favoriteForm.linkDepth.selectedIndex;
  343.     if(selectedIndex)
  344.     {
  345.         // enable them now
  346.         favoriteForm.domainFilter[0].disabled = false;
  347.         favoriteForm.domainFilter[1].disabled = false;
  348.     }
  349.     else
  350.     {
  351.         favoriteForm.domainFilter[0].disabled = true;
  352.         favoriteForm.domainFilter[1].disabled = true;
  353.     }    
  354. }
  355.