//Coop Utilities
//Create Utilities by putting <script language="JavaScript">createUtilities('de');</script> at desired location
//Implemented by Futurecom interactive, rmi, 02.2007

//declare variables with global scope
//Images

//Home, Contact, Search (images left of the textbox. Image-URLs will be set in createUtilities())
ImgSpacer = new Image();
ImgVerticalLine = new Image();
ImgHomeLow = new Image();
ImgHomeHi = new Image();
ImgContactLow = new Image();
ImgContactHi = new Image();
ImgSearchLow = new Image();
URLContact = 'http://www.coop.ch/homepage/homepage/kontakt.cfm?sprache='; //Language will be added automatically
URLHome = 'http://www.coop.ch/?lang=';

//Search Form
var FormActionURL = 'http://suche.coop.ch/coop-suche/search.jsp';
var FormMethod = 'get';
var FormName = 'searchUtitlities';
var FormSite = 'default';
var FormSendButtonURL = 'http://www.coop.ch/utilities/images/img_pfeil_grau.gif';
var FormTextFieldStyleString = 'width: 112px; height: 19px; font-size: 9px; position: relative; top: -7px;';
var FormStartTag = '<form name="'+FormName+'" method="'+FormMethod+'" action="'+FormActionURL+'" style="margin:0px;">';
var FormEndTag = '</form>';
var NewLine = '\n';

//HTML
//Tables
var HTMLOutput = '';
var TblUtilitiesStart = '<table border="0" cellspacing="0" cellpadding="0">';
var TblEnd = '</table>';
var TRStart = '<tr>';
var TREnd = '</tr>';
var TD = '';
var TDEnd = '</td>';
var TDContent = '';

//Functions
function changeImage(bildnr,bildobj) {
	//swap image (hi/lo)
    window.document.images[bildnr].src = bildobj.src;
}

function createTDStart(strAlign, strVAlign, strColSpan, strRowSpan, strCssClass, strCssStyle)
{
	//creates Start-Tag "<td>"
	var TDNew = '<td';
	
	if(strAlign != '')
		TDNew += ' align="'+strAlign+'"';
	if(strVAlign != '')
		TDNew += ' valign="'+strVAlign+'"';
	if(strColSpan != '')
		TDNew += ' colspan="'+strColSpan+'"';
	if(strRowSpan != '')
		TDNew += ' rowspan="'+strRowSpan+'"';
	if(strCssClass != '')
		TDNew += ' class="'+strCssClass+'"';
	if(strCssStyle != '')
		TDNew += ' style="'+strCssStyle+'"';
	
	TDNew += '>';
	
	return TDNew;
}

function createImage(strPath, strWidth, strHeight, strBorder, strAlt, strName)
{
	//creates Image
	var ImgNew = '<img src="'+strPath+'"';
	
	if(strWidth != '')
		ImgNew += ' width="'+strWidth+'"';
	if(strHeight != '')
		ImgNew += ' height="'+strHeight+'"';
	strBorder != '' ? ImgNew += ' border="'+strBorder+'"' : ImgNew += ' border="0"';
	ImgNew += ' alt="'+strAlt+'" title="'+strAlt+'"';
	if(strName != '')
		ImgNew += ' name="'+strName+'"';
	
	ImgNew += '>';
	
	return ImgNew;
}

function createLink(strURL, strTarget, strMouseOver, strMouseOut, strAltText, strText)
{
	//creates Link
	var LnkNew = '<a href="'+strURL+'"';
	
	if(strTarget != '')
		LnkNew += ' target="'+strTarget+'"';
	if(strMouseOver != '')
		LnkNew += ' onmouseover="'+strMouseOver+'"';
	if(strMouseOut != '')
		LnkNew += ' onmouseout="'+strMouseOut+'"';
		
	LnkNew += '>';
	LnkNew += strText + '</a>';
	
	return LnkNew;
} 

function createInputField(strName, strType, strValue, strStyle)
{
	//creates Input-Field
	var InputNew = '<input name="'+strName+'" type="'+strType+'" value="'+strValue+'"';
	if(strStyle != '')
		InputNew += ' style="'+strStyle+'"';
	InputNew += '>';
	return InputNew;
}

//Main function
function createUtilities(strLanguage)
{
	//creates Utilites
	//strLanguage: de, fr, it
	
	var LanguageShort = strLanguage.substring(0,1); //for language specific images (de -> d, fr -> f, it -> i)
	
	//URL Images (hi/lo)
	ImgSpacer.src = 'http://www.coop.ch/utilities/images/platz.gif';
	ImgVerticalLine.src = 'http://www.coop.ch/utilities/images/nav_trenn.gif';
	ImgHomeLow.src = 'http://www.coop.ch/utilities/images/nav_home.gif';
	ImgHomeHi.src = 'http://www.coop.ch/utilities/images/nav_home_o.gif';
	ImgContactLow.src = 'http://www.coop.ch/utilities/images/nav_kontakt_'+LanguageShort+'.gif';
	ImgContactHi.src = 'http://www.coop.ch/utilities/images/nav_kontakt_'+LanguageShort+'o.gif';
	ImgSearchLow.src = 'http://www.coop.ch/utilities/images/nav_search_lo-'+strLanguage+'.gif';
	
	//Width / Height / Alt-Text language dependent
	var ImgHomeWidth = '33';
	var ImgHomeHeight = '11';
	var ImgHomeAltText = 'Home';
	var ImgContactWidth = '0';
	var ImgContactHeight = '0';
	var ImgContactAltText = '';
	var ImgSearchWidth = '0';
	var ImgSearchHeight = '0';
	var ImgSearchAltText = '';
	var ImgSubmitWidth = '9';
	var ImgSubmitHeight = '9';
	var ImgSubmitAltText = '';
	
	switch(strLanguage)
	{
		case 'de':
			ImgContactWidth = '43';
			ImgContactHeight = '11';
			ImgContactAltText = 'Kontakt';
			ImgSearchWidth = '87';
			ImgSearchHeight = '11';
			ImgSearchAltText = 'Gesamtsuche';
			break;
		case 'fr':
			ImgContactWidth = '45';
			ImgContactHeight = '11';
			ImgContactAltText = 'Contact';
			ImgSearchWidth = '113';
			ImgSearchHeight = '11';
			ImgSearchAltText = 'Recherche globale';
			break;
		case 'it':
			ImgContactWidth = '49';
			ImgContactHeight = '11';
			ImgContactAltText = 'Contatto';
			ImgSearchWidth = '72';
			ImgSearchHeight = '11';
			ImgSearchAltText = 'Cerca tutto';
			break;
	}
	
	HTMLOutput = TblUtilitiesStart + NewLine;
	HTMLOutput += TRStart + createTDStart('','','9','','','');
	HTMLOutput += createImage(ImgSpacer.src,'2','28','0','','');
	HTMLOutput += TDEnd + NewLine + TREnd + NewLine;
	
	//Contact
	HTMLOutput += createTDStart('','top','','','','');
	var strImgContact = createImage(ImgContactLow.src,ImgContactWidth,ImgContactHeight,'','','utilscontact');
	var strLnkContact = createLink(URLContact+LanguageShort,'','changeImage(\'utilscontact\',ImgContactHi)','changeImage(\'utilscontact\',ImgContactLow)',ImgContactAltText,strImgContact);
	
	HTMLOutput += strLnkContact;
	HTMLOutput += TDEnd + NewLine;
	
	//Vertical Line
	HTMLOutput += createTDStart('','top','','','','');
	var strImgVerticalLine = createImage(ImgVerticalLine.src,'9','11','','','','');
	HTMLOutput += strImgVerticalLine;
	HTMLOutput += TDEnd + NewLine;
	
	//Home
	HTMLOutput += createTDStart('','top','','','','');
	var strImgHome = createImage(ImgHomeLow.src,ImgHomeWidth,ImgHomeHeight,'','','utilshome');
	var strLnkHome = createLink(URLHome+LanguageShort,'','changeImage(\'utilshome\',ImgHomeHi)','changeImage(\'utilshome\',ImgHomeLow)',ImgHomeAltText,strImgHome);
	
	HTMLOutput += strLnkHome;
	HTMLOutput += TDEnd + NewLine;
	
	//Vertical Line
	HTMLOutput += createTDStart('','top','','','','');
	HTMLOutput += strImgVerticalLine;
	HTMLOutput += TDEnd + NewLine;
	
	//Search
	HTMLOutput += createTDStart('','top','','','','');
	var strImgSearch = createImage(ImgSearchLow.src,ImgSearchWidth,ImgSearchHeight,'',ImgSearchAltText,'');
	HTMLOutput += strImgSearch;
	HTMLOutput += TDEnd + NewLine;
	
	//Spacer
	HTMLOutput += createTDStart('','top','','','','');
	var strSpacer = createImage(ImgSpacer.src,'7','1','','','','');
	HTMLOutput += strSpacer;
	HTMLOutput += TDEnd + NewLine;
	
	//Table cell with form
	HTMLOutput += createTDStart('','top','','','','') + NewLine;
	HTMLOutput += FormStartTag + NewLine;
	
	//Input-Fields
	var strInputLanguage = createInputField('lang', 'hidden', strLanguage, '') + NewLine;
	var strInputSite = createInputField('site', 'hidden', 'default', '') + NewLine;
	var strInputQt = createInputField('qt', 'text', '', FormTextFieldStyleString) + NewLine;
	
	HTMLOutput += strInputLanguage + NewLine + strInputSite + NewLine + strInputQt + NewLine;
	HTMLOutput += FormEndTag + NewLine;
	HTMLOutput += TDEnd + NewLine;
	
	//Spacer
	HTMLOutput += createTDStart('','top','','','','');
	HTMLOutput += strSpacer;
	HTMLOutput += TDEnd + NewLine;
	
	//Submit-Button
	HTMLOutput += createTDStart('','top','','','','');
	var strImgSubmit = createImage(FormSendButtonURL,ImgSubmitWidth,ImgSubmitHeight,'','','');
	var strLnkSubmit = createLink('javascript:document.'+FormName+'.submit();','','','',ImgSubmitAltText,strImgSubmit);
	HTMLOutput += strLnkSubmit;
	HTMLOutput += TDEnd + NewLine + TREnd + NewLine;
	HTMLOutput += TblEnd;
	
	document.write(HTMLOutput); //output utilities
}
