//
// "Internal" function to return the decoded value of a cookie
//

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//

function GetCookie (name) {
  /*
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;

  while (i < clen) {
    var j = i + alen;

    if (document.cookie.substring(i, j) == arg)
      return getCookieVal(j);

    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }

  return "";
  */

  // first we'll split this cookie up into name/value pairs
  // note: document.cookie only returns name=value, not the other components
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false; // set boolean t/f default f

  for ( i = 0; i < a_all_cookies.length; i++ )
  {
    // now we'll split apart each name=value pair
    a_temp_cookie = a_all_cookies[i].split( '=' );

    // and trim left/right whitespace while we're at it
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

    // if the extracted name matches passed name
    if (cookie_name == name)
    {
      b_cookie_found = true;
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if ( a_temp_cookie.length > 1 )
      {
        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      // note that in cases where cookie is initialized but no value, null is returned
      return cookie_value;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if (!b_cookie_found)
  {
    return "";
  }
}


//
//  Function to create or update a cookie.
//
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//

function SetCookie (name, value, expires, path, domain, secure) {

  document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") 
                    + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") 
                    + ((secure) ? "; secure" : "");

}



//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//

function DeleteCookie (name, path, domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}

function detectCookieSetting()
{
  var random_num = Math.floor(Math.random() * 1000000);

  SetCookie("cb", escape(random_num), null, "/");

  var cookieData = GetCookie("cb");

  if (cookieData == escape(random_num)) {
    return "true";
  } else {
    return "false";
  }
}

function formatDate(number) {
  var result;

  if (number < 10) {
    result = "0" + number;
  } else {
    result = number;
  }
  
  return result;
}

function getDateStr() {
  var today = new Date();
  var year = formatDate(today.getYear() % 100);
  var month = formatDate(today.getMonth() + 1);
  var date = formatDate(today.getDate());

  var todayStr = month + "." + date + "." + year;

  return todayStr;
}

function formatDateAlphabet(number) {
    var result;
    var chars = "0ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567";

    result = chars.charAt(number % 60);

    return result;
}

function getCurrentDate() {
  var today = new Date();
  var year = today.getYear();
  var month = today.getMonth() + 1;
  var date = today.getDate();

  if (month < 10) {
    month = '0' + month;
  }

  if (date < 10) {
    date = '0' + date;
  }

  var todayStr = year + '-' + month + "-" + date;

  return todayStr;
}

function ValidateSearchForm(theForm)
{
  var text = theForm.search.value;

  // alert (text);

  if (text == "" || text.substring(0, 18) == "Type your keywords") {
    alert("Please enter your search keywords before performing a search.");
    return false;
  } else {
    return true;
  }
}

function view(link)
{
  var newWindow;

  var width = 800;
  var height = 600;

  if (window.screen.width >= 1400) {
    width = 1280;
    height = 1024;
  } else if (window.screen.width >= 1152) {
    width = 1024;
    height = 768;
  }

  var winleft = (window.screen.width - width) / 2;
  var wintop = 0;
  if (window.screen.height > (height + 140)) {
    wintop = (window.screen.height - height - 140) / 2;
  }

  var windowProperties = 'width=' + width + ',height=' + height + ',top=' + wintop + ',left=' + winleft + ',directories=no,location=yes,menubar=yes,personalbar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes';

  newWindow = window.open(link, 'vw', windowProperties);

  newWindow.focus();

  return false;
}

function show(link, windowname, subid, params)
{
  if (!window.focus)
    return true;

  var keyword;
  var offerType = "default";
  var href;
  var dataType;

  keyword = windowname;

  var inSubid = subid;
  if (subid == "0" || escape(subid) == "undefined") {
    subid = getTid();
  }

  if (escape(params) == "undefined" || params.length < 3) {
    params = GetCookie("params");
  }

  var bankName = GetBankName(keyword);
  if (bankName == "citi" || bankName == "amex") {
    var cookieEnabled = detectCookieSetting();
    if (cookieEnabled == "true") {
      if (GetCid(keyword) == null) {
        SetCid(keyword, subid);
      }
    }
  }

  if (escape(params) == "undefined" || params.length < 3) {
    if (inSubid == "0" || escape(inSubid) == "undefined") {
      var queryStr = "offer=" + windowname + "&tid=" + subid;
      document.click.src="/php/stats/click.php?" + queryStr;
    }
  }

  var newWindow;

  var width = 800;
  var height = 600;

  if (window.screen.width >= 1400) {
    width = 1280;
    height = 1024;
  } else if (window.screen.width >= 1152) {
    width = 1024;
    height = 768;
  }

  var winleft = (window.screen.width - width) / 2;
  var wintop = 0;
  if (window.screen.height > (height + 140)) {
    wintop = (window.screen.height - height - 140) / 2;
  }

  var windowProperties = 'width=' + width + ',height=' + height + ',top=' + wintop + ',left=' + winleft + ',directories=no,location=yes,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes';

  if (escape(params) == "undefined" || params.length < 3) {
    href = 'http://cardbenefit.com/php/offer.php?offer=' + windowname + '&subid=' + subid;
  } else {
    href = 'http://cardbenefit.com/php/offer.php?offer=' + windowname + '&subid=' + subid + '&' + params;
  }

  newWindow = window.open(href, windowname, windowProperties);

  newWindow.focus();

  return false;
}

function GetBankName(keyword)
{
  var bankName = "";

  var citicards = "CFW,CFS,CPP,MTV,CPS";
  var amexcards = "BGC,SPG,PRW,SPB,DSB,BGR,JBB,TEB,TEC,PDS,DRC,PLC,PRC";
  
  if (citicards.indexOf(keyword) >= 0) {
    bankName = "citi";
  } else if (amexcards.indexOf(keyword) >= 0) {
    bankName = "amex";
  }

  return bankName;
}

function SetCid(keyword, subid)
{
  var days = 0;

  if (GetBankName(keyword) == "citi") {
    days = 30;    
  } else if (GetBankName(keyword) == "amex") {
    days = 90;
  } else if (GetBankName(keyword) == "usbank") {
    days = 1;
  }

  var expdate = new Date();
  expdate.setTime(expdate.getTime() + (days * 24 * 60 * 60 * 1000)); 

  SetCookie(keyword, subid, expdate, "/");
}

function GetCid(keyword)
{
  var subid = GetCookie(keyword);
  return subid;
}

function popup(link)
{
  if (!window.focus)
    return true;

  var href;

  href = link.href;

  var newWindow;
  newWindow = window.open(href, 'rewards', 'width=800,height=600,directories=no,location=yes,menubar=yes,personalbar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes');

  newWindow.focus();

  return false;
}

function displayAd(link)
{
  if (!window.focus)
    return true;

  var href;

  href = link.href;

  var newWindow;
  newWindow = window.open(href, 'advertisement', 'width=800,height=600,directories=no,location=yes,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes');

  newWindow.focus();

  return false;
}

function validate()
{ 
  if ((document.guestform.realname.value=="") || (document.guestform.email.value=="")) {
    return false;
  } else {
    return true;
  }
}

function getTid()
{
  var today = new Date();

  var month = formatDateAlphabet(today.getMonth() + 1);
  var date = formatDateAlphabet(today.getDate());
  var zone = getTimeZoneSymbol();

  var hour = formatDateAlphabet(today.getHours());
  var minute = formatDateAlphabet(today.getMinutes());
  var second = formatDateAlphabet(today.getSeconds());

  var random_num = Math.floor(Math.random() * 1000);
  while (random_num % 100 == 0) {
	random_num = Math.floor(Math.random() * 1000);
  }

  var text;

  if (random_num < 10) {
    text = month + date + zone + hour + minute + second + "00" + random_num;
  } else if (random_num < 100) {
    text = month + date + zone + hour + minute + second + "0" + random_num;
  } else {
    text = month + date + zone + hour + minute + second + random_num;
  }

  return text;
}

function getTimeZoneSymbol()
{
  var timezone;
  // var daylightSummertime = 1;
  var daylightSummertime = 0;
  var d = new Date();
  var gmtHours = d.getTimezoneOffset() / 60;
  var chars = "FUVYJBNLKSORGZDQTECMPAHIW";

  gmtHours = gmtHours + daylightSummertime;
  
  if (gmtHours > 12 || gmtHours < -12) {
    timezone = "X";
  } else if (escape(gmtHours + 12).length > 2) {
    timezone = "X";
  } else {
    timezone = chars.charAt(gmtHours + 12);
  }

  // gmtHours:
  // 0: Greenwich; 1: Azores; 2: MidAtlantic; 3: Greenland; 4: Atlantic
  // 5: EST; 6: CST; 7: MST; 8: PST; 9: Alaska
  // 10: Hawaii; 11: MidwayIsland; 12: Eniwetok; -1: Paris; -2: Cairo
  // -3: Moscow; -4: Baku; -5: Islamabad; -6: Astana; -7: Bangkok
  // -8: Beijing; -9: Tokyo; -10: Sydney; -11: SolomonIsland; -12: Fiji
  
  return timezone;
}

function detectDaylightSavings()
{
    // var Date1 = new Date();
    // Date1.setFullYear(2007, 2, 11);
    // Date1.setHours(2, 0, 0, 0);

    // var Date2 = new Date();
    // Date2.setFullYear(2007, 10, 4);
    // Date2.setHours(2, 0, 0, 0);

    var Date3 = new Date();
    Date3.setFullYear(2008, 2, 9);
    Date3.setHours(2, 0, 0, 0);

    var Date4 = new Date();
    Date4.setFullYear(2008, 10, 2);
    Date4.setHours(2, 0, 0, 0);

    var Date5 = new Date();
    Date5.setFullYear(2009, 2, 8);
    Date5.setHours(2, 0, 0, 0);

    var Date6 = new Date();
    Date6.setFullYear(2009, 10, 1);
    Date6.setHours(2, 0, 0, 0);

    var Date7 = new Date();
    Date7.setFullYear(2010, 2, 14);
    Date7.setHours(2, 0, 0, 0);

    var Date8 = new Date();
    Date8.setFullYear(2010, 10, 7);
    Date8.setHours(2, 0, 0, 0);

    var today = new Date();
    if (today >= Date3 && today < Date4) {
        return 1;
    } else if (today >= Date4 && today < Date5) {
        return 0;
    } else if (today >= Date5 && today < Date6) {
        return 1;
    } else if (today >= Date6 && today < Date7) {
        return 0;
    } else if (today >= Date7 && today < Date8) {
        return 1;
    } else if (today >= Date8 || today < Date3) {
        return detectGenericDaylightSavings();
    }
}

function detectGenericDaylightSavings()
{
    var testDate1 = new Date(2007, 0, 1, 10, 30, 00, 1);
    var dateDiff1 = (testDate1.getHours() - testDate1.getUTCHours());

    var testDate2 = new Date();
    var dateDiff2 = (testDate2.getHours() - testDate2.getUTCHours());

    if (dateDiff1 + 1 == dateDiff2) {
        return 1;
    } else {
        return 0;
    }
}

function getTimeZone() {
  var assoc = [];
  assoc[801] = "Pacific Time";
  assoc[501] = "Eastern time";
  assoc[601] = "Central Time";
  assoc[701] = "Mountain Time";
  assoc[1000] = "Hawaii";
  assoc[700] = "Arizona";
  assoc[901] = "Alaska";
  assoc[500] = "Indiana, Bogota, Lima, Quito, Rio Branco";
  assoc[401] = "Atlantic time";
  assoc[10800] = "Beijing, Hong Kong, Singapore, Taipei";
  assoc[1200] = "International Date Line West";
  assoc[1100] = "Midway Island, Samoa";
  assoc[600] = "Central America, Saskatchewan";
  assoc[400] = "Caracas, La Paz";
  assoc[331] = "Newfoundland";
  assoc[301] = "Greenland, Brasilia, Montevideo";
  assoc[300] = "Buenos Aires, Georgetown";
  assoc[201] = "Mid-Atlantic";
  assoc[101] = "Azores";
  assoc[100] = "Cape Verde Is.";
  assoc[0] = "Casablanca, Monrovia, Reykjavik";
  assoc[1] = "GMT: Dublin, Edinburgh, Lisbon, London";
  assoc[10101] = "Amsterdam, Berlin, Rome, Vienna, Prague, Brussels";
  assoc[10100] = "West Central Africa";
  assoc[10201] = "Amman, Athens, Istanbul, Beirut, Cairo, Jerusalem";
  assoc[10200] = "Harare, Pretoria";
  assoc[10301] = "Baghdad, Moscow, St. Petersburg, Volgograd";
  assoc[10300] = "Kuwait, Riyadh, Nairobi, Tbilisi";
  assoc[10330] = "Tehran";
  assoc[10400] = "Abu Dhadi, Muscat";
  assoc[10401] = "Baku, Yerevan";
  assoc[10430] = "Kabul";
  assoc[10501] = "Ekaterinburg";
  assoc[10500] = "Islamabad, Karachi, Tashkent";
  assoc[10530] = "Chennai, Kolkata, Mumbai, New Delhi, Sri Jayawardenepura";
  assoc[10545] = "Kathmandu";
  assoc[10600] = "Astana, Dhaka";
  assoc[10601] = "Almaty, Nonosibirsk";
  assoc[10630] = "Yangon (Rangoon)";
  assoc[10701] = "Krasnoyarsk";
  assoc[10700] = "Bangkok, Hanoi, Jakarta";
  assoc[10801] = "Irkutsk, Ulaan Bataar, Perth";
  assoc[10901] = "Yakutsk";
  assoc[10900] = "Seoul, Osaka, Sapporo, Tokyo";
  assoc[10930] = "Darwin";
  assoc[10931] = "Adelaide";
  assoc[11000] = "Brisbane, Guam, Port Moresby";
  assoc[11001] = "Canberra, Melbourne, Sydney, Hobart, Vladivostok";
  assoc[11100] = "Magadan, Solomon Is., New Caledonia";
  assoc[11201] = "Auckland, Wellington";
  assoc[11200] = "Fiji, Kamchatka, Marshall Is.";
  assoc[11300] = "Nuku alofa";  

  var rightNow = new Date();
  var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
  var june1 = new Date(rightNow.getFullYear(), 5, 1, 0, 0, 0, 0); // june 1st
  var temp = jan1.toGMTString();
  var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
  temp = june1.toGMTString();
  var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
  var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
  var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
  var dst;
  if (std_time_offset == daylight_time_offset) {
    dst = 0; // daylight savings time is NOT observed
  } else {
    // positive is southern, negative is northern hemisphere
    var hemisphere = std_time_offset - daylight_time_offset;
    if (hemisphere >= 0)
      std_time_offset = daylight_time_offset;
    dst = 1; // daylight savings time is observed
  }
  
  var timezone;
  var timezoneIndex = convert(std_time_offset) + dst;

  timezone = assoc[timezoneIndex];
  return timezone;
}

function calculate_time_zone() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 5, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	var i;
	// check just to avoid error messages
	if (document.getElementById('timezone')) {
		for (i = 0; i < document.getElementById('timezone').options.length; i++) {
			if (document.getElementById('timezone').options[i].value == convert(std_time_offset)+","+dst) {
				document.getElementById('timezone').selectedIndex = i;
				break;
			}
		}
	}
}

function convert(value) {
  var hours = parseInt(value);
  value -= parseInt(value);
  value *= 60;
  var mins = parseInt(value);
  
  // value -= parseInt(value);
  // value *= 60;
  // var secs = parseInt(value);
  
  var returnVal;
  if (hours > 0) {
    returnVal = 10000 + hours * 100 + mins;
  } else {
    returnVal = Math.abs(hours) * 100 + mins;
  }

  return returnVal;
}

function expandMenuItem(menu_id) {
    //  Change the image on the parent item
    document.getElementById('ID-'+menu_id).parentNode.className = 'selected';
    //  Then show the child item
    document.getElementById('ID-'+menu_id).className = 'visible';
}

function collapseMenuItem(menu_id) {
    //  Change the image on the parent item
    document.getElementById('ID-'+menu_id).parentNode.className = 'haschildren';
    //  Then hide the child item
    document.getElementById('ID-'+menu_id).className = 'hidden';
}

function collapseOrExpand(menu_id) {
    //  Check for valid 'menu_id'
    if (menu_id != null && menu_id > 0) {
        //  Check for hidden or visible sub-menu and show/hide accordingly
        if (document.getElementById('ID-'+menu_id).className == 'hidden') {
            expandMenuItem(menu_id);
        } else {
            collapseMenuItem(menu_id);
        }
    }
}

function expandAllMenus() {
    var els = document.getElementsByTagName('ul');
    for (i=0; i<els.length; i++) {
        var tmp = els[i].getAttribute('id');
        if (tmp != null) {
            if (tmp.substr(0,3) == 'ID-') {
                if (tmp.substr(3) > 0) {
                    expandMenuItem(tmp.substr(3));
                }
            }
        }
    }
}

function collapseAllMenus() {
    var els = document.getElementsByTagName('ul');
    for (i=0; i<els.length; i++) {
        var tmp = els[i].getAttribute('id');
        //  Make sure the ID attribute exists
        if (tmp != null) {
            //  Make sure it starts with 'ID-'
            if (tmp.substr(0,3) == 'ID-') {
                //  Make sure it's not 'ID-0'
                if (tmp.substr(3) > 0) {
                    collapseMenuItem(tmp.substr(3));
                }
            }
        }
    }
}

function SetVal(id) {
  // return;

  var rates = GetCookie("rates");
  if (rates.length > 0) {
    var pos = rates.indexOf(id + ",");
    if (pos >= 0) {
      var pos2 = rates.indexOf(";", pos + 4);
      var value = rates.substr(pos + 4, pos2 - pos - 4);
      // document.getElementById(id + "Val").innerHTML = "<font color=red>Earn Extra $" + value + "</font>";
      if (parseInt(value) > 0) {
        document.getElementById(id + "Val").innerHTML = "<span class=dotted onmouseover=\"Tip('Additional $" + value + " bonus from CardBenefit upon application approval')\" onmouseout=\"UnTip()\"><font class=size12bold color=#ff4500>$" + value + " Bonus</font></span>";
      }
    }
  }
}

function addBookmark(title, url) {
    if (window.sidebar) { // Firefox
        window.sidebar.addPanel(title, url, ""); 
    } else if (document.all) { // IE
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
}
		
function tellAFriend() {
  window.location = "mailto:?subject=Useful%20site%20for%20credit%20cards&body=Hi%3a%0A%0AI%20thought%20you%20would%20be%20interested%20in%20this%20-%20www.CardBenefit.com,%20a%20free%20site%20where%20you%20can%20compare%20credit%20card%20deals.%0A%0A";
}

function ToggleFloatingLayer(DivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)       //NN4+
    {
       document.layers[DivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(DivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)    // IE 4
    {
        document.all[DivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function addToGoogle() 
{
  var theurl= "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+document.location.href+"&title="+document.title;
  window.open(theurl);
}

function addToYahoo() {
  var theurl= "http://myweb2.search.yahoo.com/myresults/bookmarklet? t="+document.title+"&u="+document.location.href+"&ei=UTF-8";
  window.open(theurl);
}

function addToStumbleUpon() {
  var theurl= "http://www.stumbleupon.com/submit?url="+document.location.href+"&title="+document.title;
  window.open(theurl);
}

function addToDigg() {
  var theurl= "http://digg.com/submit?phase=2&url="+document.location.href+"&title="+document.title;
  window.open(theurl);
}

function addToDelicious() {
  var theurl= "http://del.icio.us/post?url="+document.location.href+"&title="+document.title;
  window.open(theurl);
}

var BrowserDetect = {
    	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Google Chrome",
			versionSearch: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Internet Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
