

/**********************************
**** TD InjectRandom 20080409 *****
**********************************/

if (typeof(TD) == "undefined") TD = {};

TD.Inject = Class.create();
TD.Inject.prototype = {
	initialize: function() {	
		if (arguments.length > 0 && typeof(arguments[arguments.length-1]) == 'object') {
			window.onload = this.randomizeContent.bind(this, arguments);
		}
		else if (arguments.length > 0) {
			this.renderInline(arguments[Math.floor(Math.random() * arguments.length)]);
		}
	},
	randomizeContent: function(args) {	
		var randNum = Math.floor(Math.random() * (args.length-1));	
		this.renderToContainer($(args[args.length-1].container), args[randNum]);
	},
	renderToContainer: function(container, content) {
		container.innerHTML = content;
	},
	renderInline: function(content) {
		document.write(content);
	}
};



/***************************************
**** TD Hide Mail Address 20080610 *****
***************************************/

function showmail(name) {
        var domain = "target-distribution";
		var toplevel = "com"
window.location.href = "mai" + "lto:" + name + "@" + domain + "." + toplevel;
}

function showmoremail(name,subject) {
		var domain = "target-distribution";
		var toplevel = "com"
window.location.href = "mai" + "lto:" + name + "@" + domain + "." + toplevel + "?subject=" + subject;
}



/*************************************
**** TD changeimgsource 20080409 *****
*************************************/

function changeimgsource(data){
	imgsource = data.firstChild.src;
	var sourcestring = data.firstChild.src.substr(0,data.firstChild.src.length-4);
	var matchstr = sourcestring.search(/back/);
	if(matchstr < 0){
		newsource = sourcestring+"_back.png";
		data.firstChild.src = newsource;
	} else {
		newsource = sourcestring.substr(0,data.firstChild.src.length-9)+".png";
		data.firstChild.src = newsource;
	};
}

/******************************
**** TD MoveSwap 20080508 *****
******************************/

Effect.MoveSwap = function(container){
	//set box maximum
	var maxbox = 4;
	//set check value for standard box
	var boxcheck = "box";
	//set check value for detailbox
	var boxcheckdetail = "detailbox";
	//get id of parent div
	var movebox = container.parentNode.id;
	//set move distance
	var hmove = -212;
	//set effects queue
	var queue = Effect.Queues.get('menuScope');
	//Visibility counter
	var viscounter = 0;
	for(i=0;i<maxbox;i++){
		if(Element.visible(boxcheck+i)==true){viscounter++;}
	}
	//loop for moving the selected box
	for(i=0;i<maxbox;i++){
		var checkbox = boxcheck+i;
		var detailbox = boxcheckdetail+i;
		var backsymbol = "backsym"+i;
		//alert(checkbox);
		if(checkbox == movebox){
			//check if corresponding box are visible
			if(viscounter>1){
				//calculate effective moving distance
				var effectivehmove = hmove*i;
				//move the box
				if(queue.toArray().length<1){
					new Effect.Move (movebox,{duration:0.3, x: effectivehmove, y: 0, mode: 'relative',queue:{position:'end',scope:'menuScope',limit:1}});
				}
				//subloop for fading the other boxes
				for(i=0;i<maxbox;i++){
					var checkfadebox = boxcheck+i;
					if(checkfadebox !== movebox){
						//check if corresponding box are visible
						if(viscounter>1){
							if(queue.toArray().length<4){
								new Effect.Fade(checkfadebox,{duration:0.1,queue:{scope:'menuScope',limit:4}});
							}
						}
					}
				}
				if(queue.toArray().length<6){
				//appear detailbox
				new Effect.Appear(detailbox,{duration:0.1,queue:{position:'end',scope:'menuScope',limit:6}});	
				//appear go-back symbol
				new Effect.Appear(backsymbol,{duration:0.1,queue:{position:'end',scope:'menuScope',limit:6}});	
				}
			//else move box back to orgin and let the boxes appear again
			} else {
				//calculate effective moving distance
				var effectivehmove = (hmove*i)*-1;
				if(queue.toArray().length<1){
					//fade go-back symbol
					new Effect.Fade(backsymbol,{duration:0.1,queue:{position:'front',scope:'menuScope',limit:3}});
					//move box back
					new Effect.Move(movebox,{duration:0.3, x: effectivehmove, y: 0, mode: 'relative',queue:{position:'end',scope:'menuScope',limit:3}});
					//fade detailbox
					new Effect.Fade(detailbox,{duration:0.1,queue:{position:'front',scope:'menuScope',limit:3}});
					//subloop for fading the other boxes
					for(i=0;i<maxbox;i++){
						var checkfadebox = boxcheck+i;
						if(checkfadebox !== movebox){
							//check if corresponding box are visible
							if(viscounter=1){
								if(queue.toArray().length<6){
									//let boxes appear
									new Effect.Appear(checkfadebox,{duration:0.1,queue:{scope:'menuScope',limit:6}});
								}
							}
						}
					}
				}
			}
		}
	}
}

/*****************************
**** TD DivSwap 20080409 *****
*****************************/

Effect.divSwap = function(element,container){
    var div = document.getElementById(container);
    var nodeList = div.childNodes;
    var queue = Effect.Queues.get('menuScope');
	//check if target div is visible
    if(queue.toArray().length<1){
        //hide target div
		if(Element.visible(element)==true){
		Effect.SlideUp(element,{duration:0.4,queue:{position:'end',scope:'menuScope',limit:2}})
		}
		//check if target div is invisible
		if(Element.visible(element)==false){
            //check if other sliders are opened, loops through all divs in container
			for(i=0;i<nodeList.length;i++){
                if(nodeList.item(i).nodeName=="DIV" && nodeList.item(i).id!=element){
                    //close slider if open
					if(Element.visible(nodeList.item(i))==true){
                        //hide slider
						Effect.SlideUp(nodeList.item(i),{duration:0.4,queue:{position:'end',scope:'menuScope',limit:2}})
                    }
                }
            }
			//show target div
            Effect.SlideDown(element,{duration:0.4,queue:{position:'end',scope:'menuScope',limit:2}})
       }
   }
}


/*************************************
**** TD Form Validation 20080409 *****
*************************************/

function checknewcust(){
	var alarm=0;
	//search for input fields
	if (!document.getElementsByTagName){ return;}
	var inputfields = document.getElementsByTagName('input');
	var selectfields = document.getElementsByTagName('select');
	var textareafields = document.getElementsByTagName('textarea');
	
	// loop through all input tags
	for (var i=0; i<(inputfields.length-1); i++){
		var inputfield = inputfields[i];
		var relAttribute = String(inputfield.getAttribute('rel'));
		var idAttribute = String(inputfield.getAttribute('id'));	
		// use the string.match() method to catch 'td_control' references in the rel attribute
		if ((relAttribute.toLowerCase().match('td_control'))){
			//check if inputfield is empty
			if (inputfield.value ==""){
				//change inputfieldcolor
				alarm = alarm + 1;
				//inputfield.setStyle({background:'#ffcccc'});
				inputfield.style.background = "#ffcccc";
			} else {
				//change inputfieldcolor
				//inputfield.setStyle({background:'#FFFFFF'});
				inputfield.style.background = "#ffffff";
			}
		}
		
	}
	
	// loop through all select tags
	for (var i=0; i<selectfields.length; i++){
		var selectfield = selectfields[i];
		var relAttribute = String(selectfield.getAttribute('rel'));
		// use the string.match() method to catch 'td_control' references in the rel attribute
		if ((relAttribute.toLowerCase().match('td_control'))){
			//check if selectfield is empty
			if (selectfield.value ==""){
				//change selectfieldcolor
				alarm = alarm + 1;
				//selectfield.setStyle({background:'#ffcccc'});
				inputfield.style.background = "#ffcccc";
			} else {
				//change inputfieldcolor
				//selectfield.setStyle({background:'#FFFFFF'});
				inputfield.style.background = "#ffffff";
			}
		}
	}	
	
	// loop through all textarea tags
	for (var i=0; i<textareafields.length; i++){
		var textareafield = textareafields[i];
		var relAttribute = String(textareafield.getAttribute('rel'));
		// use the string.match() method to catch 'td_control' references in the rel attribute
		if ((relAttribute.toLowerCase().match('td_control'))){
			//check if textareafield is empty
			if (textareafield.value ==""){
				//change textareafieldcolor
				alarm = alarm + 1;
				textareafield.style.background = "#ffcccc";
			} else {
				//change textareafieldcolor
				textareafield.style.background = "#ffffff";
			}
		}
	}	
	// tempcheck() and function tempcheck can be removed after rma prozess runs via target online
	tempcheck();
	if ($('control').checked==false && alarm == 0) {alert(unescape('Sie m%FCssen die rechtlichen Bestimmungen akzeptieren')); return false;};
	if (alarm > 0) {alert(unescape('Bitte f%FCllen Sie alle markierten Felder aus')); return false} else {if (!emailcheck()) {return false;}};
	
}

function tempcheck(){
	if($('grund') == undefined){}
	else {
		if($('grund').value == "") {$('grund').style.background = "#ffcccc";}
		else {$('grund').style.background = "#ffffff";}
	}
}

function emailcheck(){
	//search for input fields
	if (!document.getElementsByTagName){ return;}
	var inputfields = document.getElementsByTagName('input');
	var counter = 0;
	// loop through all input tags
	for (var i=0; i<(inputfields.length-1); i++){
		var inputfield = inputfields[i];
		var idAttribute = String(inputfield.getAttribute('id'));	
		// check if field is disabled
		if(!inputfield.disabled){
			// use the string.search() method to catch 'emailadresse' references in the id attribute
			if ((idAttribute.toLowerCase().search('emailadresse')) != -1){
				var emailPat = /(.+)@(.+)/;
				var emailfieldvalue = document.getElementById(idAttribute).value;
				var matchArray = emailfieldvalue.match(emailPat);
				if (matchArray == null) {
    				//alert(unescape('Ihre Emailadresse ist ung%FCltig. Bitte %FCberpruefen Sie die Eingabe.'));
					counter = counter + 1;
					inputfield.style.background = "#ffcccc";
				}
			}
		}
	}
	if (counter == 1){alert(unescape('Ihre Emailadresse ist ung%FCltig. Bitte %FCberpruefen Sie die Eingabe.'))}
	if (counter == 2){alert(unescape('Eine oder mehrere Emailadressen sind ung%FCltig. Bitte %FCberpruefen Sie die Eingabe.'))}
	if (counter > 0) {return false} else {return true};
}

