function init(){
	// document.siteSearchForm.searchString.value = searchValue;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){ x.src=x.oSrc; x.oSrc=x.src; }
}

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.0
  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 && document.getElementById) x=document.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];}
   
   document.oldImg = new Object;
   document.oldImg.src = a[2];
   document.oldImg.name = a[0];
}

function openTellFriend(pageUri,siteId,siteLocale){
	tellWin = window.open('http://www.wiitaunioni.fi/kerrokaverille/index.php?pageUri='+pageUri+'&siteId='+siteId+'&locale='+siteLocale,'tellFriendWin','scrollbars=no,width=460,height=500,location=no,resizable=no');
	tellWin.focus();
}

function openGallupComment(gallupId){
    window.open('/gallup/comment.php?gallupid='+gallupId,'commentWin','scrollbars=no,width=400,height=300,location=no,resizable=no');   
}

function kirjoita2(muuttuja) {
  document.write(muuttuja);
}

function mixIt(begin1, begin2, end1, end2){
kirjoita2("<a href=\"mail");
kirjoita2("to:");
kirjoita2(begin1);
kirjoita2(begin2+'@');
kirjoita2(end1);
kirjoita2(end2+'">');
if (mixIt.arguments.length<5) {
  kirjoita2(begin1);
  kirjoita2(begin2);
  kirjoita2('@'+end1);
  kirjoita2(end2);
}
else {
  kirjoita2(mixIt.arguments[4]);
}
kirjoita2('</a>');
}

function initProduct(color){
    if(document.addToCartForm){
            changeColor(color);

            for(var i=0;i<document.addToCartForm.selColor.options.length;i++){
                    if(document.addToCartForm.selColor.options[i].value == color)
                            document.addToCartForm.selColor.options[i].selected = true;
            }
    }
}

function changeColor(color){
    if(color != ""){
            showColor(color);
            populateSize(color);
    }
}

function showColor(color){
    document.getElementById('selectedColor').innerHTML = aColor[color];
    document.productImage.src = aImage[color].src;
	
}

function changeSize(size){
    populateColor(size);
}

function populateColor(size)
{
    var list = new Array();

    var i = 0;
    for(sizeIndex in aSize)
    {
            var colorSizes = aSize[sizeIndex];
            for(n=0;n<colorSizes.length;n++){
                    if(colorSizes[n] == size){
                            list[list.length] = sizeIndex;
                    }
            }
            i++;
    }

    var oColorSelect = document.addToCartForm.selColor;
    var initSelected = oColorSelect.options[oColorSelect.selectedIndex].value;
    oColorSelect.options.length = 0;
    for(i=0;i<list.length;i++)
    {
            oColorSelect.options[i] = new Option(aColor[list[i]],list[i]);
            if(initSelected == list[i]) oColorSelect.options[i].selected = true;
    }
}

function populateSize(color)
{
    var selection = color;
    if (!selection) return;

    var list = aSize[selection];
    var oSizeSelect = document.addToCartForm.selSize;
    var initSelected = oSizeSelect.options[oSizeSelect.selectedIndex].value;

    oSizeSelect.options.length = 0;
    for(i=0;i<list.length;i++)
    {
            oSizeSelect.options[i] = new Option(list[i],list[i]);
            if(initSelected == list[i]) oSizeSelect.options[i].selected = true;
    }
}

function populateQuantity(color,size)
{
    if (!size) return;
    if (!color) return;

    var quantity = aQuantity[color+"_"+size];
    if(!quantity) quantity = 10;

    var oQuantitySelect = document.addToCartForm.selQuantity;
    var initSelected = oQuantitySelect.options[oQuantitySelect.selectedIndex].value;

    oQuantitySelect.options.length = 0;
    for(i=1;i<=quantity;i++)
    {
            oQuantitySelect.options[i-1] = new Option("Määrä: "+i,i);
            if(initSelected == i) oQuantitySelect.options[i-1].selected = true;
            if(i == 10) break;
    }
}


function addToBasket(){
/*if(document.addToCartForm.selColor.options[document.addToCartForm.selColor.selectedIndex].value == ""){
            alert("Valitse tuotteen väri");
            document.addToCartForm.selColor.focus();
    }
    else if(document.addToCartForm.selSize.options[document.addToCartForm.selSize.selectedIndex].value == ""){
            alert("Valitse tuotteen koko");
            document.addToCartForm.selSize.focus();
    }*/
    //else{
            document.addToCartForm.submit();
    //}
}

function confirmRemoveFromCart(variation,id){
    if(confirm("Haluatko varmasti poistaa tuotteen ostoskorista?")){
            document.location.href = "/base/data/modules/formbuilder/processForm.php?id="+id+"&fb_formProcessor=data/event/removeFromCart.php&variation="+variation;
    }
}

function confirmClearCart(id){
    if(confirm("Haluatko varmasti tyhjentää ostoskorin?")){
            document.location.href = "/base/data/modules/formbuilder/processForm.php?id="+id+"&fb_formProcessor=data/event/clearCart.php";
    }
}

function showHideCartView(){
    var oLayer = document.getElementById('cartLayer');
    var oButImg = document.getElementById('cartButImg');

    if(oLayer.style.display == 'none' || oLayer.style.display == ''){
            oLayer.style.display = 'block';
            oButImg.src = "/images/lay_cart_select_but_2.gif";
    }
    else{
            oLayer.style.display = 'none';
            oButImg.src = "/images/lay_cart_select_but.gif";
    }
}

function openReceipt(order,k){
    window.open("/receipt.php?orderId="+order+"&k="+k,"receiptWin","width=400,height=400,scrollbars=yes,resizable=no");
}

function openTerms(){
    window.open("/terms.php?orderId","receiptWin","width=400,height=400,scrollbars=yes,resizable=no");
}

function openDelivery(){
    window.open("/deliveryInfo.php?orderId","deliveryWin","width=400,height=400,scrollbars=yes,resizable=no");
}

function openImageInFullSize(img){
    /*img = img.replace("previews/","");*/
    window.open(img,"imageWin","width=500,height=500,scrollbars=yes,resizable=yes");
}

function selectBank(bank){
    document.orderInfo.payment.value = bank;
    document.orderInfo.submit();
}

