/***********************************************************
 * Global JavaScript Library for WittGroup
 *
 * Copyright by Josef Witt GmbH, Weiden
 * 
 * $Id: common.js 77062 2011-07-01 07:28:10Z marpor $
 ***********************************************************/
<!--

// ----------------------------
// global definitions
// ----------------------------
var PARAMETER_START = "/_/";

var URL_PARAMETER_GW_NAME = "gw";
var URL_PARAMETER_SESSIONID_SEPERATOR = ";";
var URL_PARAMETER_SESSIONID = "jsessionid";
var SESSIONID_COOKIE_NAME = "JSESSIONID";

// ----------------------------
// check user for cookie
// ----------------------------
function userHasCookie(name) {		
	if(document.cookie.indexOf(name) != -1) {
		// DEBUG: alert("User has Cookie " + name)
		return true;
	} 
	else
	{
		return false;
	}	
}

// ----------------------------
// read a cookie value
// ----------------------------
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {			
			value = c.substring(nameEQ.length,c.length);
			// DEBUG: alert("Cookie " + name + " has value: " + value);
			return value;
		}
	}
	return null;
}


// ----------------------------
// write a cookie
// ----------------------------
function writeCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	cookievalue = name+"="+value+expires+"; path=/";
	document.cookie = cookievalue;
	// DEBUG: alert("Cookie " + name + " has been written: " + cookievalue);
}


// ----------------------------
// delete a cookie
// ----------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}


// ----------------------------
// get the sessionid
// ----------------------------
function getSessionId() {
	if(document.cookie) {
		// get session id from cookie
		sessionID = readCookie(SESSIONID_COOKIE_NAME);
		if (sessionID != null) {			
			return sessionID;
		}
	}
	else {
		// get session id from url
		path = document.URL; 
		sessionid_param = URL_PARAMETER_SESSIONID_SEPERATOR + URL_PARAMETER_SESSIONID + "=";
		position = path.lastIndexOf(sessionid_param);
	
		if (position > 0) {
			sessionId = path.substr(position + sessionid_param.length, path.length);
			return sessionId;
		}
		else {
			return null;
		}
	}
}


// ----------------------------
// checks if url has parameters
// ----------------------------
function parametersInUrl() {	
	if (document.URL.indexOf(PARAMETER_START) != -1) {
		return true;
	}
	else {
		return false;
	}
}


// ----------------------------
// get parameters from url
// ----------------------------
function getParameterArray() {
	if (parametersInUrl()) {
		start = document.URL.indexOf(PARAMETER_START) + PARAMETER_START.length;
		end = document.URL.lastIndexOf("/");
		parameters = document.URL.substring(start, end);		
		return parameters.split("/");
	}
	else {
		return null;
	}
}

//----------------------------
// get parameters from url
//----------------------------
function getParameterString() {
	if (parametersInUrl()) {
		start = document.URL.indexOf(PARAMETER_START) + PARAMETER_START.length;
		end = document.URL.lastIndexOf("/");
		parameters = document.URL.substring(start, end);		
		return parameters;
	}
	else {
		return null;
	}
}

// ----------------------------
// get page
// ----------------------------
function getCalledHTMLPage() {

	path = document.URL; 
	
	// remove session id
	sid = path.lastIndexOf(URL_PARAMETER_SESSIONID);
	if (sid != -1) {
		path = path.substring(0, sid);
	}

	pipe = path.lastIndexOf("/");
	path = path.substring(pipe + 1, path.length);

	return path;
}


// ----------------------------
// get the host
// ----------------------------
function getHost() {
	return document.location.host;
}

// ----------------------------
// get the hostname
// ----------------------------
function getHostName() {
	return document.location.hostname;
}

// ----------------------------
// get the port
// ----------------------------
function getPort() {
	return document.location.port;
}

// ----------------------------
// get the browser engine
// ----------------------------
function getBrowserEngine() {
	return navigator.appCodeName;
}


// ----------------------------
// get the browser name
// ----------------------------
function getBrowserName() {
	return navigator.appName;
}


// ----------------------------
// get the browser version
// ----------------------------
function getBrowserVersion() {
	return navigator.appVersion;
}


// -----------------------------
// check if cookies are enabled
// -----------------------------
function cookiesEnabled() {
	if(document.cookie || navigator.cookieEnabled) {
		return true;
	}
	
	return false;
}


// ----------------------------
// get the browser language
// ----------------------------
function getBrowserLanguage() {
	return navigator.language;
}


// ----------------------------
// get the system platform
// ----------------------------
function getSystemPlatform() {
	return navigator.platform;
}

// ----------------------------
// get the cpu class
// ----------------------------
function getCpuClass() {
	return navigator.platform;
}


// ----------------------------
// get java enabled
// ----------------------------
function javaEnabled() {
	return navigator.javaEnabled;
}


// ----------------------------
// get user agent
// ----------------------------
function getUserAgent() {
	return navigator.userAgent;
}


// ----------------------------------
// get protocoll (http, https, ...)
// ----------------------------------
function getProtocol() {
	protocol = document.location.protocol;
	protocol = protocol.replace(":", "");
	return protocol;
}


// ----------------------------
// get screen resolution 
// ----------------------------
function getResolution() {
	resol = screen.width + "x" + screen.height;
	return resol;
}

//----------------------------
// is flash plugin installed
//----------------------------
function flashInstalled() {
	
	flash = "false";
	
	try {
		var agent = navigator.userAgent.toLowerCase(); 
		
		if ((navigator.plugins) && (navigator.plugins.length > 0)) {
			for (a = 0; a < navigator.plugins.length; a++) {	
				if ((navigator.plugins[a].name.indexOf('flash') != -1) && (parseint(navigator.plugins[a].name) >= 4)) {
					flash = "true";
					break;
				}
			}
		}
		else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1) {
			document.write('<scr' + 'ipt language="VBScript"\> \n');
			document.write('on error resume next \n');
			document.write('dim useFlash \n');
			document.write('set useFlash = CreateObject("ShockwaveFlash.ShockwaveFlash") \n');
			document.write('if IsObject(useFlash) then \n');
			document.write('flash = \"true\" \n');
			document.write('end if');
			document.write('</scr' + 'ipt\> \n');
		}
	} catch (e) {
	}
			
	return flash;
}

//----------------------------
// get flash plugin version
//----------------------------
function getFlashVersion() {
	
	version = "";
	
	try {	
		var agent = navigator.userAgent.toLowerCase(); 
	 	
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			for (a = 0; a < navigator.plugins.length; a++) {	
				if ((navigator.plugins[a].name.indexOf('flash') != -1) && (parseint(navigator.plugins[a].name) >= 4)) {
					version = navigator.plugins[a].description;
					break;
				}
			}
		}
		else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1) {
			document.write('<scr' + 'ipt language="VBScript"\> \n');
			document.write('on error resume next \n');
			document.write('version = 20 \n');
			document.write('Do While version >= 1 \n');
			document.write('On Error Resume Next \n');
			document.write('Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & version) \n');
			document.write('if IsObject(obFlash) then \n');		
			document.write('Exit Do \n');
			document.write('End If \n');
			document.write('version = version - 1 \n');
			document.write('Loop \n');
			document.write('</scr' + 'ipt\> \n');
		}
	} catch (e) {
	}
	
	return version;
}


// ----------------------------
// get path decoration
// ----------------------------
function getPathDecoration() {
	start = document.URL.indexOf(getHost()) + getHost().length;
	if (parametersInUrl()) {
		end = document.URL.indexOf(PARAMETER_START);
	}
	else {
		end = document.URL.lastIndexOf("/");
	}
	return document.URL.substring(start, end);
}


// ----------------------------
// get the referrer
// ----------------------------
function getReferrer() {
	referrer = document.referrer;	
	if (referrer.length > 0) {
		start = referrer.indexOf("://") + 3;				
		if (start == -1) {
			// uri without protocol
			start = 0;		
			end = referrer.indexOf("/");			
		}
		else {
			// uri with protocol
			referrer_without_protocol = referrer.substring (start, referrer.length);
			end = referrer_without_protocol.indexOf("/") + start;			
		}
		
		referrer = referrer.substring(0, end);
	}	
	return referrer;
}


// ---------------------------------
// check if parameter gw is in url
// ---------------------------------
function isGwParameterInUrl() {	
	
	returnValue = false;
	
	// check if GW parameter in OSecom Style is available
	returnValue = isOsecomGwParameterInUrl();	
	
	if (returnValue == false) {
		// check if GW parameter as Standard URL parameter is available
		returnValue = isStandardURLGwParameterInUrl();
	}
		
	return returnValue;	
}

function isStandardURLGwParameterInUrl() {
	// ... ?GW=...	
	if (document.URL.indexOf(URL_PARAMETER_GW_NAME.toLowerCase() + "=") != -1
		|| document.URL.indexOf(URL_PARAMETER_GW_NAME.toUpperCase() + "=") != -1) {		
		return true;
	}
	
	return false;
}

function isOsecomGwParameterInUrl() {
	// .../_/gw/.../	
	if (document.URL.indexOf("/" + URL_PARAMETER_GW_NAME.toLowerCase() + "/") != -1
		|| document.URL.indexOf("/" + URL_PARAMETER_GW_NAME.toUpperCase() + "/") != -1) {		
		return true;
	}
	
	return false;
}

// ---------------------------------
// get gw parameter from url
// ---------------------------------
function getGwParameter() {
	if (isOsecomGwParameterInUrl()) {
	 	 lowerurl = document.URL.toLowerCase();
		 start = lowerurl.indexOf("/" + URL_PARAMETER_GW_NAME.toLowerCase() + "/") + URL_PARAMETER_GW_NAME.length + 2;	 
		 gwurl = lowerurl.substring(start, lowerurl.length);	 
		 end = gwurl.indexOf("/");

		 value = gwurl.substring(0,end);		 
		 return value;
	}
	else if (isStandardURLGwParameterInUrl()) {
		lowerurl = document.URL.toLowerCase();
		start = lowerurl.indexOf(URL_PARAMETER_GW_NAME.toLowerCase() + "=") + URL_PARAMETER_GW_NAME.length + 1;		
		gwurl = lowerurl.substr(start, 9);	 		
		return gwurl;
	}
	else {
		return RETURNVALUE_NOT_DEFINED;
	}
}

// --------------------------------------------------
// Preventing double submit by hiding submit button
// --------------------------------------------------
function hideButtons(){
	if (document.getElementById('submitButton')) {
		document.getElementById('submitButton').style.display='none';
	}
	
	if (document.getElementById('submitButtonDown')) {
		document.getElementById('submitButtonDown').style.display='none';
	}
}

//--------------------------------------------------
// Hide an element
//--------------------------------------------------
function hideElement(elementName){
	if (document.getElementById(elementName)) {
		document.getElementById(elementName).style.display='none';
	}
}

// ------------------------------------
//  get Live-Host
// ------------------------------------
function getLiveHost(sourceURL) {

	if (sourceURL.indexOf("clde") != -1 || sourceURL.indexOf("creation-l.de") != -1) {
		host = "www.creation-l.de";
	}
	else if (sourceURL.indexOf("wwde") != -1 || sourceURL.indexOf("witt-weiden.de") != -1) {
		host = "www.witt-weiden.de";
	}
	else if (sourceURL.indexOf("wwat") != -1 || sourceURL.indexOf("witt-weiden.at") != -1) {
		host = "www.witt-weiden.at";
	}
	else if (sourceURL.indexOf("wwch") != -1 || sourceURL.indexOf("witt-weiden.ch") != -1) {
		host = "www.witt-weiden.ch";
	}
	else if (sourceURL.indexOf("sade") != -1 || sourceURL.indexOf("sieh-an.de") != -1) {
		host = "www.sieh-an.de";
	}
	else if (sourceURL.indexOf("saat") != -1 || sourceURL.indexOf("sieh-an.at") != -1) {
		host = "www.sieh-an.at";
	}
	else if (sourceURL.indexOf("sach") != -1 || sourceURL.indexOf("sieh-an.ch") != -1) {
		host = "www.sieh-an.ch";
	}
	else if (sourceURL.indexOf("sanl") != -1 || sourceURL.indexOf("your-look-for-less.nl") != -1) {
		host = "www.your-look-for-less.nl";
	}
	else if (sourceURL.indexOf("sait") != -1 || sourceURL.indexOf("modavilona.it") != -1) {
		host = "www.modavilona.it";
	}
	else if (sourceURL.indexOf("amde") != -1 || sourceURL.indexOf("ambria.de") != -1) {
		host = "www.ambria.de";
	}
	else if (sourceURL.indexOf("wicz") != -1 || sourceURL.indexOf("witt-international.cz") != -1) {
		host = "www.witt-international.cz";
	}
	else if (sourceURL.indexOf("wpde") != -1 || sourceURL.indexOf("waeschepur.de") != -1) {
		host = "www.waeschepur.de";
	}
	else if (sourceURL.indexOf("winl") != -1 || sourceURL.indexOf("witt-international.nl") != -1) {
		host = "www.witt-international.nl";
	}
	else if (sourceURL.indexOf("wiua") != -1 || sourceURL.indexOf("witt-international.com.ua") != -1) {
		host = "www.witt-international.com.ua";
	}
	else {
		host = getHost();
	}
	
	return host;
}


// ------------------------------------
//  get Stage-Host
// ------------------------------------
function getStageHost(sourceURL) {

	if (sourceURL.indexOf("clde") != -1 || sourceURL.indexOf("creation-l.de") != -1) {
		host = "stage.creation-l.de";
	}
	else if (sourceURL.indexOf("wwde") != -1 || sourceURL.indexOf("witt-weiden.de") != -1) {
		host = "stage.witt-weiden.de";
	}
	else if (sourceURL.indexOf("wwat") != -1 || sourceURL.indexOf("witt-weiden.at") != -1) {
		host = "stage.witt-weiden.at";
	}
	else if (sourceURL.indexOf("wwch") != -1 || sourceURL.indexOf("witt-weiden.ch") != -1) {
		host = "stage.witt-weiden.ch";
	}
	else if (sourceURL.indexOf("sade") != -1 || sourceURL.indexOf("sieh-an.de") != -1) {
		host = "stage.sieh-an.de";
	}
	else if (sourceURL.indexOf("saat") != -1 || sourceURL.indexOf("sieh-an.at") != -1) {
		host = "stage.sieh-an.at";
	}
	else if (sourceURL.indexOf("sach") != -1 || sourceURL.indexOf("sieh-an.ch") != -1) {
		host = "stage.sieh-an.ch";
	}
	else if (sourceURL.indexOf("sanl") != -1 || sourceURL.indexOf("your-look-for-less.nl") != -1) {
		host = "stage.your-look-for-less.nl";
	}
	else if (sourceURL.indexOf("sait") != -1 || sourceURL.indexOf("modavilona.it") != -1) {
		host = "stage.modavilona.it";
	}
	else if (sourceURL.indexOf("amde") != -1 || sourceURL.indexOf("ambria.de") != -1) {
		host = "stage.ambria.de";
	}
	else if (sourceURL.indexOf("wicz") != -1 || sourceURL.indexOf("witt-international.cz") != -1) {
		host = "stage.witt-international.cz";
	}
	else if (sourceURL.indexOf("wpde") != -1 || sourceURL.indexOf("waeschepur.de") != -1) {
		host = "stage.waeschepur.de";
	}
	else if (sourceURL.indexOf("winl") != -1 || sourceURL.indexOf("witt-international.nl") != -1) {
		host = "stage.witt-international.nl";
	}
	else if (sourceURL.indexOf("wiua") != -1 || sourceURL.indexOf("witt-international.com.ua") != -1) {
		host = "stage.witt-international.com.ua";
	}
	else {
		host = getHost();
	}
	
	return host;
}

// ------------------------------------
//  get Shopmanagement-Host
// ------------------------------------
function getShopmanagementHost(sourceURL) {

	if (sourceURL.indexOf("clde") != -1 || sourceURL.indexOf("creation-l.de") != -1) {
		host = "clde-sm";
	}
	else if (sourceURL.indexOf("wwde") != -1 || sourceURL.indexOf("witt-weiden.de") != -1) {
		host = "wwde-sm";
	}
	else if (sourceURL.indexOf("wwat") != -1 || sourceURL.indexOf("witt-weiden.at") != -1) {
		host = "wwat-sm";
	}
	else if (sourceURL.indexOf("wwch") != -1 || sourceURL.indexOf("witt-weiden.ch") != -1) {
		host = "wwch-sm";
	}
	else if (sourceURL.indexOf("sade") != -1 || sourceURL.indexOf("sieh-an.de") != -1) {
		host = "sade-sm";
	}
	else if (sourceURL.indexOf("saat") != -1 || sourceURL.indexOf("sieh-an.at") != -1) {
		host = "saat-sm";
	}
	else if (sourceURL.indexOf("sach") != -1 || sourceURL.indexOf("sieh-an.ch") != -1) {
		host = "sach-sm";
	}
	else if (sourceURL.indexOf("sanl") != -1 || sourceURL.indexOf("your-look-for-less.nl") != -1) {
		host = "sanl-sm";
	}
	else if (sourceURL.indexOf("sait") != -1 || sourceURL.indexOf("modavilona.it") != -1) {
		host = "sait-sm";
	}
	else if (sourceURL.indexOf("amde") != -1 || sourceURL.indexOf("ambria.de") != -1) {
		host = "amde-sm";
	}
	else if (sourceURL.indexOf("wicz") != -1 || sourceURL.indexOf("witt-international.cz") != -1) {
		host = "wicz-sm";
	}
	else if (sourceURL.indexOf("wpde") != -1 || sourceURL.indexOf("waeschepur.de") != -1) {
		host = "wpde-sm";
	}
	else if (sourceURL.indexOf("winl") != -1 || sourceURL.indexOf("witt-international.nl") != -1) {
		host = "winl-sm";
	}
	else if (sourceURL.indexOf("wiua") != -1 || sourceURL.indexOf("witt-international.com.ua") != -1) {
		host = "wiua-sm";
	}
	else {
		host = getHost();
	}
	
	return host;
}

// ------------------------------------
//  get Context
// ------------------------------------
function getServerContext(sourceURL) {

	if (sourceURL.indexOf("/clde/") != -1) {
		context = "/clde";
	}
	else if (sourceURL.indexOf("/wwde/") != -1) {
		context = "/wwde";
	}
	else if (sourceURL.indexOf("/wwat/") != -1) {
		context = "/wwat";
	}
	else if (sourceURL.indexOf("/wwch/") != -1) {
		context = "/wwch";
	}
	else if (sourceURL.indexOf("/sade/") != -1) {
		context = "/sade";
	}
	else if (sourceURL.indexOf("/saat/") != -1) {
		context = "/saat";
	}
	else if (sourceURL.indexOf("/sach/") != -1) {
		context = "/sach";
	}
	else if (sourceURL.indexOf("/sanl/") != -1) {
		context = "/sanl";
	}
	else if (sourceURL.indexOf("/sait/") != -1) {
		context = "/sait";
	}
	else if (sourceURL.indexOf("/amde/") != -1) {
		context = "/amde";
	}
	else if (sourceURL.indexOf("/wicz/") != -1) {
		context = "/wicz";
	}
	else if (sourceURL.indexOf("/wpde/") != -1) {
		context = "/wpde";
	}
	else if (sourceURL.indexOf("/winl/") != -1) {
		context = "/winl";
	}
	else if (sourceURL.indexOf("/wiua/") != -1) {
		context = "/wiua";
	}
	else {
		context = "";
	}
	
	return context;
}

//------------------------------------
// check the search query
//------------------------------------
function checkSearchQuery(defaultInputFieldText) {
	query = document.getElementById('query').value;				
	if (query == defaultInputFieldText) {
		return false;
	}
	return true;
}

function checkQuery(defaultInputFieldText, inputId) {
	query = document.getElementById(inputId).value;				
	if (query == defaultInputFieldText) {
		return false;
	}
	return true;
}

//------------------------------------
// scroll to the given html value in a site
// example: scrollToPosition( "h1", "Blazer" );
//------------------------------------
function scrollToPosition( tag, value ) { 
	
	var htmlTag = $(tag); 
	var htmlValue = $(value);
	
	$( htmlTag ).each( function( index ) {
	   if( ($(this).html())==( value ) ){

			$('html,body').animate({
				scrollTop: $(this).offset().top
			}, 2000 , function (){location.hash = $(this);});		  
	   }
	});
} 

//-------------------------------------------------
// -- global readyHandler() function --
// should be invoked in each REAL readyHandler 
// in the specific site 
//-------------------------------------------------
function readyHandler() {
}
-->
