var wss = {};
wss.images = new Array();
wss.webtrendsEnabled = false;
wss.pageIsReady = false;
wss.ieVersion = 0;

wss.checkDefaultText = function(ele, default_text) {
	if (ele.value == default_text)
		ele.value = "";
}
wss.trackFile = function(filename, title){
	var path = window.location.pathname;
	 if ( path.lastIndexOf("/") != path.length - 1 ) {
		 path += "/";
	}
	path += filename;
	this.trackUrl( path, title )
}
/* @param link URL or just path but no query parameters allowed! */
wss.trackUrl = function(){
	
	if(!this.webtrendsEnabled) return;
	
	var link = arguments[0];
	var title = arguments[1];
	var hostURL = window.location.protocol + "//" + window.location.hostname;
	if (link.indexOf(hostURL) == 0)
		ink = link.substr( hostURL.length );
	var dcsqryValue = "";
	if ( WT_OVERLAY_PARAMETER != "" )
		dcsqryValue = "?" + WT_OVERLAY_PARAMETER;
	// reset
	var params_reset = new Array ("WT.clip_t","WT.clip_n","WT.clip_ev","WT.es");
	var params_set = new Array ();
	for (var i=2; i < arguments.length; i=i+2) {
		params_set[params_set.length] = arguments[i];
	};
	for (var j=0; j < params_reset.length; j++) {
		var c_param = params_reset[j];
		var do_reset_param = true;
		for (var k=0; k < params_set.length; k++) {
			if ( params_set[k] == c_param) do_reset_param = false;
		}
		if (do_reset_param) {
			switch (c_param) {
				case "WT.clip_t":
					WT.clip_t = undefined;
					break;
				case "WT.clip_n":
					WT.clip_n = undefined;
					break;
				case "WT.clip_ev":
					WT.clip_ev = undefined;
					break;
				case "WT.es":
					WT.es = undefined;
					break;
			}
		}
	}
	// call dcsMultiTrack
	if (arguments.length == 2)
		dcsMultiTrack( "DCS.dcsuri", link, "WT.ti", title, "DCS.dcsqry", dcsqryValue );
	else if (arguments.length == 4)
		dcsMultiTrack( "DCS.dcsuri", link, "WT.ti", title, "DCS.dcsqry", dcsqryValue, arguments[2], arguments[3] );
	else if (arguments.length == 6)
		dcsMultiTrack( "DCS.dcsuri", link, "WT.ti", title, "DCS.dcsqry", dcsqryValue, arguments[2], arguments[3], arguments[4], arguments[5] );
	else if (arguments.length==8)
		dcsMultiTrack( "DCS.dcsuri", link, "WT.ti", title, "DCS.dcsqry", dcsqryValue, arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7] );
	else if (arguments.length==10)
		dcsMultiTrack( "DCS.dcsuri", link, "WT.ti", title, "DCS.dcsqry", dcsqryValue, arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9] );
}

// function tracks WebTrends and Google Analytics
wss.trackUrlMulti = function (link, title){
	this.trackUrl(link, title);
	// Google Analytics assumes that a variable pageTracker be defined.
	if ((pageTracker != null) && (pageTracker != undefined))
   		pageTracker._trackPageview(link);
}

wss.changeImg = function(name, aktiv){
	var image = document.images[name];
	var imgactive = document.images[aktiv];
	if (image != null && imgactive != null)
		image.src = eval(aktiv+'.src');
	return true;
}
// just NEC
wss.changeImgSrc = function(name, source){
	var image = document.images[name];
	if (image != null)
		  image.src = source;
	return true;
}
// view images
wss.viewImage = function(source,alt,language) {
	wss.imageview = new Image();
	wss.imageview.onload = function() {
		wss.openSupersizePicture(source,alt,language,wss.imageview.width,wss.imageview.height);		
	}
	wss.imageview.onerror = function() {
		alert('Sorry, file not found.')
	}
	wss.imageview.src = source;
}
wss.openSupersizePicture = function(picpath,picalt,picwidth,picheight,lang) {

	var picTitle = "SCHOTT";
	var closeCaption =  "Close<br>window";
	if (lang == "german")  closeCaption = "Fenster<br>schließen";
	if (picalt != "") picTitle += " - " + picalt;
	var windowWidth  = picwidth + 20;
	var windowHeight = picheight + 80;
	var myDate = new Date();
	var popupWindowName = "viewImage" + myDate.getTime();
	var popupWindowParams = 'width=' + windowWidth + ', height=' + windowHeight + ', resizable=no, scrollbars=auto, top=10, left=10';
	var w = window.open("", popupWindowName, popupWindowParams);
	w.document.write ("<html>\n<head>\n");
	w.document.write ("<title>"+picTitle+"</title>\n");
	w.document.write ("<link href='/css/schott.css' rel='stylesheet' type='text/css'>\n");
	w.document.write ("</head>\n");
	w.document.write ("<body style='margin:0; padding:0;'>\n");
	w.document.write ("<p style=\"width:" + windowWidth + "px;margin:10px 0px;text-align:center;\"><img src='"+picpath+"' width='"+picwidth+"' height='"+picheight+"' alt='"+picalt+"' style=\"margin:0px;padding:0px;\"></p>\n");
	w.document.write ("<p style=\"width:"+windowWidth+"px;margin:0px;margin-top:20px;text-align:center;\"><a class='blue' href='#' onclick='self.close();'>"+varCloseWindow+"</a></p>");
	w.document.write ("\n</body>\n</html>");
	w.focus();
}
// preload images
wss.preload = function(source) {
	var ni = new Image();
	ni.src = source;
	this.images.push(ni);
}
//Popup Tubing Produktselektor (referenced outside of SVN)
wss.openSelectorProduct = function(glassID) {
	var w = window.open(
		'/flash/tubing/selector/popup.php?glassid='+glassID,
		'Product',
		'width=800,height=645,left=120,top=120,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no'
	);
    w.focus();	
}
wss.openSelectorGroup = function(groupID) {
	var w = window.open(
		'/flash/tubing/selector/popup.php?appid='+groupID,
		'Product',
		'width=800,height=645,left=120,top=120,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no'
	);
    w.focus();	
}

// temporary replacements
function funcOpenProduct(glassID){
	wss.openSelectorProduct(glassID);
}
function funcOpenGroup(groupID){
	wss.openSelectorGroup(groupID);
}
function track_url(a,b) {
	wss.trackUrl(a,b);
}
