// JS for AUDI shop $Revision: 2720 $ (Rev:1.61)

var cb={
	version:false,
	ns4:0,
	op:0,
	ie:0,
	ie50:0,
	moz:0,
	saf:0,
	init:function(){
		try{
			this.ns4=(document.layers)?1:0;
			this.op=(window.opera)?1:0;
			this.ie=(document.all&&!this.op)?1:0;
			this.ie50=(this.ie&&!document.createEventObject)?1:0;
			this.moz=(document.getElementById&&!this.ie&&!this.op)?1:0;
			this.saf=(navigator.userAgent.lastIndexOf("Safari")>0)?1:0;
		}
		catch(e){
		}
	},
	getVer:function(){
		if(this.ns4){
			this.version="ns4";
		}
		if(this.op){
			this.version="op";
		}
		if(this.ie){
			this.version="ie";
		}
		if(this.ie50){
			this.version="ie50";
		}
		if(this.moz){
			this.version="moz";
		}
		if(this.saf){
			this.version="saf";
		}
		return this.version;
	}};
	
cb.init();

function getElementsByClass(_1,_2,_3){
	var _4=new Array();
	if(_2==null){
		_2=document;
	}
	if(_3==null){
		_3="*";
	}
	var _5=_2.getElementsByTagName(_3);
	var _6=_5.length;
	var _7=new RegExp("(^|\\s)"+_1+"(\\s|$)");
	var i;
	var j;
	for(i=0,j=0;i<_6;i++){
		if(_7.test(_5[i].className)){
			_4[j]=_5[i];
			j++;
		}
	}
	return _4;
}

function cssClassChanger(_a,_b,_c,_d){
	if(_a=="flip"){
		_b.className=(!cssClassChanger("verify",_b,_c))?_b.className.replace(_d,_c):_b.className.replace(_c,_d);
	}else{
		if(_a=="add"){
			if(!cssClassChanger("verify",_b,_c)){
				_b.className+=_b.className?" "+_c:_c;
			}
		}else{
			if(_a=="remove"){
				var _e=_b.className.match(" "+_c)?" "+_c:_c;
				_b.className=_b.className.replace(_e,"");
			}else{
				if(_a=="verify"){
					return new RegExp("\\b"+_c+"\\b").test(_b.className);
				}
			}
		}
	}
}

var popWin=null;
function openPopup(_f,_10){
	var w=640;
	var h=480;
	if(_10==1){
		w=958;
		h=590;
	}else{
		if(_10==2){
			w=480;
			h=336;
		}
	}
	if(popWin!=null){
		popWin.close();
		popWin=null;
	}
	popWin=window.open(_f.href,"popWin","dependent=yes,scrollbars=yes,menubar=no,toolbar=no,status=yes,location=no,locationbar=no,width="+w+",height="+h+",resizable=yes");
	popWin.focus();
}

//////////////////////////////////////////////////////////////////
// change image dynamically for modelSW, detSW and catSW.
// using jQuery.
//////////////////////////////////////////////////////////////////
function imgSW(){
	this.imgID="";
	this.imgEl=new Image();
	this.imgARR=new Array();
	this.imgThere=false;
	this.bgID="";
	this.lnkID="";
	this.lnkARR=new Array();
	this.selID="";
	this.selEl=new Object();
	this.ulID;
	this.ulEl=new Object();
}

imgSW.prototype=new Object();

imgSW.prototype.init=function(o){
	if(o.imgID==null){
		return;
	}
	this.imgID=o.imgID;
	this.bgID=o.bgID?o.bgID:null;
	this.lnkID=o.lnkID;
	this.selID=o.selID;
	this.ulID=o.ulID;
	this.regImg();
	if(o.swType=="catSW"){
		this.regCatEv();
	}else{
		if(o.swType=="modelSW"){
			this.regModelEv();
		}else{
			if(o.swType=="detSW"){
				this.regDetailEv();
			}
		}
	}
};

imgSW.prototype.regImg=function(){
	try{
		this.imgEl=$("#"+this.imgID);
		this.imgThere=true;
	}
	catch(e){
		this.imgThere=false;
	}
};

imgSW.prototype.regCatEv=function(){
	this.lnkARR=$(this.lnkID).getElementsByTagName("A");
	for(var i=0;i<this.lnkARR.length;i++){
		this.lnkARR[i].nr=i;
		this.lnkARR[i].parent=this;
		this.lnkARR[i].onmouseover=function(){
			if(this.parent.imgThere){
				this.parent.imgEl.src=this.parent.imgARR[this.nr];
			}
			$(this.parent.imgID).style.display="block";
			if(this.parent.bgID){
				$(this.parent.bgID).style.display="block";
			}
		};
		this.lnkARR[i].onmouseout=function(){
			$(this.parent.imgID).style.display="none";
			if(this.parent.bgID){
				$(this.parent.bgID).style.display="none";
			}
		};
	}
};

imgSW.prototype.regModelEv=function(){
	this.selEl=$("#"+this.selID);
	this.selEl.parent=this;
	this.selEl.bind("change", {el: this.selEl}, function(e){
		sel = e.data.el;
		if(sel.parent.imgThere){
			sel.parent.imgEl.attr("src", sel.parent.imgARR[sel.attr("selectedIndex")-1]);
		}
	});
};

imgSW.prototype.regDetailEv=function(){
	this.lnkARR = $("#"+this.ulID).find("A");
	for(var i=0;i<this.lnkARR.length;i++){
		$(this.lnkARR[i]).bind("click", {parent: this, _nr: i}, function(event){
			event.preventDefault();
			_parent = event.data.parent;
			nr = event.data._nr;
			$("#ext_loading").css("display", "block");
			if(_parent.imgThere){
				_parent.imgEl.attr("src", _parent.imgARR[nr]);
			}
		});
	}
	this.imgEl.bind("load", function(){
		$("#ext_loading").css("display", "none");
	});
};

//////////////////////////////////////////////////////////////////////////
// remove pre-inserted text in keyword search field
// using jQuery.
//////////////////////////////////////////////////////////////////////////
function srch(){
	this.formID="";
	this.formEl=new Object();
	this.val="";
	this.inpID="";
	this.inpEl=new Object();
	this.extChangeID = "";
	this.extChangeEl = new Object();
}

srch.prototype=new Object();

srch.prototype.init=function(o){
	if(o.inpID==null){
		return;
	}
	this.inpID=o.inpID;
	this.val=o.val==null?"":o.val;
	this.inpEl=$("#"+this.inpID);
	if(this.inpEl.attr("value") == "")
		this.inpEl.attr("value", this.val);
	this.extChangeID = o.extChangeID;
	this.extChangeEl=$("#"+this.extChangeID);
	this.inpEl.bind("focus", {el: this.inpEl, val : this.val}, function(e)
	{
			inpEl = e.data.el;
			val = e.data.val;
			if(inpEl.attr("value").indexOf(val) != -1)
			{
				inpEl.attr("value", "");
			}
	});
	this.inpEl.bind("blur", {el0: this.extChangeEl, el: this.inpEl, val : this.val}, function(e)
	{
			extChangeEl = e.data.el0;
			inpEl = e.data.el;
			val = e.data.val;
			if(inpEl.attr("value")=="")
			{
				inpEl.attr("value", val + " " + extChangeEl.find(":selected").text());
			}
	});
	if(o.formID==null)
	{
		return;
	}
	this.formID=o.formID;
	this.formEl=$("#"+this.formID);
	this.formEl.bind("submit", {el: this.inpEl, val : this.val}, function(e)
	{
			inpEl = e.data.el;
			val = e.data.val;
			if(inpEl.attr("value").indexOf(val) != -1)
			{
				inpEl.attr("value", "");
			}
	});
	if(o.extChangeID==null)
	{
		return;
	}
	this.extChangeEl.bind("change", {el0: this.extChangeEl, el: this.inpEl, val : this.val}, function(e)
	{
			extChangeEl = e.data.el0;
			inpEl = e.data.el;
			val = e.data.val;
			if(inpEl.attr("value").indexOf(val) != -1)
			{
				inpEl.attr("value", val + " " + extChangeEl.find(":selected").text());
			}
	});
	
};
//////////////////////////////////////////////////////////////////////////

function CheckBoxSel(){
this.pID="";
this.clName="";
this.cbEl=new Object();
this.cbARR=new Array();
}
CheckBoxSel.prototype=new Object();
CheckBoxSel.prototype.init=function(o){
this.pID=o.pID;
this.clName=o.clName;
this.cbARR=getElementsByClass(this.clName,$(this.pID),"INPUT");
this.cbEl=$(o.cbID);
this.regEv();
};
CheckBoxSel.prototype.regEv=function(){
this.cbEl.parent=this;
this.cbEl.onclick=function(){
this.parent.changeState();
};
};
CheckBoxSel.prototype.changeState=function(){
for(var i=0;i<this.cbARR.length;i++){
this.cbARR[i].checked=this.cbEl.checked;
}
};
var AudiOSFormUtils={apHdFld:function(_19){
var _1a=document.createElement("input");
_1a.type=_19.type;
_1a.name=_19.name;
_1a.value=_19.value;
return _1a;
},transfer:function(arr,obj){
var frm=new fs(obj);
if(frm){
for(var i=0;i<arr.length;i++){
var _1f=$(arr[i]);
frm.f.appendChild(AudiOSFormUtils.apHdFld({type:"hidden",name:_1f.name,id:"hidden"+_1f.id,value:_1f.value}));
}
}
},createHiddenFields:function(arr,obj){
var frm=new fs(obj);
if(frm){
for(var i=0;i<arr.length;i+=2){
frm.f.appendChild(AudiOSFormUtils.apHdFld({type:"hidden",name:arr[i],id:"id"+arr[i],value:arr[i+1]}));
}
}
}};
function cssClassChangerTimer(_24,id,_26,_27,_28,_29){
if(_29>0){
if((_26=="")&&(_27.length!=0)){
cssClassChanger("add",document.getElementById(id),_27);
setTimeout("cssClassChangerTimer('"+_24+"','"+id+"','"+_27+"','"+_26+"',"+_28+","+(_29-0.5)+")",_28);
}else{
if((_26.length!=0)&&(_27=="")){
cssClassChanger("remove",document.getElementById(id),_26);
setTimeout("cssClassChangerTimer('"+_24+"','"+id+"','"+_27+"','"+_26+"',"+_28+","+(_29-0.5)+")",_28);
}else{
cssClassChanger("flip",document.getElementById(id),_26,_27);
setTimeout("cssClassChangerTimer('"+_24+"','"+id+"','"+_26+"','"+_27+"',"+_28+","+(_29-0.5)+")",_28);
}
}
}
}
function replaceParameter(qry, key, value) {
var searchPos = qry.lastIndexOf(key);
if (searchPos > 0) {
	var parmPart = qry.substr(searchPos, qry.length);
	var beginQry = qry.substr(0, searchPos);
	var check  = parmPart.indexOf("&")
	var endQry =  "";
	if (check > 0) {
		endQry = parmPart.substr(check, parmPart.length);
		parmPart = parmPart.substr(0, check);		
	}
	var newParam = parmPart.split("=");
	newParam[1] = value;
	
return beginQry + newParam[0] +  "=" + newParam[1] + endQry;
} else {
return "";
}
}
function parseQueryString(qry,key){
var _2c=(qry.replace(/(.+\?)/,""));
var _2d=_2c.split("&");
var _2e=new Array();
for(var prs=0;prs<_2d.length;++prs){
_2e.push(_2d[prs].split("="));
}
for(var i=0;i<_2d.length;++i){
if(_2e[i][0]==key){
return _2e[i][1];
}
}
return "";
}

function getAllFormValues(formName){
  var res=new Array();
  var j=0;
  $(formName).each(['SELECT'], function() {
    res[j]["name"]=(this).name;
    res[j]["value"]=(this).options[(this).selectedIndex].value;
    j++;
  });

  $(formName).each(['INPUT'], function() {
    res[j]["name"]=(this).name;
    res[j]["value"]=(this).value;
    j++;
  });
  
  $(formName).each(['TEXTAREA'], function() {
    res[j]["name"]=$(this).name;
    res[j]["value"]=(this).innerHTML;
    j++;
  });
  
  return res;
}


////////////////////////////////////////////////////////////////////////////
// update functionality for cascading drop-down lists
// using jQuery
////////////////////////////////////////////////////////////////////////////
function selOBJ(){
	this.selEl1=new Object();
	this.selEl2=new Object();
	this.sARR1=new Array();
	this.sARR2=new Array();
}

selOBJ.prototype=new Object();

selOBJ.prototype.init=function(o){
	try{
		this.selEl1=$("#"+o.selID1);
		this.selEl2=$("#"+o.selID2);
	}
	catch(e){
		return;
	}
	this.sARR1=o.sARR1;
	this.sARR2=o.sARR2;
	this.selEl1.parent=this;
	this.selEl1.bind("change", {el: this.selEl1}, function(e){
		sel = e.data.el;
		sel.parent.fillSelect(sel.parent.selEl2,
								sel.parent.sARR2[sel.attr("selectedIndex")]);
	});
	this.fillSelect(this.selEl1,this.sARR1);
	this.fillSelect(this.selEl2,this.sARR2[this.selEl1.attr("selectedIndex")]);
};

selOBJ.prototype.kill=function(el){
	var c=el.attr("options").length;
	el.attr("length", 0);
};

selOBJ.prototype.refresh=function(sARR1, sARR2, index){
	this.sARR1 = sARR1;
	this.sARR2 = sARR2;
	this.fillSelect(this.selEl1, this.sARR1);
	this.fillSelect(this.selEl2,this.sARR2[index]);
}

selOBJ.prototype.fillSelect=function(el,arr){
	this.kill(el);
	var _3c=0;
	var Ins=new Object();
	var c=arr.length;
	for(var i=0;i<c;i++){
		Ins=document.createElement("option");
		Ins.text=decodeHTML(arr[i][0]);
		Ins.value=arr[i][1];
		if(cb.saf){
			el.appendChild(Ins);
		}else{
			el.attr("options").add(Ins);
		}
		if(arr[i][2]){
			el.attr("selectedIndex", i);
		}
	}
};
////////////////////////////////////////////////////////////////////////////

function togTbl(o){
	var el=o.el;
	var _42=o.tblID;
	var _43=cssClassChanger("verify",o.el,"ext_arr_close");
	$(_42).style.display=_43?"block":"none";
	cssClassChanger("flip",el,"ext_arr_close","ext_arr_open");
}

function JSDB(){
}
JSDB.prototype=new Object();
JSDB.prototype.setDB=function(db){
this.db=db;
};
JSDB.prototype.setIDs=function(_45){
this.prices=_45;
};
JSDB.prototype.getDropdownVals=function(arr,_47){
var res=new Array();
for(var i=1;i<arr.length;i++){
if(!res[arr[i][_47][0]]){
res[arr[i][_47][0]]=arr[i][_47][0];
}
}
return res;
};
JSDB.prototype.getColDesc=function(_4a){
for(var i=0;i<this.db.length;i++){
if(this.db[0][i]==_4a){
return i;
}
}
return -1;
};
JSDB.prototype.getConditionalDropdownVals=function(arr,_4d,_4e,_4f){
var res=new Array();
for(var i=1;i<arr.length;i++){
if(arr[i][_4e][0]==_4d){
var tmp=new Array();
tmp[0]=arr[i][_4f][0];
tmp[1]=arr[i][_4f][1];
res.push(tmp);
}
}
return res;
};
JSDB.prototype.findPrice=function(arr,_54){
for(var i=1;i<arr.length;i++){
var _56=_54.length;
for(var ii=0;ii<_54.length;ii++){
if(arr[i][this.getColDesc(_54[ii][0])][0]==_54[ii][1]){
_56--;
}
}
if(!_56){
return i;
}
}
return -1;
};
JSDB.prototype.kill=function(el){
var c=el.length;
for(var i=0;i<c;i++){
el.remove(0);
}
};
JSDB.prototype.createOptions=function(_5b,_5c){
var old=_5b.options[_5b.options.selectedIndex].value;
this.kill(_5b);
for(var i=0;i<_5c.length;i++){
newOption=document.createElement("option");
newOption.value=_5c[i][0];
if(cb.moz||cb.saf){
newOption.selected=(_5c[i][0]==old);
}
newOption.text=_5c[i][1];
if(cb.saf){
_5b.appendChild(newOption);
}else{
_5b.options.add(newOption);
}
}
if(cb.ie||cb.op){
for(var i=0;i<_5c.length;i++){
_5b.options[i].selected=(_5c[i][0]==old);
}
}
};
JSDB.prototype.connect=function(_5f,_60,_61,_62){
_5f.parent=this;
_5f.onchange=function(evt){
var p=this.parent;
p.createOptions(_61,p.getConditionalDropdownVals(p.db,_5f.options[_5f.options.selectedIndex].value,p.getColDesc(_60),p.getColDesc(_62)));
};
};

// ls - wishlist
  function selectAllCatEntries(selected) {
    var catEntryCheckbox;
    var i = 0;
	while (true) {
      catEntryCheckboxOutOfForm = document.getElementsByName("iiOutOfForm")[i];
      if (catEntryCheckboxOutOfForm) {
        catEntryCheckboxOutOfForm.checked = selected;
		i++;
      } else {
        break;
      }
	}
  }

  function setCatEntryIds() {
    var catEntryCheckbox;
    var minOneEntrySet = false;
    document.forms.MoveDeleteSendForm.productList.value = '';
    var i = 0;
	while (true) {
      catEntryCheckboxOutOfForm = document.getElementsByName("iiOutOfForm")[i];
      if (catEntryCheckboxOutOfForm) {
        var dynFormElement = "iiMoveDeleteSend_" + catEntryCheckboxOutOfForm.value
        var catEntryFieldInForm = document.getElementsByName(dynFormElement)[0];
        catEntryFieldInForm.value = catEntryCheckboxOutOfForm.checked ? 'true' : 'false';
        
        if (document.forms.MoveDeleteSendForm.productList.value != '') {
          document.forms.MoveDeleteSendForm.productList.value += ',';
        }
        document.forms.MoveDeleteSendForm.productList.value += catEntryCheckboxOutOfForm.value;
        
        if (catEntryCheckboxOutOfForm.checked) {
          minOneEntrySet = true;
          document.getElementsByName("artAmount" + catEntryCheckboxOutOfForm.value)[0].value = 
	          document.getElementsByName("initArtAmount" + catEntryCheckboxOutOfForm.value)[0].value;    
          
        } else {
          document.getElementsByName("artAmount" + catEntryCheckboxOutOfForm.value)[0].value = -1;    
        }
        
		i++;
      } else {
        break;
      }
	}
	return minOneEntrySet;
  }
  
  function disableFormElements() {
    var inputFields = document.getElementsByTagName("input");
    for (var i = 0; i < inputFields.length; i++) {
      inputFields[i].disabled = true;
    }
    inputFields = document.getElementsByTagName("select");
    for (var i = 0; i < inputFields.length; i++) {
      inputFields[i].disabled = true;
    }
    inputFields = document.getElementsByTagName("textarea");
    for (var i = 0; i < inputFields.length; i++) {
      inputFields[i].disabled = true;
    }
  }
  
  function checkAndSubmit(el)
  {
	if (el.value != 'iiSend') 
	{
		if (setCatEntryIds())
		{
			document.forms.MoveDeleteSendForm.submit();
		}
		else
		{
			el.selectedIndex = 0;
		}
	}
  }

////////////////////////////////////////////////////////////
// function to translate html umlauts
////////////////////////////////////////////////////////////  
function decodeHTML(text) {
	text = text.replace(/&auml;/, unescape("%E4"));
	text = text.replace(/&ouml;/, unescape("%F6"));
	text = text.replace(/&uuml;/, unescape("%Fc"));
	text = text.replace(/&amp;/, unescape("&"));
	return text;
}
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// function to fire an event on an elemnt identified by id
////////////////////////////////////////////////////////////
function fireEvent(el, eType) {
	if (document.createEvent) { 
		var event = document.createEvent('HTMLEvents'); 
		event.initEvent(eType, false, false); 
		el.dispatchEvent(event); 
	} else if (document.createEventObject) { 
		el.fireEvent('on' + eType); 
	} 
} 
////////////////////////////////////////////////////////////  

////////////////////////////////////////////////////////////
// function to highlight an element
////////////////////////////////////////////////////////////
function highlight(id)
{
	document.getElementById(id).className= "item_light";
}
function normal(id)
{
	document.getElementById(id).className= "item";
}

function fontReloadNDsIFR() {

	addClass(document.getElementsByTagName("body")[0], 'shopFont-hasFlash');

	audi_ngw.api.flash.sifr('body', 'h1.shopFontSIFR', 18, '#ffffff');
	audi_ngw.api.flash.sifr('body', 'h3.shopFontSIFR', 14, '#ffffff');
	audi_ngw.api.flash.sifr('body', 'h4.shopFontSIFR', 14, '#ffffff', true);
	audi_ngw.api.flash.sifr('body', 'h5.shopFontSIFR', 20, '#ffffff');
	audi_ngw.api.flash.sifr('body', 'h6.shopFontSIFR', 20, '#2e3036');
}

function addClass(element, stringToAdd) {
	var classNameToAdd=element.className;
	if(classNameToAdd==null)
		classNameToAdd=stringToAdd;
	else 
		classNameToAdd=classNameToAdd+(classNameToAdd==""?"":" ")+stringToAdd;
	element.className=classNameToAdd;
}

function alertOutOfModalLayer(url) {
	audi_ngw.api.closeModal();

	// only alert, if an url is given
	if (url != null && url != "") {
		var modalAlert = new Object();
		modalAlert.onOpen = function() {}
		modalAlert.onClose = function() {}	
		
		audi_ngw.api.openModal(url, modalAlert);
	}
}