// JScript File
var tempObj;
var xpos;
var ypos;
var doScroll = false;;
var divStart;
var divEnd;
var divStartTop;
var al_finder_selected_div1;
var al_finder_selected_div2;
var al_finder_selected_div3;
var al_finder_selected_div4;
var al_finder_over_div1;
var al_finder_over_div2;
var hideFunc;
var hrz_visible_content = ''; //hrz-prod-content;
/*set the start scroll*/
function hrz_startScroll(){
//	divStart = document.getElementById('hrz-prod-finder-holder1').offsetLeft;
//	divStartTop = document.getElementById('hrz-prod-finder-holder1').offsetTop + 15;
//	divEnd = divStart + (3*188);
//	document.onmousemove = hrz_traceMove;
}

/*checks where the mouse is and scrolls div if the mousepointer is over av div*/
function hrz_scrollDiv()
{	
//	if((xpos > divStart) && (xpos < (divStart+173)))
//	{
//		tempObj = document.getElementById('hrz-prod-finder-submeny1');
//		hrz_scrollContent();
//	}
//	if((xpos > (divStart+188)) && (xpos < (divStart+188+173)))
//	{
//		tempObj = document.getElementById('hrz-prod-finder-submeny2');
//		hrz_scrollContent();
//	}
//	if((xpos > (divStart+188+188)) && (xpos < (divEnd-15)))
//	{
//		tempObj = document.getElementById('hrz-prod-finder-submeny3');
//		hrz_scrollContent();
//	}
//    
//    //Sets the sensitivity
//	if(doScroll){
//			setTimeout("hrz_scrollDiv()",100);
//		}
}
function hrz_scrollContent()
{
//	if(ypos > divStartTop && ypos < (divStartTop + 205)){
//	if((xpos > divStart) && (xpos < divEnd))
//	{
//			if(ypos > 260){
//    		tempObj.
//			}
//			if(ypos > 280){
//				tempObj.scrollTop += 4;
//			}
//			if(ypos < 180){
//				tempObj.scrollTop -= 2;
//			}
//			if(ypos < 160){
//				tempObj.scrollTop -= 4;
//			}
//		}
//	}
}
function hrz_traceMove(e){	
//	if(e) { xpos = e.pageX; ypos = e.pageY; }
//	else { xpos = event.clientX; ypos = event.clientY; }
//	
//	//if the mouse is in the area
//	if(xpos > divStart && xpos < divEnd)
//	{
//		//if scroll function not is started start it;
//		if(!doScroll){
//			doScroll = true;
//			hrz_scrollDiv();
//		}
//	}
}

/*
 * Fills sub industry column with data	
 */
function hrz_fill_finder_meny1(sendLink){

	/* tmp vars only for the show info in the prototyp */	
	var magicVar = 0;
	var tmpArray = new Array('Cooling','Desalination','Oil treatment','Tank cleaning','Waste treatment','Centrifugal separation','Fluid handling','Heating','Evaporation &amp; condensing','Filtration','Cleaning','Conditioning');
	
	var meny1 = document.getElementById('hrz-prod-finder-submeny1');
	var meny2 = document.getElementById('hrz-prod-finder-submeny2');
	var meny3 = document.getElementById('hrz-prod-finder-submeny3');
	
	if(al_finder_selected_div3)
	{
		al_finder_selected_div3.className="hrz-mainbox-contentBox-prodshooser-item";
	}
	sendLink.className = "hrz-mainbox-contentBox-prodshooser-item-active-with-bg hrz-mainbox-contentBox-prodshooser-item";
	al_finder_selected_div3 = sendLink;
	sendLink.blur();
	
	//empties the div
	while (meny1.hasChildNodes())
		meny1.removeChild(meny1.lastChild);

	//empties div nr2		
	while (meny2.hasChildNodes())
		meny2.removeChild(meny2.lastChild);
		
	while (meny3.hasChildNodes())
		meny3.removeChild(meny3.lastChild);
	

	//fills the div
	for(var i=0;i<tmpArray.length;i++){
		var newA = document.createElement('a');
		newA.className = "hrz-mainbox-contentBox-prodshooser-item";
		newA.innerHTML = tmpArray[i];
		newA.onclick = function(){hrz_fill_finder_meny2(magicVar,this);}
		newA.setAttribute('href','#"');
		meny1.appendChild(newA);
		
	}
	hrz_showResults();
}


/*
 * Fills sub industry column with data	
 */
function hrz_fill_finder_meny2(inVar,sendLink){

	/* tmp vars only for the show info in the prototyp */	
	var magicVar = 0;
	var tmpArray = new Array('Cool Water','Refrieration','Free Cooling','Ice storage systems','Local cooling','Swimming pool cooling','Tap water cooling','Cooling of Hydrogen gas','Cooling brine & caustic soda','CO2 gas cooling','Interstage cooling of CO2','Nitric acid cooling','Engine Cooling','Cargo cooling','Lubricating oil cooling');
	
	var meny1 = document.getElementById('hrz-prod-finder-submeny1');
	var meny2 = document.getElementById('hrz-prod-finder-submeny2');
	var meny3 = document.getElementById('hrz-prod-finder-submeny3');
	
	if(al_finder_selected_div1)
	{
		al_finder_selected_div1.className="hrz-mainbox-contentBox-prodshooser-item";
	}
	sendLink.className = "hrz-mainbox-contentBox-prodshooser-item-active hrz-prod-finder-active hrz-mainbox-contentBox-prodshooser-item-active-with-bg";
	al_finder_selected_div1 = sendLink;
	sendLink.blur();
	
	//empties the div
	while (meny2.hasChildNodes())
		meny2.removeChild(meny2.lastChild);

	//fills the div
	for(var i=0;i<tmpArray.length;i++){
		var newA = document.createElement('a');
		newA.className = "hrz-mainbox-contentBox-prodshooser-item";
		newA.innerHTML = tmpArray[i];
		newA.onclick = function(){hrz_fill_finder_meny3(magicVar,this);}
		newA.setAttribute('href','#"');
		meny2.appendChild(newA);
	}
	hrz_showResults();
}

/*
 * Fills Solution column with data	
 */

function hrz_fill_finder_meny3(inVar, sendLink){
	//temp variables
	var magicVar = inVar;
	var tmpArray = new Array('Marine','Mini & Pigments','Oil & Gas','Power');
	
	var meny2 = document.getElementById('hrz-prod-finder-submeny2');	
	var meny3 = document.getElementById('hrz-prod-finder-submeny3');
	
	if(al_finder_selected_div2)
	{
		al_finder_selected_div2.className="hrz-mainbox-contentBox-prodshooser-item";
	}
	sendLink.className = "hrz-mainbox-contentBox-prodshooser-item-active hrz-prod-finder-active hrz-mainbox-contentBox-prodshooser-item-active-with-bg";
	al_finder_selected_div2 = sendLink;
	sendLink.blur();

	//empties the div
	//while (meny3.hasChildNodes())
	//	meny3.removeChild(meny3.lastChild);
	meny3.innerHTML = "";
		
	//fills the div
	for(var i=0;i<tmpArray.length;i++){
		var newA = document.createElement('a');
		newA.className = "hrz-mainbox-contentBox-prodshooser-item";
		newA.innerHTML = tmpArray[i];
		newA.setAttribute('href','#"');

		newA.onclick = function(){hrz_setMeny3Link(this);}
		meny3.appendChild(newA);
	}
	hrz_showResults();
}
function hrz_setMeny3Link(obj)
{
	if(al_finder_selected_div4)
	{
		al_finder_selected_div4.className="hrz-mainbox-contentBox-prodshooser-item";
	}
	al_finder_selected_div4 = obj;
	al_finder_selected_div4.className = "hrz-mainbox-contentBox-prodshooser-item-active hrz-prod-finder-active hrz-mainbox-contentBox-prodshooser-item-active-with-bg";
}
function hrz_mouse_over(overlink)
{
	overlink.className = 'hrz-prod-row-hover';
	if(al_finder_over_div1)
	{
		al_finder_over_div1.className = 'hrz-prod-row';
	}
	al_finder_over_div1 = overlink;
}
/*
 * changes the height of the div that shows the products 
 * this function is called when searching
 */
function hrz_hideFinder(){
	
	var finder  = document.getElementById('hrz-prod-finder-wraper');
	finder.style.visibility = "hidden";
	finder.style.display = "none";
	var prodShower = document.getElementById('hrz-browser-wraper');
	finder.style.height = "0px";
	document.getElementById('hrz-result-ss-header').style.visibility= "visible";
	document.getElementById('hrz-result-prod-header').style.visibility= "visible";
	document.getElementById('hrz-result-ss-header').style.display= "block";
	document.getElementById('hrz-result-prod-header').style.display= "block";
}
/*
 * Shows the "finder" div and resets the height of the product results
 */
function hrz_showFinder(){
	var finder  = document.getElementById('hrz-prod-finder-wraper');
	finder.style.visibility = "visible";
	finder.style.display = "block";
	var prodShower = document.getElementById('hrz-browser-wraper');
	finder.style.height = "210px";
}

/* 
 * Sets the 'Success Stories' to active and show the content of success stories
 */
function hrz_setBrowseCases(obj){

    var unactiveBtn = document.getElementById(_resultTabs[0]);  //hrz-prod-browser-products
	var products = document.getElementById(_resultPanels[0]);   //hrz-prod-content
	var cases = document.getElementById(_resultPanels[1]);      //hrz-case-content;
	
	obj.className = "hrz-prod-browser-ss-active";
	
	if(products != null) {
	    products.style.visibility = "hidden";
	    products.style.display = "none";
    }
	
	if(cases != null) {
	    cases.style.visibility ="visible";
	    cases.style.display = "block";
    }

    if(unactiveBtn != null) {
        unactiveBtn.className = "hrz-prod-browser-inactive-left";
    }
    		
	hrz_visible_content = _resultPanels[1];
}
/*
 * Sets the 'Products' button to active and show the content of products
 */
function hrz_setBrowseProducts(obj){

    var unactiveBtn = document.getElementById(_resultTabs[1]);  //hrz-prod-browser-cases
	var products = document.getElementById(_resultPanels[0]);   //hrz-prod-content
	var cases = document.getElementById(_resultPanels[1]);      //hrz-case-content
	
	obj.className = "hrz-prod-browser-active";
	
	if(products != null) {
	    products.style.visibility = "visible";
        products.style.display = "block";
    }
    
    if(cases != null){
	    cases.style.visibility ="hidden";
	    cases.style.display = "none";
    }
	
	if(unactiveBtn != null) {
	    unactiveBtn.className = "hrz-prod-browser-inactive";
    }
		
	hrz_visible_content = _resultPanels[0];
}

/*
 * Checks if the enterbutton is pressed and if so show full height search results
 */
function hrz_checkIfEnter(e){
	if(window.event) 
	{
		keynum = e.keyCode
	}
	else if(e.which) 
	{
		keynum = e.which
	}
	if(keynum == 13){
		hrz_hideFinder();
	}
}

function hrz_toggleList(listname)
{
	var ddList = document.getElementById(listname);
	if(ddList.style.display == '' || ddList.style.display == 'none')
	{
		ddList.style.visibility = "visible";
		ddList.style.display = "block";
		hideFunc = "document.onclick = function(){hrz_toggleList('"+listname+"');}";
		setTimeout(hideFunc,200);
	}
	else
	{
		ddList.style.visibility = "hidden";
		ddList.style.display = "none";
		document.onclick = function(){}
	}
}
function hrz_selectListItem(clink,inputName)
{
	var outDiv = document.getElementById(inputName);
	outDiv.innerHTML = clink.innerHTML;
	hrz_toggleList(clink.parentNode.parentNode.id);
}

function hrz_clearSearch()
{
	var meny1 = document.getElementById('hrz-prod-finder-submeny1');	
	var meny2 = document.getElementById('hrz-prod-finder-submeny2');	
	var meny3 = document.getElementById('hrz-prod-finder-submeny3');
	meny1.innerHTML = "";
	meny2.innerHTML = "";
	meny3.innerHTML = "";
}
function hrz_showResults()
{
    if(hrz_visible_content != null && hrz_visible_content != '') {
        var o = document.getElementById(hrz_visible_content);
        if(o != null) {
	        o.style.display = "block";
	        o.style.visibililty = "visible";
        }    
    }
}

function hrz_footerScript(listItemID, webID, siteID, listName) 
{
    // Set height and width
    var NewWinHeight=400;
    var NewWinWidth=600;

    // Place the window in centre of screen
    var NewWinPutX=((screen.width/2) - (NewWinWidth/2));
    var NewWinPutY=((screen.height/2) - (NewWinHeight/2));

    //Get the url
    var dialogUrl = '/_layouts/1033/Horizon/footer.aspx?listItem=' + listItemID + '&webID=' + webID + '&siteID=' + siteID + '&listName=' + listName;    
    
    //Get what is below onto one line
    var TheNewWin = window.open(dialogUrl,'TheNewpop','scrollbars=1,left=' + NewWinPutX + ',top=' + NewWinPutY + ',width=' + NewWinWidth + ',height=' + NewWinHeight); 
  
}


//****************** Product Relations Page ********************//

/*==================================================
                        Tabs
  ==================================================*/

function tab(tagID){
    // Reset tabs

    document.getElementById('tab1').style.display = "none";
    document.getElementById('tab2').style.display = "none";
    document.getElementById('tab3').style.display = "none";
    document.getElementById('tab4').style.display = "none";
    document.getElementById('a1').className ="";
    document.getElementById('a2').className ="";
    document.getElementById('a3').className ="";
    document.getElementById('a4').className ="";
    
    // Set tab
    switch (tagID)
    {
        case 'a1':
            document.getElementById('tab1').style.display = "inline";
            document.getElementById('a1').className ="current";
            setCookie('tabCookie','a1');
        break;
        
        case 'a2':
            document.getElementById('tab2').style.display = "inline";
            document.getElementById('a2').className ="current";
            setCookie('tabCookie','a2');
        break;
        
        case 'a3':
            document.getElementById('tab3').style.display = "inline";
            document.getElementById('a3').className ="current";
            setCookie('tabCookie','a3');
        break;
        
                case 'a4':
            document.getElementById('tab4').style.display = "inline";
            document.getElementById('a4').className ="current";
            setCookie('tabCookie','a4');
        break;
        
        default:
            document.getElementById('tab1').style.display = "inline";
            document.getElementById('a1').className ="current";
            setCookie('tabCookie','a1');
    }
}

/*==================================================
  Cookie functions
  ==================================================*/
  
  function checkCookie()
  {
    var cookie = getCookie('tabCookie');    
    if(cookie != null)
    {
        tab(cookie);
    }
    else
        tab('a1');
  }
  
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function collapseOrExpand()
{   
    $(".mainContent").slideToggle(350);
}

firstSlide = 1;
currentSlide = 1;

function nextPicture(last) {
   // Hide current picture
   object = document.getElementById('slide' + currentSlide);
   object.style.display = 'none';
   
   // Show next picture, if last, loop back to front
   if (currentSlide == last) { currentSlide = 1; }
   else { currentSlide++ }
   object = document.getElementById('slide' + currentSlide);
   object.style.display = 'block';
}

function previousPicture(last) {
   // Hide current picture
   object = document.getElementById('slide' + currentSlide);
   object.style.display = 'none';
   
   if (currentSlide == firstSlide) { currentSlide = last; }
   else { currentSlide--; }
   object = document.getElementById('slide' + currentSlide);
   object.style.display = 'block';
}

function SelectCurrentTab(flashLinkID, imagelinkID, flashContentID, imageContentID, radioFlashID, radioImageID, stateFieldID) 
{
	var selectedTab = document.getElementById(stateFieldID).value;

	if (selectedTab.length > 0) {
		if (selectedTab.indexOf('ImageContent') > -1) {
			toggleTabs(imagelinkID, flashLinkID, imageContentID, flashContentID, radioImageID, radioFlashID, stateFieldID);
		} else {
			toggleTabs(flashLinkID, imagelinkID, flashContentID, imageContentID, radioFlashID, radioImageID, stateFieldID);
		}
	}
}


function toggleTabs(showTabLinkID, hideTabLinkID, showTabContentID, hideTabContentID, radioSelected, radioUnselected, stateFieldID) 
{
	document.getElementById(showTabLinkID).className = 'active';
	document.getElementById(hideTabLinkID).className = '';

	document.getElementById(showTabContentID).style.display = 'block';
	document.getElementById(hideTabContentID).style.display = 'none';

	document.getElementById(radioUnselected).checked = false;
	document.getElementById(radioSelected).checked = true;

	document.getElementById(stateFieldID).value = showTabContentID;
}

