/**********************************/
/* General Support                */
/**********************************/
// changes by Quirijn Slings, 03-02-2009:
// - no popups if the url contains '/support/Search/index.aspx' (case sensitive!)
// - fixed bug in checkbox logic (see function 'uncheck')
// - no more js errors when popup blocker is active

var openedWindow;
function OpenWindow(url,name)
{
	openedWindow=window.open(url,name,"menubar=no,scrollbars=yes, resizable=yes,toolbar=no, width=750, height=550");
	if (window.focus) {openedWindow.focus()}
}
function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {
    begin = document.cookie.indexOf(NameOfCookie+"=");
    if (begin != -1) {
      begin += NameOfCookie.length+1;
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(begin, end));
    }
  }
  return null;
}


function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

  document.cookie = NameOfCookie + "=" + escape(value) + 
  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())+" ;path=/";
}


// args: 1=Full brouwser functionalities, 0=Only scrollbars and resize handles
function NewWindow (URL,args){
	if (args==1)
	 {
		var xw,yw
		xw=(screen.width/3)*2;
		yw=(screen.height/3)*2;
		window.open(URL, "", "height="+yw+",width="+xw+",scrollbars=1,resizable=1,location=1,menubar=1,status=1,toolbar=1");
	 }

	else if (args==9)
	 {
		var xw,yw, win1
		xw=788;
		yw=469;
		win1 = window.open(URL, "", "height="+yw+",width="+xw+",scrollbars=1,resizable=1");
		win1.moveTo((screen.width/2)-((xw/2)),(screen.height/2)-((yw/2)));
	 }
	 else if (isNaN(args))
	 {
		var arrWFeatures = args.split(",");
		var intFeature = 0;
		var winWidth  = arrWFeatures[0].substring(arrWFeatures[1].indexOf('='),arrWFeatures[0].length);
		var winHeight = arrWFeatures[1].substring(arrWFeatures[1].indexOf('=')+1,arrWFeatures[1].length);
		var intLeft = (screen.width - winWidth)/2;
		var intTop  = (screen.height - winHeight)/2 - 50;
		if(intLeft<0){intLeft=0;}
		if(intTop<0){intTop=0;}
		var strCenter  = ",left=" + intLeft + ",screenX=" + intLeft;
		   strCenter += ",top=" + intTop + ",screenY=" + intTop;
		args += strCenter;
		var winNew = window.open(URL, 'winNew', args);
		winNew.focus()
		// .moveto method causes an error: access denied
		//winNew.moveTo((screen.width/2)-((winWidth/2)),(screen.height/2)-((winHeight/2)));
	 }

	 else
	 {
		var xw,yw, win1
		xw=(screen.width/3)*2;
		yw=(screen.height/3)*2;
		win1=window.open(URL, 'win2', "height="+yw+",width="+xw+",scrollbars=1,resizable=1");
		win1.moveTo((screen.width/2)-((xw/2)),(screen.height/2)-((yw/2)));
	 }

 return false;   }

/***************************/
/* End of General          */
/***************************/

/***************************/
/* Hide & Show Headers/DIV */
/***************************/
function init()
{
    // Add click/hover system to all h6 element that can hide/show its next sibling
	var h6s,i,tohide,tohideobj,isexpanded;
	h6s=document.getElementsByTagName('h6');
	for (i=0;i<h6s.length;i++)
	{
        // get next sibling (the element to hide, check that it is an element
		tohide=h6s[i].nextSibling;
		while(tohide.nodeType!=1)
		{
			tohide=tohide.nextSibling;
		}
		// Assign the relationship, since the combination of h6 with a hidden first sibling will trigger the hide show functionality
		if (HasClassName(tohide, "hidden")) {
		    h6s[i].tohideobj=tohide;
            // add the hover function onmouseover and onmouseout 
		    h6s[i].onmouseover=function(){hover(this.tohideobj,1);}
		    h6s[i].onmouseout=function(){hover(this.tohideobj,0);}
		    AddClassName(h6s[i], 'normal', true);
		    h6s[i].onclick=function(){collapse(this,this.tohideobj);return false}
		}
	}
}
	
	
// hover function, adds the hover colour 
// unless the headline is an active trigger
function hover(ho,state)
{
	if(state == 1) {AddClassName(ho, 'hover', false);}
	else {RemoveClassName(ho, 'hover');}
}
// collapse function, shows and hides the element and sets the highlight 
// colour of the headline
function collapse(o,ho)
{
    if(HasClassName(ho, 'hidden')){
        RemoveClassName(ho, 'hidden', false);
        AddClassName(o, 'selected', false);
        RemoveClassName(o, 'normal');
    } else {
        AddClassName(ho, 'hidden', false)
        RemoveClassName(o, 'selected');
        AddClassName(o, 'normal', false);
    }
}
/**********************************/
/* End of Hide & Show Headers/DIV */
/**********************************/


/**********************************/
/* Survey                         */
/**********************************/




/**********************************/
/* Survey                         */
/**********************************/

function DoSurvey(e)
{
    setCookie('CanonSurveyTaken','YES',183); 
    OpenWindow(this.href,'SurveyDetail'); 
    window.close(); 
    return false;
}

function CloseSurvey()
{
    setCookie('CanonSurveyTaken','YES',183); 
    window.close(); 
    return false;
}

function InstallSurveyClickHandler()
{
    var obj;
    obj=document.getElementById("DoSurvey");
    if (obj) obj.onclick=DoSurvey;
    obj=document.getElementById("CloseSurvey");
    if (obj) obj.onclick=CloseSurvey;
}

function show_dbg(header,obj)
{
    var msg="";;
    
    if (typeof(obj)=="object") 
    {
        for (var i in obj) msg+=i+":"+obj[i]+"\n"; 
    }
    else
    {
        msg=""+obj;
    }
    
    if (document.all) // IE
        window.confirm(header+"\n"+msg);
    else
        window.prompt(header+"\n"+msg);
}


function ExecuteSurvey(url)
{	
// ignore survey functionality for global search!
	if (location.href.indexOf('/support/Search/index.aspx')> -1) {
		return;
	}
	if(getCookie('CanonSurveyTaken') == null ) 
	{
		var newWindow = window.open(url,'Canon','height=520, width=420, scrollbars=auto, status=0, z-lock=yes');
		// no more js errors when popup blocker is active (QS, 03-02-2009)
		if (newWindow != null) newWindow.blur();
	    
	    //window.focus();
		if (window.safetyRiskWindow != null) window.safetyRiskWindow.focus();
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function JH_MM_nbGroup(imgname, newsrc) {
  document[imgname].src = newsrc;
}

function MM_showHideLayers() { //v3.0 show/hide the layers with the rollovertext
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=4) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	obj.visibility=v; obj.left = (args[i+3].offsetLeft - 20) + 'px'; }
}
function MM_findObj(n, d) { //v4.01 needed for the rollover
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_clearDIV()
{
	var i;
	var countries = document.getElementsByTagName("div");
	for(i=0;i<countries.length;i++)
	{
		if(countries[i].className == "CountrySelectorLanguageBox")
		{
		    var obj = countries[i];
			if(obj.style)
			{
				obj=obj.style;
				try {
					obj.visibility = 'hidden';
				} catch(err)
				{
					//alert('undefined');
				}
			}
		}
		else
		{
			//alert('obj: '+countries[i]+" is_null");
		}
	}
}




// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // we found it
            return true;

            }

         }

      }

   // if we got here then the class name is not there
   return false;

   }
// 
// HasClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

   }
// 
// AddClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }
// 
// RemoveClassName
// ----------------------------------------------------------------------------
  

   function setValidatorToValid(source, clientside_arguments)
   {         
      clientside_arguments.IsValid=true;
   }

/************************************/
/* Start of Global Search Javascript*/
/************************************/

function setSearchFormState(strToggle) {
    if(strToggle=="advanced"){
        document.getElementById("advanced_search").style.display = 'none';
        document.getElementById("toggleSearchAdvanced").style.display = 'block';
        document.getElementById("toggleSearchBasic").style.display = 'none'
        document.getElementById("ctl00_ContentWide_Wide1_hdnAdvanced").value = "false";
    } else {
        document.getElementById("advanced_search").style.display = 'block';
        document.getElementById("toggleSearchAdvanced").style.display = 'none';
        document.getElementById("toggleSearchBasic").style.display = 'block'
        document.getElementById("ctl00_ContentWide_Wide1_hdnAdvanced").value = "true";
    }
}

function checkAdvancedLinkState() {
    if(document.getElementById("search_box")){
        if (document.getElementById("ctl00_ContentWide_Wide1_hdnAdvanced").value == "true") {
            document.getElementById("advanced_search").style.display = 'block';
            document.getElementById("toggleSearchAdvanced").style.display = 'none';
            document.getElementById("toggleSearchBasic").style.display = 'block'
        } else {
            document.getElementById("advanced_search").style.display = 'none';
            document.getElementById("toggleSearchAdvanced").style.display = 'block';
            document.getElementById("toggleSearchBasic").style.display = 'none'
        }
    }
}

/*
function checkboxes(type)
{
    var idPrefix = "ctl00_ContentWide_Wide1_";
    if(type=='all')
    {
        document.getElementById(idPrefix+"chkProducts").checked = false;
        document.getElementById(idPrefix+"chkNews").checked = false;
        document.getElementById(idPrefix+"chkSupport").checked = false;
        document.getElementById(idPrefix+"chkCareers").checked = false;
        document.getElementById(idPrefix+"chkStore").checked = false;
        document.getElementById(idPrefix+"chkCPN").checked = false;
        document.getElementById(idPrefix+"chkBrochure").checked = false;
        document.getElementById(idPrefix+"chkSoftware").checked = false;
    } else {
        document.getElementById(idPrefix+"chkALL").checked = false;
    }    
}
*/

function checkboxes(type)
{
    var idPrefix = "ctl00_ContentWide_Wide1_";
    if(type=='all')
    {
        uncheck('chkProducts');
        uncheck('chkNews');
        uncheck('chkSupport');
        uncheck('chkCareers');
        uncheck('chkStore');
        uncheck('chkCPN');
        uncheck('chkBrochure');
        uncheck('chkSoftware');
    } else {
        uncheck ('chkALL');
    }    
}

// Quirijn Slings, 03-02-2009: added function 'uncheck' which finds an element of a certain type even if the ID was modified by .NET
function uncheck(id) {
	var elmts = document.getElementsByTagName('input');
	for (var i = 0; i < elmts.length; i++) {
		var elmt = elmts[i];
		if (elmt.id.indexOf(id)>-1) {
			elmt.checked = false;
		}
	}
	return null;
}

/**********************************/
/* End of Global Search Javascript*/
/**********************************/
