//Globals...
var editId=0;
var activeWindow;
var dezi;
var leftCurr=null;
var actAgePrice="standard";
var nbsp = String.fromCharCode(160); 
function openProds(id)
{
	//var h=parseInt(id)==-2?560:500;
	var h=560;
	h+=document.all?0:10;
	activeWindow=openWin('Products','tableproducts.aspx?res='+id,700,h,1);
}

function openInfo(id)
{

	if(id.length==0)return;
	switch(id){
		case -1:
			openWin('Skitype','skitype.aspx',700,300,1);
			break;
		case -2:
			openWin('Snowboard','snobo.aspx',460,150,1);
			break;
		default:
			openWin('Hotel','hotel.aspx?id='+id,300,200,1);	
	}
	return;
}
function kickFromCart(who){
    
   who=getElem(who);
    try{
       //alert(typeof(who));
        var what=who.parentNode.parentNode;
        var priceNode=getNextElemByIdEnd(what.firstChild,"crtprc");    
        var price=getPrice(priceNode.firstChild.nodeValue)* -1;
        var Cart=what.parentNode;
        Cart.removeChild(what);
        try{
            var resPrice=(Cart.id=="Prod_0")?getNextElemByIdEnd(Cart.parentNode,"lblPrice"):getNextElemByIdEnd(Cart.parentNode,"subPrice");
            setResPrice(resPrice,price);
            Cart = getElem("shopCart");
            resPrice=getNextElemByIdEnd(Cart.firstChild,"lblPriceTotal");
            setResPrice(resPrice,price);
            setDiscPrice(price)
        }catch(e){}
    }catch(e){}
    return false;
}
function setDiscPrice(price){
    try{
        if(myDisc>0){
            var elem=getElem("PDiscTotal");
             if(elem){
                price-=(price*myDisc/100); try{
                var mTax=getTaxTotal(price);
	            if(!taxInc)price+=mTax;
                    var taxElem=getElem("TaxVal");
                    if(taxElem)setResPrice(taxElem,mTax);
	            }catch(n){/*alert(n);*/}      
                setResPrice(elem,price);
                elem=getNextElemByIdEnd(elem.parentNode.firstChild,"lblTotalPrc");
                if(elem)setResPrice(elem,price);
             }
         }
     }catch(e){}
}

function getPrice(tx){
    var i=0;
    var retVal=0;
    try{
        tx=tx.replace(/\s/g,"");
        while("-0123456789".indexOf(tx.charAt(i))<0){
            i++;
            if(i>=tx.length)break;
        }
        tx=tx.substr(i);
        var point=tx.indexOf(".");
        var comma=tx.indexOf(",");
        if(point>0 && comma>0){
            if(point>comma){
                tx=tx.replace(",","");
            }else{
                 tx=tx.replace(".","");
                 tx=tx.replace(",",".");
            }
        }else{
            if(comma>0)tx=tx.replace(",",".");
        }
        retVal=parseFloat(tx);
        if(isNaN(retVal))retVal=0;
       }catch(e){
        retVal=0;
        }//alert(e);}
    return retVal;
}

function frmCur(Num){
    var mDezi=(!dezi || dezi=="")?".":dezi;
    var retVal="0"+mDezi+"00";
    if(!isNaN(Num)){
        if(Num.toFixed){
            retVal=Num.toFixed(2);
            retVal=retVal.replace(".",mDezi);
        }else{
            retVal=Num.toString(10);
            retVal=retVal.replace(".",mDezi);
            var n=retVal.indexOf(mDezi)
            if(n==-1){
                retVal+=mDezi;
                n=retVal.indexOf(mDezi);
            }
            while(n>(retVal.length-3)){retVal+="0";}
        }
    //alert (retVal+"!"+dezi);
    }
    return retVal;
}

function makeDezi(PrTx){
    try{
        if(!dezi || leftCurr==null){
            curSign=curSign.replace(/[&#;]/g,"");
            RX=/(\d+)/;
            RX.exec(curSign);
            if(RegExp.$1){
                curSign=curSign.replace(RegExp.$1,String.fromCharCode(0+RegExp.$1));
            }
            var curPos=PrTx.indexOf(curSign);
            var needle=PrTx.search(/\d\D\d/);
            if(needle!==false){
                dezi=PrTx.charAt(needle+1);
                if(!isNaN(dezi))dezi=null;
                leftCurr=((curPos>-1) && (curPos<needle));
            }else{
                needle=PrTx.search(/\d/);
                if(needle!==false){
                    leftCurr=((curPos>-1) &&( curPos<needle));
                }
            }
        }
    }catch(e){
	}
}

function setResPrice(resPrice,price){
	var cResVal=0.00;
	var rPrTx="";
	try{
	    rPrTx=resPrice.firstChild.nodeValue;
	    makeDezi(rPrTx);
	}catch(e){
	    rPrTx="0.00";
	}
    try{
	    cResVal=getPrice(rPrTx);
    }catch(e){
        cResVal=0.00;
        leftCurr=null;
    }
    if(isNaN(price))price=0.00;
    cResVal+=price;
    if(cResVal==0)return;
	if(resPrice){	
		if(resPrice.firstChild){
			resPrice.firstChild.nodeValue=rPrTx.replace(/-?(\d+\D\d+)|(\d+)/,frmCur(cResVal));
		}else{
		    var tx=frmCur(cResVal);
		    if(leftCurr){tx=curSign+ tx;}
		    else{tx=tx+curSign;}
            var txn=document.createTextNode(""+tx);
            txn.data=txn.data.replace(" ",String.fromCharCode(160));
            resPrice.appendChild(txn);		
		}
	}
}

function getNodePrice(){


}


function add2Cart(who,Res, isPack){
    if(one4all)Res=0;
    var Cart=getElem("Prod_"+Res);
    var resPrice=Res>0?getNextElemByIdEnd(Cart.parentNode,"subPrice"):getNextElemByIdEnd(Cart.parentNode,"lblPrice");
    //alert(who.tagName);
    if(!who.parentNode){who=getElem(who);}
    var what=who.parentNode.parentNode;
    var price=0.00;
    var priceTotal=0.00;
    var selPrc="";
    var myVal="";
    var myPrice="-";
    var tx="";
    var arrVal=new Array();
    if(what.hasChildNodes){
         tx+=what.getElementsByTagName("td")[0].firstChild.nodeValue;
       // var model=what.getElementsByTagName("select")[0];
        myVal=who.value;
        arrVal[0]=(isPack?"S":"P") +myVal ;
        var prcCont=getElem("pr"+who.value);//+"cd"+Res
        for(var prcId in prcCont.childNodes){
            var prcElem=prcCont.childNodes[prcId];
            if(prcElem.style){
                if(prcElem.style.display!="none"){
                    if(prcElem.hasChildNodes()){
                        myPrice=prcElem.firstChild.nodeValue;
                        myPrice=myPrice.replace(" ",nbsp);
                        makeDezi(myPrice);
                        price=getPrice(myPrice);
                        selPrc=prcElem.id;
                        break;
                    }
                }
            }
        }
        if(isPack){
            what=what.nextSibling;
            while(what!=null){
                if(what.hasChildNodes && what.getElementsByTagName){
                    try{
                        var tds=what.getElementsByTagName("td");
                         tx+=" "+tds[0].firstChild.nodeValue;
                         var PPg=""+tds[0].id;
                        try{
                            var model=tds[1].getElementsByTagName("select")[0];
                            if(model!=null && model.value>0){
                                tx+=" " + model.options[model.selectedIndex].text;
                                arrVal.push("W"+myVal+"|"+PPg+"|"+model.value);
                            }else{
                                 arrVal.push("G"+myVal+"|"+PPg);
                            }
                        }catch(ex){
                                 arrVal.push("irr"+ex);
                        }
                    }catch(e){arrVal.push("err"+e);}
                }
                what=what.nextSibling;
            };
        }else{
            try{
                var model=what.getElementsByTagName("td")[1].getElementsByTagName("select")[0];
                if(model!=null && model.value>0){
                    tx+=" " + model.options[model.selectedIndex].text;
                    arrVal[0]="M"+model.value;
                }
            }catch(e){}
        }
        do{
            priceTotal+=price;
            //alert (price);
            setResPrice(resPrice,price);
            newItem=document.createElement("tr");
            itemCell=document.createElement("td");
            trashCell=document.createElement("td");
            newItem.setAttribute("class","p100");
            var now = new Date();
            var ident=now.getTime()+"Res"+Res+"CartItem";
            for(var n=0;n< arrVal.length;n++){
                myVal=arrVal[n];
                var valNode=document.createElement("input");
                valNode.setAttribute("type","hidden");
                valNode.setAttribute("value",myVal);
                
                valNode.setAttribute("name",n+ident);
                valNode.setAttribute("id",n+ident);
                trashCell.appendChild(valNode);
            }
            ident="0"+ident;
            var ageNode=document.createElement("input");
            ageNode.setAttribute("type","hidden");
            ageNode.setAttribute("value",selPrc);
            ageNode.setAttribute("name",ident+"AP");
            ageNode.setAttribute("id",ident+"AP");
            trashCell.appendChild(ageNode);
            var prcNode=document.createElement("td");            
            prcNode.setAttribute("id",ident+"_crtprc");            
            prcNode.setAttribute("class","crtprc");          
            var mp=document.createTextNode(""+myPrice);
            prcNode.appendChild(mp);
            var trash=document.createElement("input");
            trash.setAttribute("id",ident +"_del");
            trash.setAttribute("type","image");
            trash.setAttribute("class","imgBtn");
            trash.setAttribute("src","/images/btn/trash16.gif");
            trash.setAttribute("alt","delete");
            trashCell.appendChild(trash);
            //alert (tx);
            var txn=document.createTextNode(""+tx);
            itemCell.appendChild(txn);
            newItem.appendChild(trashCell);
            newItem.appendChild(itemCell);
            newItem.appendChild(prcNode);    
            Cart.appendChild(newItem);
            //trash.setAttribute("onclick","return(kickFromCart(this));");
            addEvent(trash, "click", function(e){return(kickFromCart(e));}, false)
            //newElem.setAttribute("onclick","return(false);");  
            if(one4all){
                Res++;
                try{
                    Cart=getElem("Prod_"+Res);
                    resPrice=getNextElemByIdEnd(Cart.parentNode,"subPrice");
               }catch(e){break;}
            }else{
                break;
            }
        }while(Cart!=null);
        
        Cart = getElem("shopCart");
        resPrice=getNextElemByIdEnd(Cart.firstChild,"lblPriceTotal");
        setResPrice(resPrice,priceTotal);
        setDiscPrice(priceTotal);
    }
    return;
}


function setCartTotal(){
	try{
        Cart = getElem("shopCart");
        resPrice=getNextElemByIdEnd(Cart.firstChild,"lblPriceTotal");
        priceTotal=getPrice(resPrice.firstChild.nodeValue);
	    try{
            disc=getElem("discV");
            if(disc){
                disc.firstChild.nodeValue=disc.firstChild.nodeValue.replace(/-?(\d+\D\d+)|(\d+)/,myDisc);
            }
            priceTotal-=(priceTotal*myDisc/100);
        }catch(i){}
	    try{
            var mTax=getTaxTotal(priceTotal);
	        if(!taxInc)priceTotal+=mTax;
            resPrice=getElem("TaxVal");
            if(resPrice)resPrice.firstChild.nodeValue=resPrice.firstChild.nodeValue.replace(/-?(\d+\D\d+)|(\d+)/,frmCur(mTax));
	    }catch(n){alert(n);}
        resPrice=getNextElemByIdEnd(Cart.firstChild,"PDiscTotal");
        if(resPrice)resPrice.firstChild.nodeValue=resPrice.firstChild.nodeValue.replace(/-?(\d+\D\d+)|(\d+)/,frmCur(priceTotal));
        resPrice=getNextElemByIdEnd(Cart.firstChild,"lblTotalPrc");
        if(resPrice)resPrice.firstChild.nodeValue=resPrice.firstChild.nodeValue.replace(/-?(\d+\D\d+)|(\d+)/,frmCur(priceTotal));
    }catch(e){}
}

function getTaxTotal(priceTotal){
	try{
	    var retval=0;
        if(tax>0){
            var prozTot=100+(taxInc?tax:0);
            retval=(priceTotal*tax/prozTot);
        }
	    return retval;
	}catch(e){
	    return 0;
	}
}

function getNextElemByIdEnd(firstSib,idEnd){
    var nextSib;
    try{
        nextSib=firstSib.nextSibling;
        var regeX="/"+idEnd+"$/";
        while(nextSib!=null){
            if(nextSib.id){
                if(nextSib.id.match(eval(regeX))){
                    // alert(nextSib.id);
                    break;
                }
            }
            nextSib=nextSib.nextSibling;
        };
    }catch(e){nextSib=null;}
    return nextSib;
}

function checkname(){
    var cn="";
    var sx="";
    var fn="";
    var ln="";
    var elem;
    var fc=document.forms[0].elements.length;
    for(i=0;i<fc;i++){
        elem=document.forms[0].elements[i];
        en=elem.name;
       if(en.indexOf("sex")>-1){
        
            if(elem.selectedIndex >-1){
                sx=elem.options[elem.selectedIndex].value;
            }
       }else{
            if(en.indexOf("lastname")>-1){
                ln=elem.value;
            }else{
                if(en.indexOf("firstname")>-1){
                    fn=elem.value;
               }
           }
       }
    }
    cn = ((fn!="") && (ln!="") ) ? ", " : "";   
    //sx+ln+cn+fn
    var txn=document.createTextNode((selRes+1)+". "+ln+cn+fn); 
    elem=getElem("btnClient"+selRes); 
    if(elem){
        elem=elem.getElementsByTagName("span")[0];
        if(elem){
            if(elem.firstChild){
                elem.replaceChild(txn, elem.firstChild);  
             }else{
                elem.appendChild(txn);
             } 
        }
        elem=getElem("hdnClient"+selRes); 
        if(elem){ elem.value=sx+"|"+fn+"|"+ln}
    }
}

function setPrices(what){
    var prcs;
    var who=getElem("priceSelect");
    if(who){
        if(ageArr[selRes]>0){
            if(who.style)who.style.display="none";
               actAgePrice=what;
           // what="_";
        }else{
            if(who.style)who.style.display="";
            if(actAgePrice!=what){
                who=getElem("pSel"+what);
                var prices=who.parentNode;
                
                var nextSib=prices.firstChild;
                while(nextSib!=null){
                    try{
                        nextSib.setAttribute("class","tabItem"); 
                        nextSib.className="tabItem"; 
                    }catch(e){}
                    nextSib=nextSib.nextSibling;
                };
               who.setAttribute("class","tabItem activ"); 
               who.className="tabItem activ"; 
               actAgePrice=what;
           }
       }
   }
  // var cdOff= pgArr.length>1?pgArr[1].indexOf("cd")+2:0;
    for(var i=1;i<pgArr.length;i++){
        var pg =pgArr[i]
        if(pg!=""){
            prcs=getElem(pg);
            if(prcs){ 
                                        /* no fallback...               
                if(pg.substr(cdOff)!=selRes){
                    if(prcs.style)prcs.style.display="none";
                    //alert(pg.substr(cdOff)+"!="+selRes);
                }else{
                }  */
                    prcs.style.display="";
                        var nono=true;
                        var def;
                        if(prcs.childNodes){                
                                for(var fc in prcs.childNodes){
                                    var fcn=prcs.childNodes[fc];
                                    if(fcn.id){                     
                                        if(fcn.id.indexOf(what)>-1){
                                            fcn.style.display="";
                                            nono=false;
                                        }else{
                                        /* no fallback...
                                            if(fcn.id.indexOf("standard")>0){
                                                def=fcn;
                                            }
                                            */
                                            if(fcn.style)fcn.style.display="none";
                                           
                                        }
                                    }
                                }   
                           /* no fallback...      
                            if(prcs.childNodes.length>1){
                          }else{
                            def=prcs.childNodes[0];
                          }*/
                       }
                    }
                    //if(nono && def){if(def.style)def.style.display=""};   
        }
    }
}

function setAktRes( who,sendIt){
    if(sendIt){
        if(document.forms[0].action.indexOf("?")<=0){
            document.forms[0].action += "?res="+ (who-1);
        }else{
            var i=document.forms[0].action.indexOf("res=");
            if(i<=0){
                document.forms[0].action+="&res="+ (who-1)
            }else{
                urlArr=document.forms[0].action.split("?");
                actArr=urlArr[1].split("&");
                var l=actArr.length;
                for(i=0;i<l;i++){
                    if(actArr[i].substr(0,4)=="res="){
                        actArr[i]="res="+ (who-1);
                        break;
                    }                
                }
                urlArr[1]=actArr.join("&");
                document.forms[0].action=urlArr.join("?");
            }
        }
        document.forms[0].submit();
    }else{
        var CN=getElem("btnClient"+selRes);
        CN.parentNode.setAttribute("class","disResCart");
        CN.parentNode.className="disResCart";
        CN=CN.firstChild;
        CN.style.color="";
        selRes=who;
        CN=getElem("btnClient"+selRes);
        CN.parentNode.setAttribute("class","actResCart");
        CN.parentNode.className="actResCart";
        CN=CN.firstChild;
        CN.style.color="red";
        try{
            CN=getElem("hdnClient"+selRes);
            if(CN){
                var namArr= CN.value.split("|");                
                var fc=document.forms[0].elements.length;
                for(i=0;i<fc;i++){
                    elem=document.forms[0].elements[i];
                    en=elem.name;
                   if(en.indexOf("sex")>-1){   
                       for (var j = 0; j < document.forms[0].elements[i].length; j++){
                            if (document.forms[0].elements[i].options[j].value==namArr[0]) document.forms[0].elements[i].selectedIndex  = j;
                        }
                   }else{
                        if(en.indexOf("lastname")>-1){
                            elem.value=namArr[2];
                        }else{
                            if(en.indexOf("firstname")>-1){
                               elem.value=namArr[1];
                           }
                       }
                   }
                }
            }
        }catch(e){
        }
        try{setDate();}catch(e){}
        try{setPrsData();}catch(e){}
       // if(pgArr){setPrices(actAgePrice);}
    }
}

function loadMe(url)
{
    try{
	       showHide("sender",false);
	    showHide("loader",false);
	    if(document.cookie==""){showHide("nocookies",true);}else{showHide("nocookies",false);}
	    if(document.forms[0]["sex"])document.forms[0]["sex"].focus();
	}catch(e){}
}

function checkCartHeight()
{
    try{
        var mHold = getElem("ScHolder");
        if(mHold){
            var iSize=window.innerHeight ||( mHold.top);
            var mCart = getElem("shopCart");
            if(mCart){
            }
        }
    }catch(e){}
}


function getmyLoc()
{
	return location.href;
}

function goBack()
{
	history.back();
}
function openSubReservation(id)
{
    /*var agent = navigator.userAgent.toLowerCase();
	if(agent.indexOf("msie")!=-1){
		activeWindow=openWin('Reservierung','subReservation.aspx?res='+id,560,420 ,1);
	}else{
		activeWindow=openWin('Reservierung','subReservation.aspx?res='+id,560,440,1);
	}*/
		activeWindow=openWin('Reservierung','subReservation.aspx?res='+id,580,460,1);
}


/***********************************************************************************************************************************************
****************************************************************** end of script! ****************************************************************
************************************************************************************************************************************************/
