/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lib.js
Script library for Stiefel K�nig

Version:             1.1
Last Changed:        2007-12-07

manfred.schneiderbauer@world-direct.at
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/

// firefox/AllOS and Gecko/Mac have a smaller default font size, so increase it there
try{
if((!isMac&&navigator.userAgent.indexOf('Firefox')!=-1)||(isGecko&&isMac))
	{
	var r=document.styleSheets[2].cssRules; // ref to clib's CSS #2 (browser specific CSS)
	var rr='';var thisFs='';var fsMode='';
	for(var i=0;i<r.length;i++)
		{
		if(r[i].style.fontSize)
			{
			thisFs=r[i].style.fontSize;
			if(thisFs.indexOf('em')!=-1){fsMode='em';}
			if(thisFs.indexOf('pt')!=-1){fsMode='pt';}
			if(thisFs.indexOf('px')!=-1){fsMode='px';}
			thisFs=Number(r[i].style.fontSize.replace('em','').replace('pt','').replace('px',''));
			thisFs+=.2;
			r[i].style.fontSize=thisFs+fsMode;
			}
		}
	}
}catch(error){}

// permanently center the teaser images in the home page
function centerTeasers(){
try{
if(document.body)
  {
    if(document.body.innerHTML)
      {
        if(isIE5up)
          {
            d('tdFooter').style.position='relative';d('tdFooter').style.top='-4px';
            d('tdMiddleMenu').style.position='relative';d('tdMiddleMenu').style.top='-4px';
            if(d('tdMain')){d('tdMain').style.position='relative';d('tdMain').style.top='-4px';}
          }

        if(d('dvHeadImgTeasers'))
          {
            var ww=0;
            if(isIE5up){ww=document.body.clientWidth;}else{ww=window.innerWidth;}
            d('dvHeadImgTeasers').style.left=Number(ww/2-369)+'px';
          }
      } else {window.setTimeout("centerTeasers();",250);}
  } else {window.setTimeout("centerTeasers();",250);}
window.setTimeout("centerTeasers();",100);
}catch(error) {window.setTimeout("centerTeasers();",250);}
}
centerTeasers();

/*
// onload watchdog
function onloadWatchdog(){
document.body.onload=function()
  {
  window.timer=false;
  }
}
window.timer=true;
clib_onload("onloadWatchdog()");
window.setTimeout("onloadWatchdog_fight();",5000);
function onloadWatchdog_fight(){
if(!window.timer)
  {
    document.body.innerHTML='';
    window.setTimeout("window.open(location.href);opener=window;window.close();",250);
  }
}
*/

clib_onload('try{d("Gutschein").style.display="block";}catch(error){ }');

// reload Gutschein page once on IE; quirk to prevent IE crash
var tl=location.href;
if(isIE55up&&tl.indexOf('gutschein.html')!=-1)
  {
   if(tl.indexOf('reloaded')==-1)
    {
     if(tl.indexOf('?')==-1&&tl.indexOf('&')==-1)
      {
        setTimeout("location.href='"+tl+"?reloaded';",1000);
      }
     if(tl.indexOf('?')!=-1)
      {
        location.href=tl+'&reloaded';
      }
    }
  }


/* begin Gutschein form functions */



// Saves the form...
//*****************************
// Version. 1.0   Author: thomas.leiter@world-direct.at
// Update (05.12.2007) : Fix plz bug

function save(urlSite) {
  var SilberShoe1 = d("SilberShoe1").value-0;
  var SilberShoe2 = d("SilberShoe2").value-0;
  var SilberShoe3 = d("SilberShoe3").value-0;
  var GoldShoe1 = d("GoldShoe1").value-0;
  var GoldShoe2 = d("GoldShoe2").value-0;
  var GoldShoe3 = d("GoldShoe3").value-0;
  var Box = d("box").value-0;

  //Formular Value

  var Vorname = d("vorname").value;
  var Nachname = d("nachname").value;
  var Firma = d("firma").value;
  var Strasse = d("strasse").value;
  var Plz = d("GutscheinPlz").value-0;
  var Ort = d("ort").value;
  var Email = d("email").value;



  var updatepars ='&SilberShoe1=' + SilberShoe1 + '&SilberShoe2=' + SilberShoe2 + '&SilberShoe3=' + SilberShoe3 +
                  '&GoldShoe1=' + GoldShoe1 + '&GoldShoe2=' + GoldShoe2 + '&GoldShoe3=' + GoldShoe3 +
                  '&box=' + Box + '&vorname=' + Vorname + '&nachname=' + Nachname + '&firma=' + Firma + '&strasse=' + Strasse +
                   '&plz=' + Plz + '&ort=' + Ort + '&email=' + Email + '&action=save';

 // alert(updatepars);



   var summeGutscheine = SilberShoe1 + SilberShoe2 + SilberShoe3 + GoldShoe1 + GoldShoe2 + GoldShoe3;


  if(!summeGutscheine) {

	d("errorEmpty").style.display = "block";
	d("errorBoxen").style.display = "none";

  } else {

			// If summary of Gutscheins is bigger than ordered boxes
			//***************************
			if(summeGutscheine<Box) {

				 d("errorBoxen").style.display = "block";
				 d("errorEmpty").style.display = "none";
				 d("errorPlz").style.display = "none";
				 d("errorField").style.display = "none";

			 return false;
			}
			else {

		if(Vorname &&  Nachname && Strasse && Ort && Plz) {

			 // Check PLZ for length
			 //***************************

			if(String(Plz).length!=4 || isNaN(Plz)) {

				d("errorPlz").style.display = "block";
				d("errorField").style.display = "none";
				d("errorBoxen").style.display = "none";
				d("errorEmpty").style.display = "none";

				return false;
				}
				else {

				 // Ajax Updater
				 //***************************
				  d('gutscheine').submit();

				}

		}	else {

		d("errorField").style.display = "block";
		d("errorBoxen").style.display = "none";
		d("errorEmpty").style.display = "none";
		d("errorPlz").style.display = "none";

		}



			}
  }

}

/* end Gutschein form functions */


