        var cc=0;
        var feedImage="";
        var keywords="find rss feeds fast, findrss.net";

         function changeTitle(text)
         {
             if (document.title.indexOf(" - ") > -1)
             {
                document.title = document.title.substring(0,document.title.indexOf(" - ")) + " - " + text;
             }
             else
             {
                document.title = document.title + " - " + text;
             }

         }
         function attach_file( p_script_url )
         {
            // create new script element, set its relative URL, and load it
            script = document.createElement( 'script' );
            script.src = p_script_url;
            document.getElementsByTagName( 'head' )[0].appendChild( script );
         }
         function setCookie(cookieName,cookieValue,nDays)
         {
                  var today = new Date();
                  var expire = new Date();
                  if (nDays==null || nDays==0) nDays=1;
                  expire.setTime(today.getTime() + 3600000*24*nDays);
                  document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
         function setDefaultFeed(id)
         {
             setCookie('default',id,90);
             alert("We've set the current feed as your favorite.");
         }

         function set()
         {

          if (location.href.indexOf("?query=") > -1)
          {
            var q = location.href.substring(location.href.indexOf("?query=")+7);
            document.getElementById('PREVIEW').innerHTML="<HR>";
            attach_file("find.php?query=" + escape(q));
            //attach_file('search.php');
            //document.getElementById('query').value=q;
          }

          if (location.href.indexOf("?unid=") > -1)
          {
             var unid = location.href.substring(location.href.indexOf("?unid=")+6);
             if (unid.indexOf("?") > -1) unid=unid.substring(0,unid.indexOf("?"));
             if (unid.indexOf("!") > -1) unid=unid.substring(0,unid.indexOf("!"));
             if (unid.indexOf("/") > -1) unid=unid.substring(0,unid.indexOf("/"));
             attach_file('showFeedByUNID.php?unid=' + unid);
          }

          if (location.href.indexOf("?id=") > -1)
          {
             var unid = location.href.substring(location.href.indexOf("?id=")+4);
             if (unid.indexOf("?") > -1) unid=unid.substring(0,unid.indexOf("?"));
             if (unid.indexOf("?") > -1) unid=unid.substring(0,unid.indexOf("?"));
             if (unid.indexOf("/") > -1) unid=unid.substring(0,unid.indexOf("/"));
             attach_file('showFeed.php?id=' + unid);
          }
          else
          {

          if (location.href.indexOf("?") > -1)
          {
             var redirect = location.href.substring(location.href.indexOf("?")+1);
             if (redirect.indexOf("#") > -1) redirect=redirect.substring(0,redirect.length-1);
             attach_file(redirect + ".php");
          }
          else
          {

             //attach_file('frontpage.php');
             attach_file('showFeed.php?id=0');
          }

          }
         }
         function resetFrontPage()
         {
             attach_file('frontpage.php');
         }
         function home()
         {
             //attach_file('frontpage.php');
             //attach_file('showFeed.php?id=0');
             location.reload();
         }
         function reset()
         {
             attach_file('search.php');
         }
         function help()
         {
             attach_file('help.php');
         }
         function advertise()
         {
             attach_file('advertise.php');
         }
         function submit()
         {
             attach_file('submit.php');
         }
         function showCat(what,category)
         {
            attach_file("showcats.php?cat=" + escape(what) + "&in=" + escape(category));
         }

         function srch()
         {
             attach_file('search.php');
         }
         function tools()
         {
             attach_file('tools.php');
         }
         function feedSearch()
         {
            var q=document.getElementById('query').value;
            attach_file("find.php?query=" + escape(q));
            document.getElementById("SEARCHMESSAGE").innerHTML="";
         }
         function contact()
         {
             attach_file('contact.php');
         }
         function about()
         {
             attach_file('about.php');
         }
         function legal()
         {
             attach_file('legal.php');
         }
         function ourFeed()
         {
             attach_file('showFeed.php?id=35855');
         }
         function send()
         {
             attach_file('feedback.php');
         }

         function checkButton(e)
         {
           document.getElementById("SEARCHMESSAGE").innerHTML="";
           var keycode;
           if (window.event)
              keycode = window.event.keyCode;
           else
              if (e) keycode = e.which;
           if (keycode == 13) feedSearch();
         }

         function updateSubCats(cat1,field)
         {
             var c=cats2.split("§");
             catz="<OPTION>Choose a sub-category<OPTION>";
             comp=cat1 + "::";
             for (var i=0; i < c.length; i++)
             {
                if (c[i].indexOf(comp) == 0) catz = catz + c[i].substring(c[i].indexOf("::")+2);
             }

             document.getElementById(field).innerHTML=catz;
         }
         
         function previewImage(img)
         {
         	var prev = document.getElementById("IMAGEPREVIEW");
         	if (img.indexOf(".gif") > -1 || img.indexOf(".jp") > -1 || img.indexOf(".png") > -1)
         	{
         	   prev.innerHTML="<IMG BORDER=0 SRC='" + img + "' >";
         	}
         	else
         	{
         	   prev.innerHTML="";
                }
         }

         function checkImageURL(img)
         {
         	if (img != "" && (img.toLowerCase().indexOf(".xml") > -1  || img.toLowerCase() .indexOf(".rss") > -1))
         	{
         	   alert("Please supply a valid IMAGE reference - NO FEEDS");
         	   img="";
         	}
         	if (img != "" && img.toLowerCase().indexOf(".gif") == -1  && img.toLowerCase().indexOf(".jp") == -1 && img.toLowerCase().indexOf(".png") == -1)
         	{
         	   alert("Images must be JPG, JPEG, GIF or PNG only sorry");
         	   img="";
         	}
         }

/**
*
* Secure Hash Algorithm (SHA1)
* http://www.webtoolkit.info/
*
**/

function SHA1 (msg) {

    function rotate_left(n,s) {
        var t4 = ( n<<s ) | (n>>>(32-s));
        return t4;
    };

    function lsb_hex(val) {
        var str="";
        var i;
        var vh;
        var vl;

        for( i=0; i<=6; i+=2 ) {
            vh = (val>>>(i*4+4))&0x0f;
            vl = (val>>>(i*4))&0x0f;
            str += vh.toString(16) + vl.toString(16);
        }
        return str;
    };

    function cvt_hex(val) {
        var str="";
        var i;
        var v;

        for( i=7; i>=0; i-- ) {
            v = (val>>>(i*4))&0x0f;
            str += v.toString(16);
        }
        return str;
    };


    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    };

    var blockstart;
    var i, j;
    var W = new Array(80);
    var H0 = 0x67452301;
    var H1 = 0xEFCDAB89;
    var H2 = 0x98BADCFE;
    var H3 = 0x10325476;
    var H4 = 0xC3D2E1F0;
    var A, B, C, D, E;
    var temp;

    msg = Utf8Encode(msg);

    var msg_len = msg.length;

    var word_array = new Array();
    for( i=0; i<msg_len-3; i+=4 ) {
        j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
        msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
        word_array.push( j );
    }

    switch( msg_len % 4 ) {
        case 0:
            i = 0x080000000;
        break;
        case 1:
            i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
        break;

        case 2:
            i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
        break;

        case 3:
            i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8    | 0x80;
        break;
    }

    word_array.push( i );

    while( (word_array.length % 16) != 14 ) word_array.push( 0 );

    word_array.push( msg_len>>>29 );
    word_array.push( (msg_len<<3)&0x0ffffffff );


    for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {

        for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
        for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

        A = H0;
        B = H1;
        C = H2;
        D = H3;
        E = H4;

        for( i= 0; i<=19; i++ ) {
            temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);
            B = A;
            A = temp;
        }

        for( i=20; i<=39; i++ ) {
            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);
            B = A;
            A = temp;
        }

        for( i=40; i<=59; i++ ) {
            temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);
            B = A;
            A = temp;
        }

        for( i=60; i<=79; i++ ) {
            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);
            B = A;
            A = temp;
        }

        H0 = (H0 + A) & 0x0ffffffff;
        H1 = (H1 + B) & 0x0ffffffff;
        H2 = (H2 + C) & 0x0ffffffff;
        H3 = (H3 + D) & 0x0ffffffff;
        H4 = (H4 + E) & 0x0ffffffff;

    }

    var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

    return temp.toLowerCase();

}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


       function getSelectionValue(id)
       {
       	  var dropdownIndex = document.getElementById(id).selectedIndex;
          return(document.getElementById(id).options[dropdownIndex].text);

       }

         function validateSubmission()
         {
           //Check the field values first
           var warn=false;
           var URL=document.getElementById("url");
           if (URL.value =="" || URL.value == "http://" || URL.value == "https://")
           {
               warn=true;
               URL.style.border="2px solid rgb(255,140,0)";
               alert("URL is a required field. Enter a valid feed URL.  It should point to your feed, not your website and should start with HTTP:// or HTTPS://");
               URL.focus();
               return;

           }
           if ((URL.value.indexOf("http://") == -1 && URL.value.indexOf("https://")) || URL.value.indexOf("://") == -1 || URL.value.indexOf(".") == -1)
           {
               warn=true;
               URL.style.border="2px solid red";
               alert("Please ensure that you enter a valid URL. It should point to your feed, not your website and should start with HTTP:// or HTTPS://");
               URL.focus();
               return;
           }
           URL.style.border="1px solid rgb(190,190,190)";

           var NAME=document.getElementById("name");
           if (NAME.value.trim() =="" )
           {
               warn=true;
               NAME.style.border="2px solid rgb(255,140,0)";
               alert("Feed name is a required field. Please enter the short name of the feed, i.e. MyBlog.com or Racing Feed.");
               NAME.focus();
               return;

           }
           NAME.style.border="1px solid rgb(190,190,190)";

           var BRIEF=document.getElementById("shortDescription");
           if (BRIEF.value.trim() =="" )
           {
               warn=true;
               BRIEF.style.border="2px solid rgb(255,140,0)";
               alert("Description is a required field. Please enter a brief paragraph to describe the feed.");
               BRIEF.focus();
               return;

           }
           BRIEF.style.border="1px solid rgb(190,190,190)";

           var EMAIL=document.getElementById("emailaddress");
           if (EMAIL.value.trim() =="" )
           {
               warn=true;
               EMAIL.style.border="2px solid rgb(255,140,0)";
               alert("E-mail address is a required field. Please enter a valid e-mail address.  You will be required to confirm this submission by clicking in a link we sent to this address.");
               EMAIL.focus();
               return;

           }
           EMAIL.style.border="1px solid rgb(190,190,190)";
	    if (validateEmailAddress('emailaddress') == false) return; 

           var TYPE=document.getElementById("feedType");
           var TYPE_VALUE=TYPE.options[TYPE.selectedIndex].text;
           if (TYPE_VALUE == "Select a feed type" )
           {
               warn=true;
               TYPE.style.border="2px solid rgb(255,140,0)";
               alert("Type is a required field. Please choose one of the available feed types.");
               TYPE.focus();
               return;

           }
           TYPE.style.border="1px solid rgb(190,190,190)";

           var CAT1=document.getElementById("category");
           var CAT1dsp=document.getElementById("categoryDisplay");
           if (CAT1.value.trim() =="" )
           {
               warn=true;
               CAT1dsp.style.border="2px solid rgb(255,140,0)";
               alert("Main category is a required field. Please choose a main category.");
               CAT1.focus();
               return;

           }
           CAT1dsp.style.border="1px solid rgb(190,190,190)";

           var CAT2=document.getElementById("subcategory");
           var CAT2dsp=document.getElementById("subcategoryDisplay");
           if (CAT2.value.trim() =="" )
           {
               warn=true;
               CAT2dsp.style.border="2px solid rgb(255,140,0)";
               alert("Sub-category is a required field. Please choose a sub-category.");
               CAT2.focus();
               return;

           }
           CAT2dsp.style.border="1px solid rgb(190,190,190)";


           //Check the question
           if (SHA1(getSelectionValue('CHOICES0') + document.getElementById("ID").value)==document.getElementById("SIGNATURE").value)
             return(true);
           else
           {
             cc++;
             if (cc > 2)
             {
               alert("Sorry. Try completing the form again.");
               location.href="index.html?submit";
             }
             else
             {
               alert("Sorry, the answer to the question is incorrect. Please try again.");
               return(false);
             }
           }
         }

         function validateContact()
         {
           //Check the question
           if (SHA1(getSelectionValue('CHOICES0') + document.getElementById("ID").value)==document.getElementById("SIGNATURE").value)
             return(true);
           else
           {
             cc++;
             if (cc > 2)
             {
               alert("Sorry. Try completing the form again.");
               location.href="index.html?contact";
             }
             else
             {
               alert("Sorry, the answer to the question is incorrect. Please try again.");
               return(false);
             }
           }
         }



         function warnAboutMaincat()
         {
           var CAT1=document.getElementById("category");
           var CAT1dsp=document.getElementById("categoryDisplay");
           if (CAT1.value.trim() == "Business & Finance" )
           {
               alert("Warning for category: Business & Finance - If your feed is NOT a valid Business feed, not related to finance or the stock market or if the feed is related to internet marketing of any kind it will be removed without further consideration.  Choose 'Commercial' if in doubt!");
               return;
           }
         }
         
         
         function addFavorite(id)
         {
            var favs = readCookie('findrssFavorites');
            if (favs == null) favs="";
            if (favs.indexOf(id) == -1)
            {
              createCookie('findrssFavorites',favs + "," + id,999);
              alert("Added.  The screen will refresh and this feed will be available in the pull-down menu at the top of the screen for quick access.");
              location.reload();
            }
         }
         function removeFavorite(id)
         {
            var favs = readCookie('findrssFavorites');
            favs = favs.replace("," + id,"");
            if (favs == ",") favs="";
            createCookie('findrssFavorites',favs,999);
            alert("Removed from your favorites.");
            location.reload();
         }

         function createCookie(name,value,days)
         {
            if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
         }

         function readCookie(name) 
         {
	  var nameEQ = name + "=";
	  var ca = document.cookie.split(';');
	  for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
          }
	  return null;
        }

        function eraseCookie(name)
        {
	         createCookie(name,"",-1);
        }

	function validateEmailAddress(field)
	{
           var field=document.getElementById(field);		
		var str=field.value;
   	       if (str == "") return true;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid e-mail address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid e-mail address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Please enter a valid e-mail address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Please enter a valid e-mail address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Please enter a valid e-mail address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Please enter a valid e-mail address")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		   alert("Please enter a valid e-mail address")
		    return false
		 }

 		 return true
	}


function makePreviewTitle()
{
  //makes the 'preview submission' title tag that the preview box uses
  var v=document.getElementsByName('subpreview')[0];
  var i=document.getElementById('image').value;
  var n=document.getElementById('name').value;
  var d=document.getElementById('shortDescription').value;
  var c=document.getElementById('category').value;
  var sc=document.getElementById('subcategory').value;
  //image name desk
  var t="";
  if (i == "")
  {
    t = n + "<BR><BR>" + d + "<BR><BR>" + c + "&nbsp;/&nbsp;" + sc;
  }
  else
  {
    t = "<IMG SRC='" + i + "' BORDER=0>" + "<BR><BR>" + n + "<BR><BR>" + d + "<BR><BR>" + c + "&nbsp;/&nbsp;" + sc;
  }

  v.title=t;
}




        this.imagePreview = function(){
	/* CONFIG */

		xOffset = 5;
		yOffset = 10;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.fpreview").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='fpreview'><img style='max-width: 200px; overflow:hidden;' src='"+ this.id +"' alt='' />"+ c +"</p>");
		$("#fpreview")
			.css("top",(e.pageY - 100 - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");
    },
	function(){
		this.title = this.t;
		$("#fpreview").remove();
    });
	$("a.fpreview").mousemove(function(e){
		$("#fpreview")
			.css("top",(e.pageY - 100 - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

