﻿// JScript File

function ShowBigImgAuto(url,width,height) 
{
    imgwin=window.open('', '_blank', 'directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, width='+width+', height='+height);
    imgwin.document.open();
    imgwin.document.writeln("<HTML> <HEAD> <TITLE> "+url+" </TITLE> </HEAD> <BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 onload=\"Test();\"> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%  HEIGHT=100%><TR><TD align=center valign=middle><a href='Javascript:window.close();'> <IMG border=0 SRC='"+url+"' id=imgCover></a> </TD> </TR> </TABLE><script>function Test(){window.resizeTo((document.getElementById('imgCover').width+40),(document.getElementById('imgCover').height+60));}</script> </BODY> </HTML>");
    imgwin.document.close(); 
}

        
function WinOpen(surl,target,iwidth,iheight) {
	msgWindow=window.open(surl,target,"width="+iwidth+",height="+iheight+",menubar=no,location=no,toolbar=no,directories=no,status=yes,resizable=yes,scrollbars=yes")
}

function showdet(htmlfile)
{
    WinOpen('dias/html/'+htmlfile,'_blank',600,400);
}

function validateNumber(oSrc, args) 
{
    if (args.Value!="")
    {
        var b = parseInt(args.Value);
        if (isNaN(b))
        {
            alert('Anzahl ist ungültig');
            args.IsValid =false;
        }
        else
            args.IsValid =true;
        
    }
    else
    {
        args.IsValid =false;
        alert('Bitte Anzahl eingeben');
    }
}

//wird von button aufgerufen
function isNumber(value) 
{
    var b = parseInt(value);
    if (isNaN(b))
    {
        alert('Anzahl ist ungültig');
        return false;
    }
    else
        return true;
 
}

var hand = function(ajax,str) 
{
    var ary=str.split("|");
    if (ary.length==3)
    {
        //var responseDiv = parent.frames[0].document.getElementById('BasketHeader1_itemscount');
        var responseDiv = parent.parent.document.getElementById('BasketHeader1_itemscount'); //parent.getElementById('BasketHeader1_itemscount');
        responseDiv.innerHTML=ary[1];
        
        //responseDiv = parent.frames[0].document.getElementById('BasketHeader1_itemscosts');
        responseDiv = parent.parent.document.getElementById('BasketHeader1_itemscosts');
        if (responseDiv!=null)
            responseDiv.innerHTML=ary[2];
        
        
    }
    
}


function makeOrder(e,artnum,textbox,lang)
{
   
    //e=null wenn von warenkorb button aufgerufen wird
    //13enter, 3 enter 10pad
    if (e==null||((e.keyCode?e.keyCode:e.which)==13)||((e.keyCode?e.keyCode:e.which)==3))
    {
        //loop all textboxes
        var found=false;
        for(var i=0; i< document.forms[0].elements.length; i++)
	    {
	        
		    if(document.forms[0].elements[i].id.indexOf("_anzahl_")>0)
		    {	
			    if (parseInt(document.forms[0].elements[i].value) && parseInt(document.forms[0].elements[i].value)!=0)
			    {
			        var val = (document.forms[0].elements[i].attributes['matrix']!=null)?document.forms[0].elements[i].attributes['matrix'].value:"";
                    if (val.length>0)
                        artnum=val;
                    var ajax = new Ajax();
                    
                    var menuId=209;
                    if (lang=="de")
                        menuId=1;
                    ajax.doGet('default.aspx?MenuId='+menuId+'&status=basket&m=add&typ=ajax&ArtLnk=' + artnum + '&anz='+document.forms[0].elements[i].value, hand);        
                    document.forms[0].elements[i].value='';
                    found=true;

			    }
		    }
    		
	    }
	    
	    if (found)
	    {
	        if (lang=="de")
	            alert("Artikel in Warenkorb gespeichert");
	        else
	            alert("Item is saved in your basket");
	    }
        return false;
    }

    return true;
}

function recalcBasket()
{
        var ajax = new Ajax();
        ajax.doGet('default.aspx?MenuId=1&status=basket&m=add&typ=ajax&artlnk=0&anz=0', hand);        
}

function doSearch(searchbox, menuId)
{
    parent.frames[1].location.href ='default.aspx?MenuId='+menuId+'&search='+searchbox.value;
    return false;
}



function doSearchTextBox(e,searchbox, menuId)
{
    if (e==null||((e.which?e.which:e.keyCode)==13))
    {
        parent.frames[1].location.href ='default.aspx?MenuId='+menuId+'&search='+searchbox.value;
        return false;
    }
    
}

