//Browser name: BrowserDetect.browser
//Browser version: BrowserDetect.version
//OS name: BrowserDetect.OS

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: "OmniWeb",
                        versionSearch: "OmniWeb/",
                        identity: "OmniWeb"
                },
                {
                        string: navigator.vendor,
                        subString: "Apple",
                        identity: "Safari"
                },
                {
                        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: "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.platform,
                        subString: "Linux",
                        identity: "Linux"
                }
        ]

};
BrowserDetect.init();






function getNewVoteValue(user_id,rid,recipe_group_tag,pstar_num){
 //alert (rid + " " + recipe_group_tag + " " + pstar_num);
  if(user_id >0 ){
  var xmlhttp=false; //Clear our fetching variable
  try {
        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
  } catch (e) {
        try {
                xmlhttp = new
                ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
        } catch (E) {
            xmlhttp = false;
        }
  }
  
  
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
          xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
  }
  
  
  var file = 'update_vote.php?recipe_id=' + rid + '&group_tag=' + recipe_group_tag + '&star_num=' + pstar_num; //This is the path to the file we just finished making *
  xmlhttp.open('GET', file , true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
  //alert (file);
  
  xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
              var content = xmlhttp.responseText; //The content data which has been retrieved ***
              var content_split = content.split(',');
              
              if( content ){ //Make sure there is something in the content variable
                    //alert (typeof content);
                    //alert(content);

                    if (content_split[1] == "voted"){
                      document.getElementById('err_msg').innerHTML = 'You already rated this recipe today. Ratings may be placed once every 24 hours. Try again tomorrow.'; 
                    }
                    if (content_split[1] == "too_many_votes"){
                      document.getElementById('err_msg').innerHTML = 'You can only rate 15 recipes per day. Please return tomorrow to keep rating.'; 
                    }
                    if (content_split[1] == "not_voted"){
                      document.getElementById('std_msg').innerHTML = 'You rated this recipe ' + content_split[2] + ' out of 5.<br />';
                    }
                    
                    var element_id = document.getElementById("display_current_rating");
                    var width = content_split[0] / 20;

//alert(BrowserDetect.browser+BrowserDetect.version);

                    if ( BrowserDetect.browser+BrowserDetect.version == 'Explorer7' ){
                      if ( width >= 0 && width < 1.5 ){
                        width = 6;
                      }
                      if ( width >= 1.5 && width < 2.5 ){
                        width = 10;
                      }
                      if ( width >= 2.5 && width < 3.5 ){
                        width = 15;
                      }
                      if ( width >= 3.5 && width < 4.5 ){
                        width = 20;
                      }
                      if ( width >= 4.5 && width < 5.5 ){
                        width = 40;
                      }
                    }else{
                      width = width * 20;
                    }

                    element_id.style.width = width + "%";
                    document.getElementById('input_form').input_name.select();                      
                    
              }
              
      }
  }
  
  xmlhttp.send(null) //Nullify the XMLHttpRequest
  return;
  }else{//redirect to login page.
    window.location = "../authentication/login.php"
  }
}

