

var basketcookiename = "at.oesw.web.shop.BASKETCOOKIE=";
var basketcookieitemseparator = "/";
var basketcookiequantseparator = "^";


//NB: The seperator char, as well as the ';' and '=' characters cannot be used in the shop-key
//     nor can the '^' character.


function showVariant(theshopkey,varnum,imagepref,howmany){
// Function to Show Variants Vers. 1.0 *** depricated ***	
  theImg = document.getElementById(theshopkey + "_img");
  theImglnk = document.getElementById(theshopkey + "_imglnk");
  thePdflnk = document.getElementById(theshopkey + "_pdflnk");
  
  for (x=0;x<howmany;x++) {
  	theMenpkt = document.getElementById(theshopkey + "_" + x + "_up");
  	theMenpkt.src = "fileadmin/template/mischek/images/var_pfeil_off.gif";
  	
  } 
  
  theMenpkt = document.getElementById(theshopkey + "_" + varnum + "_up");
  theMenpkt.src = "fileadmin/template/mischek/images/var_pfeil_on.gif"
  
if (varnum == 0 ){
  theImg.src=imagepref + "_k.gif";
  theImglnk.href=imagepref + ".pdf";
  thePdflnk.href=imagepref + ".pdf";
  }else{
  theImg = document.getElementById(theshopkey + "_img");
  theImg.src=imagepref + "_k_var" + varnum + ".gif";
  theImglnk.href=imagepref + "_var" + varnum + ".pdf";
  thePdflnk.href=imagepref + "_var" + varnum + ".pdf";
  }
}

function getBasketCookie(){
  if (document.cookie){
    oldcookie = document.cookie;
    search = oldcookie.indexOf(basketcookiename);
    if (search >= 0){
      oldcookie = oldcookie.substr(search,oldcookie.length-search);
      search1 = oldcookie.indexOf(";");
      if (search1 >= 0){
        oldcookie = oldcookie.slice(0,search1);
      }
    }
    else{
      oldcookie = basketcookiename;
      }
    }
  else
      oldcookie = basketcookiename;
  return oldcookie;
}

function linkdetail(wID,dID) {
 var x= '/index.php?id=' +dID +'&type=98&' +'printlink=PRINT&_Q_UID=' +wID +'&mode=1&clear=0';
 //alert(x);
 window.open(x,wID,'top=50,left=50,width=650,height=650, scrollbars=yes, resizable=yes');
} 


function clearBasket(){
  document.cookie = basketcookiename;
  location.reload();
}




function modifyBasketCookie(oldcookie,Shopkey,quantity,deleteIt,onceOnly){
  // split the cookie into its individual shop components...

  //alert("Oldcookie: "+oldcookie);

  basketcontents = "";
  if (oldcookie.length > basketcookiename.length)
    basketcontents = oldcookie.substr(basketcookiename.length,oldcookie.length-basketcookiename.length);

  //alert("Contents: "+basketcontents);

  if (basketcontents.length < 1){
    basketcontents = Shopkey + basketcookiequantseparator + quantity;
    
  }
  else {
    basketitems = basketcontents.split(basketcookieitemseparator);
    
    basketcontents = "";
    foundit = deleteIt;
    for (i=0;i<basketitems.length;i++){
    
      theitem = basketitems[i].split(basketcookiequantseparator);  
      //alert("theitem="+theitem);
      //alert("item"+basketitems[i]);
      if (theitem[0] == Shopkey){
      	foundit = true;
        if (deleteIt == false && onceOnly == false){
          theitem[1] = parseInt(theitem[1]) + parseInt(quantity);
          basketitems[i] = theitem[0] + basketcookiequantseparator + theitem[1];
          basketcontents = basketcontents + basketitems[i];
  
          if (i<basketitems.length-1) basketcontents = basketcontents + basketcookieitemseparator;
        }
        else if (deleteIt == false){
          basketcontents = basketcontents + basketitems[i];
          if (i<basketitems.length-1) basketcontents = basketcontents + basketcookieitemseparator;
        }
      }
      else {
        basketcontents = basketcontents + basketitems[i];
        if (i<basketitems.length-1) basketcontents = basketcontents + basketcookieitemseparator;      
      }
    }
    if (foundit == false){
      basketcontents = basketcontents + basketcookieitemseparator + Shopkey + basketcookiequantseparator + quantity;
    }
  }
  
  kette = String(basketcontents);
  abschl = kette.substring(kette.length-1,kette.length);
 if (abschl == basketcookieitemseparator){
 	basketcontents = kette.substring(0,kette.length-1);
 	} 
 // alert("basketcontents=" +basketcontents);
  return (basketcookiename + basketcontents +';path=/');
}




function countItemsInBasket(){
  var oldcookie = getBasketCookie();
  var basketcontents = oldcookie.substr(basketcookiename.length,oldcookie.length-basketcookiename.length);
  
  if (basketcontents.length < 1){
    return 0;
  }
  var basketitems = basketcontents.split(basketcookieitemseparator);
  if (basketitems == null)
    return 0;
  else{
  //alert("vars=" +basketitems);
    //alert(basketitems.length);
    return basketitems.length;
    }
}





function isItemInBasket(shopKey){
	var oldcookie = getBasketCookie();
        var basketcontents = oldcookie.substr(basketcookiename.length,oldcookie.length-basketcookiename.length);
        
   
	if (basketcontents.length < 1){
		return false;
	}
	var basketitems = basketcontents.split(basketcookieitemseparator);
	if (basketitems == null)
		return false;
	var i;
	for (i=0;i<basketitems.length;i++){
      		var theitem = basketitems[i].split(basketcookiequantseparator);
      		if (theitem[0] == shopKey)
      			return true;
      		}
	return false;	
}





function addToBasket(Shopkey,quantity){
  // set a cookie, with the additional item...

  oldcookie = getBasketCookie();
  
  newcookie = modifyBasketCookie(oldcookie,Shopkey,quantity,false,false);
  
  //alert("Cookie set to:"+newcookie);
  document.cookie = newcookie;
}



function addToBasketMaxOne(Shopkey){
  // set a cookie, with the additional item...
  var oldcookie = getBasketCookie();
  
  var newcookie = modifyBasketCookie(oldcookie,Shopkey,1,false,true);
  
  //alert("Cookie set to:"+newcookie);
  document.cookie = newcookie;

}




function removeFromBasket(Shopkey){

  oldcookie = getBasketCookie();
  
  newcookie = modifyBasketCookie(oldcookie,Shopkey,0,true,false)
  //alert("newcookie=" +newcookie);
  document.cookie = newcookie;

  location.reload();
}





function changeCatalogPage(newItemNum){
  if (newItemNum >= 0)
    document.all.catalogdispatchform.firstitem.value = newItemNum;
  else
    document.all.catalogdispatchfrom.firstitem.value = 0;
  document.all.catalogdispatchform.submit();
}


function refreshBasketInfo(basketPidUrl){
	var numitems = countItemsInBasket();
	//alert("refresh "+numitems);
	// need to find the frame here...
	//var theFrame = camino_FindFrameInAnyWindow("basketinfoframe");
	//if (theFrame != null){
	//		var elem = theFrame.document.getElementById("basketinfoparagraph");
	if (basketPidUrl != null) {
	var elem = opener.document.getElementById("basketinfoparagraph");
	}
else
	{
		var elem = document.getElementById("basketinfoparagraph");
	}
		
		//alert('theElem: '+elem);
		
		if (elem!=null){
			var str = "";
			if (numitems==0){
				str += "<B>Keine</B> Objekte ausgew&auml;hlt. <br>";
	     //  str += "<A HREF='index.php?id=121' target='_top'>suchen</a>";
				}
        		else if (numitems==1){
        			str += "<A class='noDecoration' HREF='/index.php?id=194'><span class='orangefett'>1</span> Objekt ist ausgew&auml;hlt</div></a>";
        		}
        		else
        			str += "<A class='noDecoration' HREF='/index.php?id=194'><span class='orangefett'>"+numitems+"</span> Objekte sind ausgew&auml;hlt</div></a>";
        		if (numitems>0){
	          //  str += "<div style='padding-top:25px'><A HREF='index.php?id=194'>ansehen...</a></div>";
	         }
			elem.innerHTML = str;
			}
		//}
	//if (theFrame==null)
	//alert("Was Null");
}

function checkFormular(){
  if (document.basketform.nachname.value=="") {
  alert("Bitte geben Sie Ihren Nachnamen an!");
  document.basketform.nachname.focus();
  return false;
 }

 if (document.basketform.tel.value=="") {
  alert("Bitte geben Sie Ihre Telefonnummer an!");
  document.basketform.tel.focus();
  return false;
 }

 if (document.basketform.email.value=="") {
  alert("Bitte geben Sie Ihre E-mail Addresse an!");
  document.basketform.email.focus();
  return false;
 }

 if (document.basketform.email.value.indexOf('@') == -1) {
   alert("Bitte geben Sie ein gültige E-mail Addresse an!");
   document.basketform.email.focus();
   return false;
 }
 
 if (document.basketform.strasse.value=="") {
  alert("Bitte geben Sie Ihre Adresse an!");
  document.basketform.strasse.focus();
  return false;
 }	
	
 if (document.basketform.plz.value=="") {
  alert("Bitte geben Sie Ihre Postleitzahl an!");
  document.basketform.plz.focus();
  return false;
 }
 
/* 
 if (document.basketform.ort.value=="") {
  alert("Bitte geben Sie Ihren Wohnort an!");
  document.basketform.ort.focus();
  return false;
 }
 
 if (!document.basketform.PLZ) {
   alert("Bitte wählen Sie zumindest ein Projekt!");
   return false;
 }
 */
document.all.basketform.submit();

return false;
}