/* some common functions */
function changeProp(objId,x,theProp,theValue) {
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

/* frontpage prduct tab selector */
function changeTabSelected(id) {
    document.getElementById(id).className = "selected";
}
function changeTabNormal(id) {
    document.getElementById(id).className = "none";
}

/* frontpage newsletter input field */
function spostilista() {
    document.getElementById('liitySpostilistalle').value = "";
}

/* Image swaps */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* show/hide shopping basket */
function showBasket(){
    document.getElementById("shoppingbasket").className = "shoppingbasketShow";
}
function hideBasket(){
    document.getElementById("shoppingbasket").className = "shoppingbasketHide";
}

/* star ratings */
/*
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;

// 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++;
        }
    }

    if(!rated){
        s = num.id.replace("_", ''); // Get the selected star
        a = 0;
        for(i=1; i<=sMax; i++){
            if(i<=s){
                document.getElementById("_"+i).className = "on";
                document.getElementById("rateStatus").innerHTML = num.title;
                holder = a+1;
                a++;
            }else{
                document.getElementById("_"+i).className = "";
            }
        }
    }
}

// For when you roll out of the the whole thing //
function off(me){
    if(!rated){
        if(!preSet){
            for(i=1; i<=sMax; i++){
                document.getElementById("_"+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 //
function rateIt(me){
    if(!rated){
        document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
        preSet = me;
        rated=1;
        sendRate(me);
        rating(me);
    }
}

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

/* Product read more */
function prodReadMore(){
    changeProp('prodinfoMore','','display','block','DIV');
    changeProp('readMoreLink','','display','none','DIV');
    changeProp('readLessLink','','display','block','DIV');
}
function prodReadLess(){
    changeProp('prodinfoMore','','display','none','DIV');
    changeProp('readMoreLink','','display','block','DIV');
    changeProp('readLessLink','','display','none','DIV');
}

/* show add comment*/
function addComment(){
    changeProp('commentForm','','display','block','DIV');
}

/* open compare window */
function openCompare() { //v2.0
  window.open('vertailu.html','Compare','scrollbars=yes,width=700,height=286');
}
