/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
Author: Addam M. Driver
Date: 10/31/2006
 */

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;
var rateda;
var ratedb;
var ratedc;
var ratedd;
var preSeta;
var preSetb;
var preSetc;
var preSetd;
var arating=0;
var brating=0;
var crating=0;
var drating=0;
// Rollover for image Stars //
function rating(num){
    sMax = 0;	// Isthe maximum number of stars

    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }
    var elm=num.id.match(/[0-9]+_/)[0];
    if(!rated){
        s = parseInt(num.id.replace("rat"+elm, '')); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){
                document.getElementById("rat"+elm+i).className = "on";
                document.getElementById("rateStatus").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("rat"+elm+i).className = "";
            }
        }
    }
}

function ratinga(num){
    sMax = 0;	// Isthe maximum number of stars
    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }
    if(!rateda){
        s = parseInt(num.id.replace("rata", '')); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){

                document.getElementById("rata"+i).className = "ona";
                document.getElementById("rateStatusa").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("rata"+i).className = "";
            }
        }
    }
}



function ratingb(num){
    sMax = 0;	// Isthe maximum number of stars
    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }
    if(!ratedb){
        s = parseInt(num.id.replace("ratb", '')); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){

                document.getElementById("ratb"+i).className = "onb";
                document.getElementById("rateStatusb").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("ratb"+i).className = "";
            }
        }
    }
}


function ratingc(num){
    sMax = 0;	// Isthe maximum number of stars
    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }


    if(!ratedc){
        s = parseInt(num.id.replace("ratc", '')); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){

                document.getElementById("ratc"+i).className = "onc";
                document.getElementById("rateStatusc").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("ratc"+i).className = "";
            }
        }
    }
}

function ratingd(num){
    sMax = 0;	// Isthe maximum number of stars
    for(n=0; n<num.parentNode.childNodes.length; n++){
        if(num.parentNode.childNodes[n].nodeName == "A"){
            sMax++;
        }
    }
    if(!ratedd){
        s = parseInt(num.id.replace("ratd", '')); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){

                document.getElementById("ratd"+i).className = "ond";
                document.getElementById("rateStatusd").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("ratd"+i).className = "";
            }
        }
    }
}


// For when you roll out of the the whole thing //
function off(me){
    if(!preSet){
        for(i=1; i<=sMax; i++){

            document.getElementById("rat1_"+i).className = "";
            document.getElementById("rateStatus").innerHTML = me.parentNode.title;
        }
    }else{
        rating(preSet);
    //document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
    }

}

// When you actually rate something //


// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    alert("Your rating was: "+sel.title);
}






// For when you roll out of the the whole thing //
function offa(me){
    if(!preSeta){
        for(i=1; i<=sMax; i++){

            document.getElementById("rata"+i).className = "";
            document.getElementById("rateStatusa").innerHTML = me.parentNode.title;
        }
    }else{
        ratinga(preSeta);
    //document.getElementById("rateStatusa").innerHTML = document.getElementById("ratingSaveda").innerHTML;
    }

}

function rateIt(me){

    document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
    document.form1.easeofuse.value = me.id;
    preSet = me;
    arating=parseInt(me.id.charAt(me.id.length-1));
    setOverallRating();

    //rated=1;
    rating(me);
}

// When you actually rate something //
function rateIta(me){

    document.getElementById("rateStatusa").innerHTML = document.getElementById("ratingSaveda").innerHTML + " :: "+me.title;
    document.form1.features.value = me.id;
    preSeta = me;
    brating=parseInt(me.id.charAt(me.id.length-1));
    setOverallRating();

    //rateda=1;
    ratinga(me);

}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    alert("Your rating was: "+sel.title);
}





// For when you roll out of the the whole thing //
function offb(me){

    if(!preSetb){
        for(i=1; i<=sMax; i++){

            document.getElementById("ratb"+i).className = "";
            document.getElementById("rateStatusb").innerHTML = me.parentNode.title;
        }
    }else{
        ratingb(preSetb);
    //document.getElementById("rateStatusb").innerHTML = document.getElementById("ratingSavedb").innerHTML;
    }

}

// When you actually rate something //
function rateItb(me){

    document.getElementById("rateStatusb").innerHTML = document.getElementById("ratingSavedb").innerHTML + " :: "+me.title;
    document.form1.quality.value = me.id;
    preSetb = me;
    crating=parseInt(me.id.charAt(me.id.length-1));
    setOverallRating();

    //ratedb=1;
    ratingb(me);

}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    alert("Your rating was: "+sel.title);
}





// For when you roll out of the the whole thing //
function offc(me){

    if(!preSetc){
        for(i=1; i<=sMax; i++){

            document.getElementById("ratc"+i).className = "";
            document.getElementById("rateStatusc").innerHTML = me.parentNode.title;
        }
    }else{
        ratingc(preSetc);
    //document.getElementById("rateStatusc").innerHTML = document.getElementById("ratingSavedc").innerHTML;
    }

}

// When you actually rate something //
function rateItc(me){

    document.getElementById("rateStatusc").innerHTML = document.getElementById("ratingSavedc").innerHTML + " :: "+me.title;
    document.form1.service.value = me.id;
    drating=parseInt(me.id.charAt(me.id.length-1));
    setOverallRating();
    preSetc = me;
    //ratedc=1;
    ratingc(me);

}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    alert("Your rating was: "+sel.title);
}




// For when you roll out of the the whole thing //
function offd(me){

    if(!preSetd){
        for(i=1; i<=sMax; i++){

            document.getElementById("ratd"+i).className = "";
            document.getElementById("rateStatusd").innerHTML = me.parentNode.title;
        }
    }else{
        ratingd(preSetd);
    //document.getElementById("rateStatusd").innerHTML = document.getElementById("ratingSavedd").innerHTML;
    }

}

// When you actually rate something //
function rateItd(me){

    document.getElementById("rateStatusd").innerHTML = document.getElementById("ratingSavedd").innerHTML + " :: "+me.title;
    document.form1.overallrating.value = me.id;
    preSetd = me;
    //ratedd=1;
    ratingd(me);

}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    alert("Your rating was: "+sel.title);
}
function validateForm()
{
    if(document.getElementById("categoryid").value=="-1")
    {
        alert("Please select a category");
        return false;
    }
    if(document.getElementById("productname").value=="")
    {
        alert("Please enter a product name");
        return false;
    }

    if(arating==0)
    {
        alert("Please rate 'Ease of use'");
        return false;
    }
    if(brating==0)
    {
        alert("Please rate 'Features'");
        return false;
    }
    if(crating==0)
    {
        alert("Please rate 'Quality'");
        return false;
    }
    if(drating==0)
    {
        alert("Please rate 'Service'");
        return false;
    }
    if(document.getElementById("textfield").value=="")
    {
        alert("Please enter a review title");
        return false;
    }
    if(document.getElementById("textarea").value=="")
    {
        alert("Cannot leave review column blank");
        return false;
    }
    else{
        return true;
    }
}
function test()
{
    alert('rating');
}

function setOverallRating()
{
    if(arating!=0&&brating!=0&&crating!=0&&drating!=0)
    {
        var overallrating=parseInt((arating+brating+crating+drating)/4);
        switch(overallrating)
        {
            case 1:rateItd(document.getElementById("ratd1"));
                break;
            case 2:rateItd(document.getElementById("ratd2"))
                break;
            case 3:rateItd(document.getElementById("ratd3"))
                break;
            case 4:rateItd(document.getElementById("ratd4"))
                break;
            case 5:rateItd(document.getElementById("ratd5"))
                break;
        }
    }

}