var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	if (document.getElementById(id) != null)
	{
                     ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
                     }
}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 



function menuHovereffect(obj)
{
obj.style.backgroundImage = "url(/eprise/main/_tremetrics/_images/blueish-mouseover.png)"; 
obj.style.backgroundRepeat = "no-repeat";
}



var ChosenMenu = 1;


function underlineItOver(menunumber)
{
document.getElementById("redline"+menunumber).style.display = "block";
}

function underlineItOut(menunumber)
{

if (menunumber != ChosenMenu)
{
document.getElementById("redline"+menunumber).style.display = "none";
}
}


function selectProductInfo(menunumber)
{
ChosenMenu = menunumber;

for (var x = 1; x <= 5; x++)
{
document.getElementById("container"+x).style.display = "none";
document.getElementById("redline"+x).style.display = "none";
}

document.getElementById("container"+menunumber).style.display = "block";
document.getElementById("redline"+menunumber).style.display = "block";
}



function createCookie(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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function DistributorChangeState(stateName)
{
location.replace("FindDistributorUsa.htm?selectCountry="+stateName);
}


function DistributorChangeCountry(stateName)
{
location.replace("FindDistributorSouthAmerica.htm?selectCountry="+stateName);
}



function manageFavorites(prodid)
{
document.getElementById("trMemoList").style.display = 'block';
//createCookie('fav','',100)
var prodvalue = prodid;
var prodlist = readCookie('fav');

if (prodlist != null && prodlist.length > 0)
{
//alert("test");
arrProds = prodlist.split('_');
var bInsert = true;

for(var i=0;i < arrProds.length;i++) 
{
   if (arrProds[i].length > 0 )
   {   
//alert(arrProds[i]);

      if (prodvalue  == arrProds[i].toString())
      {
         bInsert = false;
      }
}
//alert(prodvalue   + "=" + arrProds[i].toString());
   }
   if (bInsert == true)
   {
//inserting
   var newValue =   prodlist +"_" + prodvalue;
   //alert(newValue );
   createCookie('fav',newValue ,100);
document.getElementById("trAdd").style.display = 'none';  
document.getElementById("trRemove").style.display = 'block';

   }
else
{
   //alert(arrProds.length);
//deleting
   for(var i=0;i < arrProds.length;i++) 
   {
if (prodvalue  == arrProds[i].toString())
{

   arrProds.splice(i, 1);
   document.getElementById("trAdd").style.display = 'block';  
   document.getElementById("trRemove").style.display = 'none';
} 

      if (arrProds.length == 0)
      {
document.getElementById("trMemoList").style.display = 'none';
      }
   }
newValue = "";
for(var i=0;i < arrProds.length;i++) 
{
newValue += "_" + arrProds[i].toString();
}
newValue  = newValue.substr(1);
createCookie('fav',newValue,100);

//alert(newValue);


}


 }
else
{
createCookie('fav',prodvalue ,100);
document.getElementById("trAdd").style.display = 'none';  
document.getElementById("trRemove").style.display = 'block';
}


}


function manageFavoritesMemoList(prodid)
{

   if (confirm("Click OK or Cancel to Continue") == true)
   {
   var prodvalue = prodid;
   var prodlist = readCookie('fav');
   arrProds = prodlist.split('_');

     for(var i=0;i < arrProds.length;i++) 
     {
        if (prodvalue  == arrProds[i].toString())
       {
          arrProds.splice(i, 1);
       } 
    }
newValue = "";
for(var i=0;i < arrProds.length;i++) 
{
newValue += "_" + arrProds[i].toString();
}
newValue  = newValue.substr(1);
createCookie('fav',newValue,100);


if (arrProds.length ==0)
{
document.getElementById("trNoProducts").style.display = 'block';  

}


document.getElementById("trMemo_"+prodid).style.display = 'none';  



   }
}


function onclick_ValidateMemoListForm()
{

var strError = false;
document.getElementById("divErrorHeadline").style.display = "none";
document.getElementById("divErrorName").style.display = "none";
document.getElementById("divErrorCountry").style.display = "none";
document.getElementById("divErrorPhone").style.display = "none";
document.getElementById("divErrorEmail").style.display = "none";
document.getElementById("divErrorCity").style.display = "none";

if (document.getElementById("selectState") != null)
{
document.getElementById("divErrorState").style.display = "none";
}
document.getElementById("divErrorPostCode").style.display = "none";
document.getElementById("divErrorStreetAddress").style.display = "none";


if (document.getElementById("txtName").value.length < 4 )
{
strError = true;
document.getElementById("divErrorName").style.display = "block";
}

if (document.getElementById("txtCompany").value.length < 1 )
{
strError = true;
document.getElementById("divErrorCompany").style.display = "block";
}

if (document.getElementById("txtCity").value.length < 1 )
{
strError = true;
document.getElementById("divErrorCity").style.display = "block";
}

if (document.getElementById("selectState") != null)
{
if (document.getElementById("selectState").value.length == 0 && document.getElementById("hiddenSiteId").value == "us_en" )
{
strError = true;
document.getElementById("divErrorState").style.display = "block";
}
}

if (document.getElementById("selectCountry") != null)
{
if (document.getElementById("selectCountry").value.length == 0 )
{
strError = true;
document.getElementById("divErrorCountry").style.display = "block";
}
}


if (document.getElementById("txtPostCode").value.length == 0 )
{
strError = true;
document.getElementById("divErrorPostCode").style.display = "block";
}



if (document.getElementById("chkPhone").checked == true)
{
if (document.getElementById("txtPhone").value.length == 0 )
{
strError = true;
document.getElementById("divErrorPhone").style.display = "block";

//document.getElementById("divErrorMsg").innerHTML= "dsfsdfdsfsdf";
}

}
if (document.getElementById("chkEmail").checked == true)
{
if ((document.getElementById("txtEmail").value.indexOf(".") > 2) && (document.getElementById("txtEmail").value.indexOf("@") > 0))
{
}
else
{
strError = true;
document.getElementById("divErrorEmail").style.display = "block";
//document.getElementById("divErrorMsg").innerHTML= "aaaaa";
}
}

if (document.getElementById("chkPost").checked == true)
{

if (document.getElementById("txtCity").value.length == 0 )
{
strError = true;
document.getElementById("divErrorCity").style.display = "block";
}


if (document.getElementById("txtStreetAddress").value.length == 0 )
{
strError = true;
document.getElementById("divErrorStreetAddress").style.display = "block";
}


}


if (strError == true)
{
document.getElementById("divErrorHeadline").style.display = "block";
return false;
}
else
{
document.getElementById("hiddenSubmit").value = "true";
form1.submit();
}


}


function onclick_ChangememoListForm(verdi)
{
document.getElementById("divErrorHeadline").style.display = "none";
document.getElementById("divErrorName").style.display = "none";
document.getElementById("divErrorCountry").style.display = "none";
document.getElementById("divErrorPhone").style.display = "none";
document.getElementById("divErrorEmail").style.display = "none";
document.getElementById("divErrorCity").style.display = "none";
document.getElementById("divErrorPostCode").style.display = "none";
document.getElementById("divErrorStreetAddress").style.display = "none";

if (verdi == 1)
{
document.getElementById("chkPhone").checked = true;
document.getElementById("chkEmail").checked = false;
document.getElementById("chkPost").checked = false;
}
else if (verdi == 2)
{
document.getElementById("chkPhone").checked = false;
document.getElementById("chkEmail").checked = true;
document.getElementById("chkPost").checked = false;
}
else if (verdi == 3)
{
document.getElementById("chkPhone").checked = false;
document.getElementById("chkEmail").checked = false;
document.getElementById("chkPost").checked = true;
}


if (document.getElementById("chkPhone").checked == true)
{
document.getElementById("spanReqPhone").style.display = "inline";
document.getElementById("spanReqEmail").style.display = "none";
document.getElementById("spanReqCity").style.display = "none";
document.getElementById("spanReqStreetAddress").style.display = "none";
}
if (document.getElementById("chkEmail").checked == true)
{
document.getElementById("spanReqPhone").style.display = "none";
document.getElementById("spanReqEmail").style.display = "inline";
document.getElementById("spanReqCity").style.display = "none";
document.getElementById("spanReqStreetAddress").style.display = "none";
}
if (document.getElementById("chkPost").checked == true)
{
document.getElementById("spanReqPhone").style.display = "none";
document.getElementById("spanReqEmail").style.display = "none";
document.getElementById("spanReqCity").style.display = "inline";
document.getElementById("spanReqPostCode").style.display = "inline";
document.getElementById("spanReqStreetAddress").style.display = "inline";
}



}



function onChange_DistributorList()
{

if (document.getElementById('selectCountry').selectedIndex != '')
{
form1.submit();
}


//document.getElementById('idregion').value = document.getElementById('selectRegion').options[document.getElementById('selectRegion').selectedIndex].value;")


}


function onclick_AddNewFlag(idCountry)
{
var strImgPath = idCountry +"__"+document.getElementById("imgCountry").src;


if (idCountry != 13 && idCountry != 86)
{
createCookie('CountryFlag',strImgPath,100);
document.getElementById("divAddNewFlag").style.display = 'none';
document.getElementById("divRemoveFlag").style.display = 'block';
document.getElementById("imgCountryChosen").src = document.getElementById("imgCountry").src;
}
else
{

}
}


function onclick_RemoveFlag()
{
createCookie('CountryFlag','',100);
document.getElementById("divAddNewFlag").style.display = 'block';
document.getElementById("divRemoveFlag").style.display = 'none';
document.getElementById("imgCountryChosen").src = "";
}



function onclick_Compare(obj)
{

//used when checkboxes are clicked
var  ProductCount = document.getElementById("hiddenProductCount").value;

var alreadyClicked = 0
for(var i=1;i <=ProductCount ;i++) 
{
if (document.getElementById("chkCompare_"+i).checked == true)
{
alreadyClicked ++;
}
}



for(var i=1;i <=ProductCount ;i++) 
{



//if (alreadyClicked == 1)
//{
document.getElementById("spanCompareMax_"+i).style.display = 'none';
document.getElementById("spanCompareAvailable_"+i).style.display = 'inline';
document.getElementById("spanCompareButton_"+i).style.display = 'none';
document.getElementById("spanCompareChkbox_"+i).style.display = 'inline';
//}

if (document.getElementById("chkCompare_"+i).checked == false && alreadyClicked  ==3)
{

document.getElementById("spanCompareMax_"+i).style.display = 'inline';
document.getElementById("spanCompareAvailable_"+i).style.display = 'none';
document.getElementById("spanCompareButton_"+i).style.display = 'none';
document.getElementById("spanCompareChkbox_"+i).style.display = 'none';
}


if (document.getElementById("chkCompare_"+i).checked == true && alreadyClicked > 1 && alreadyClicked <=3)
{
document.getElementById("spanCompareMax_"+i).style.display = 'none';
document.getElementById("spanCompareAvailable_"+i).style.display = 'none';
document.getElementById("spanCompareButton_"+i).style.display = 'inline';
}

}




//document.getElementById("hiddenProductCount").value;

if (alreadyClicked >3)
{
obj.checked = false;
} 

if (obj.checked == false)
{
var compareCountId = obj.id.replace("chkCompare_","");
document.getElementById("spanCompareButton_"+compareCountId).style.display = 'none';
document.getElementById("spanCompareAvailable_"+compareCountId ).style.display = 'inline';
}


}


function onclick_CompareButton()
{
//Used when compare button is clicked
   var  ProductCount = document.getElementById("hiddenProductCount").value;
   var strBuildCompareString = "";
   kk=0;
   for(var i=1;i <=ProductCount ;i++) 
   {
   if (document.getElementById("chkCompare_"+i).checked == true)
      {
      kk+=1;
         if (kk>1)
         {
         strBuildCompareString += ":" + document.getElementById("chkCompare_"+i).getAttribute('comparisonPath');
         }
        else
        {
         strBuildCompareString += document.getElementById("chkCompare_"+i).getAttribute('comparisonPath');
        }
      }
   }
//alert(strBuildCompareString );
document.getElementById("hiddenProductsToCompare").value = strBuildCompareString ;
formCompare.submit();
}

function onclick_checkCount(e)
{

   var checkboxesMarked = 0;
   var tempCount = document.getElementById('ProductSpecificCount').value;
       
   for (i = 1; i <= tempCount ; i++)
       {

          if (document.getElementById('ProductNumber'+i).checked == true)
          {
          checkboxesMarked ++;
          }
   }

if (checkboxesMarked <2)
{
document.getElementById('submitComparison').disabled = true;
}

if (checkboxesMarked == 2 || checkboxesMarked == 3)
{
document.getElementById('submitComparison').disabled = false;
}

if (checkboxesMarked >3)
{
document.getElementById(e.id).checked = false;
}
}


function onclick_compare()
{

strProductSpecificCount = document.getElementById("ProductSpecificCount").value;
strBuildCompareString = "";
kk=0;
 for (i = 1; i <= strProductSpecificCount ; i++)
 {
   if (document.getElementById("ProductNumber"+i).checked == true)
      {
       kk+=1;
         if (kk>1)
         {
         strBuildCompareString += ":" + document.getElementById("ProductNumber"+i).getAttribute('productPath');
         }
         else
         {
         strBuildCompareString += document.getElementById("ProductNumber"+i).getAttribute('productPath');
         }
      }
  }

document.getElementById("hiddenProductsToCompare").value = strBuildCompareString ;
formCompare.submit();

}


function onchange_ChangeProductStyle()
{

var selectValue= document.getElementById('selectProductType').options[document.getElementById('selectProductType').selectedIndex].value;

if (selectValue != "")
{
document.getElementById("ProductCheckBoxClear").value = "true";
formCompare.submit();

}

}


function ScrollToTop()
{
//spanTop
window.scrollTo(0,0);
}

function ObjectPosition(obj) {
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return [curleft,curtop];
}

function showMemoBox(obj)
{

var CookieValue = readCookie('MemoBox');
//alert(CookieValue);

if (CookieValue == null || CookieValue  == '')
{
createCookie('MemoBox','HelloCookie',30);
var aryPosition = ObjectPosition(obj);
document.getElementById("divMemoBox").style.display = "block";
document.getElementById("divMemoBox").style.left= (aryPosition[0]-100) +"px";
document.getElementById("divMemoBox").style.top = (aryPosition[1]+20) +"px";
}
//createCookie('MemoBox','',30);
}

function hideMemoBox()
{
document.getElementById("divMemoBox").style.display = "none";
}


function RedirectSearchWebSite(e)
{
var characterCode
	 if(e && e.which)
                      {
	 e = e;
	 characterCode = e.which;
	 }
	 else
                      {
	 e = event;
	 characterCode = e.keyCode;
	 }	 
	 if(characterCode == 13){
                      SearchWebSite();	 
                      e.returnValue=null;
                      e.cancelBubble = true;
                      return false;
	 }
e.cancelBubble = true;
return false;
}

function SearchWebSite()
{

var searchValue = document.getElementById("txtSearch").value;
//alert(searchValue +"");

if (searchValue.length> 2 )
{
document.forms["formSearch"].submit();
}



}



function windowOpen(url,heightY,WidthX)
{
window.open(url,'Product','height="+heightY+",width="+WidthX+"');
}


var strActiveDivContainer = "";



function hideActiveDivContainer()
{




if (document.getElementById("container1").style.display == "block")
{
document.getElementById("container1").style.display = "none";
strActiveDivContainer= "container1";
}
if (document.getElementById("container2").style.display == "block")
{
document.getElementById("container2").style.display = "none";
strActiveDivContainer= "container2";
}
if (document.getElementById("container3").style.display == "block")
{
document.getElementById("container3").style.display = "none";
strActiveDivContainer= "container3";
}
if (document.getElementById("container4").style.display == "block")
{
document.getElementById("container4").style.display = "none";
strActiveDivContainer= "container4";
}

}



function showActiveDivContainer()
{
document.getElementById(strActiveDivContainer).style.display = "block";

var flash = "<embed id='embedVideo'  src='/eprise/main/_Swf/dummy.swf' width='500' height='450' align='middle' quality='high' name='player' allowScriptAccess='sameDomain' allowFullScreen='true' wmode='transparent' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";

document.getElementById("flash").innerHTML=flash;

document.getElementById("tableTab").style.display = "block";
document.getElementById("imgProduct").style.display = "block";



}


function showVideo(url)
{
hideActiveDivContainer();

document.getElementById("tableTab").style.display = "none";
document.getElementById("imgProduct").style.display = "none";

document.getElementById("divVideo").style.display = "block";

var flash = "<embed id='embedVideo'  src='"+url+"' width='500' height='450' align='middle' quality='high' name='player' allowScriptAccess='sameDomain' allowFullScreen='true' wmode='transparent' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";

document.getElementById("flash").innerHTML=flash;
}


function loadRegion(obj)
{
location.href = obj.options[obj.selectedIndex].value;
}
