var strSelectMaxThree = "Maximum 3 produits peuvent être selectionné";
var strSelectUpToThree = "Veuillez selectionner jusqu'au trois produits";
var strInvalidEmailAddress = "Veuillez entrer une adresse Email valide";
var strNotSimilar = "Les adresses emails saisies sont différentes";
var strVPOLogin = "Votre mot de passe est incorrect";
var strFillOut = "Vous n'avez pas rempli toutes les champs obligatoires";
var strInfoRequest = "Veuillez indiquer quel type d'information vous voulez recevoir";
function cmdPrintPage()
{
	var lObjArrProperties = new Array()
	lObjArrProperties["Title"] = document.title
	var lObjAllPrintSpans = document.getElementsByName("PrintElement")
	if(lObjAllPrintSpans.length == 0)
	{
                                lObjArrProperties["NoElements"] = true
                               	lObjArrProperties["PrintElements"] = document.body.firstChild
	}
                else
                {
                                lObjArrProperties["NoElements"] = false
	                lObjArrProperties["PrintElements"] = lObjAllPrintSpans
                }


	var lStrFixedAttributes = "center:1;help:0;status:0;resizable:1;"
	var lStrSize			= "dialogWidth:800px;dialogHeight:600px;"
	var lStrPopupLocation	= "/system/printpage.xhtml"

	return showModalDialog(lStrPopupLocation, lObjArrProperties, lStrSize + lStrFixedAttributes);

}

function printwin()
{
               window.print();
}

function swapDisplay(element)
{
   var objULelement = element.parentNode.parentNode.children[1];
   for (i=0; i< objULelement.children.length; i++) {
      var objLIelement = objULelement.children[i];
   	if (objLIelement.style.display == "block") {
		objLIelement.style.display = "none";
	} else {
		objLIelement.style.display = "block";
   	}
   }
}


// Have Global Navigation MouseOver Swapped Static Ver.

function swaponBg(target) {
	/* if(window.opera){
		return true;
	}
	else{ */ // no need to make exception for Opera -- BS
		target.style.backgroundColor = '#006699';
	/*}*/
}

function swapoffBg(target) {
	/*if(window.opera){
		return true;
	}
	else{ */ 
		target.style.backgroundColor = '#44AADD';
	/*}*/
}

function showImg(imgID) {
	document.images['imgMain'].src = document.images[imgID].src;
}

//this function checks if the VPO fields contain values
function vpoCheck(form){
	if ((form.username.value == "") || (form.password.value == "")){
		alert(strVPOLogin);
		return false;
	}	else	{
		return true;
	}
}

function checkWhenChecked(form, lastbox){
	// 3 products can be selected
	var total = 0;
	var box = null;
	var total = checkCheckedCheckBoxes(form);
	if (total > 3) {
		for (var cntProduct = 0; cntProduct < form.product.length; cntProduct++) {
			if (form.product[cntProduct].id == lastbox) {
				box = form.product[cntProduct];
				box.checked = false;
				alert(strSelectMaxThree);	
				return false;
			}
		}
	}	
}	

function checkProdSubmit(form) {
// at least one product must have been selected
var	total = 0;
total = checkCheckedCheckBoxes(form);
if (total < 1) {
	alert(strSelectUpToThree);
	}
else{
	form.submit();
	}
}

function checkCheckedCheckBoxes(form) {
//counts the number of checkboxes that was checked
var total = 0;
var max = form.product.length;
for (var counter = 0; counter < max; counter++) {
if (eval("form.product[" + counter + "].checked") == true) {
    total += 1;
   }
}
return total;	   
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert(strInvalidEmailAddress)
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert(strInvalidEmailAddress)
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert(strInvalidEmailAddress)
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert(strInvalidEmailAddress)
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert(strInvalidEmailAddress)
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr=strInvalidEmailAddress
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function resetAll(form) {
	form.reset();
	return false;
}

function enewsCheck(form){
	var strEmail=form.email.value;
	var strConfirmEmail=form.confirmemail.value;

	if (emailCheck(strEmail)){
		if (strEmail == strConfirmEmail){
			return true;
		}
		else {
			alert(strNotSimilar);
			return false;
		}
	}
	else {
		return false;
		}	
}


function productFormCheck(form){
	var strEmail=form.email.value;
	var strFirstName=form.firstname.value;
	var strLastName=form.lastname.value;
	var strCity=form.city.value;
	var strPostal=form.postCode.value;
	var strCountry=form.country.value;
	var blnSpecs=form.specification.checked;
	var blnLiterature=form.literature.checked;

	if (emailCheck(strEmail)) {
	 if (strFirstName == "" || strCity == "" || strPostal=="" || strLastName == "" || strCountry == "") {
	 alert (strFillOut);
	 return false;
		} else {
				if (!(blnSpecs == true || blnLiterature == true)) {
				alert (strInfoRequest);
				return false;

				} else {
				return true;
				}
	 }
	}
	else {
		return false;
		}	
}


function vpoRequestFormCheck(form){

	var strFirstName=form.firstname.value;
	var strLastName=form.lastname.value;
	var strEmail=form.email.value;
	var strPublication=form.publication.value;
	var strAddress=form.address.value;
	var strPostalCode=form.postalcode.value;
	var strCity=form.city.value;
	var strCountry=form.country.value;

	if (emailCheck(strEmail)) 
	{
		if (strFirstName == "") 
		{
			alert (strFillOut);
			return false;
		} 
		else 
		{
	 		if (strLastName == "") 
	 		{
				alert (strFillOut);
				return false;
			} 
			else 
			{
				if (strPublication == "") 
				{
					alert (strFillOut);
	    			return false;
				} 
				else 
				{

					if (strAddress == "") 
					{
						alert (strFillOut);
	    				return false;
					} 
					else 
					{
						if (strPostalCode == "") 
						{
							alert (strFillOut);
	    					return false;
						} 
						else 
						{
							if (strCity == "") 
							{
								alert (strFillOut);
	    						return false;
							} 
							else 
							{
								if (strCountry == "") 
								{
									alert (strFillOut);
	    							return false;
								} 
								else 
								{
									return true;
								}
							}
						}
					}
				}
			}
		}
	}
	else 
	{
		return false;
	}	
}

//random image picker
function pickImage(upperlimit){
	// get a random number in the specified range (0 - upperlimit)
	var rndNumber = Math.round(upperlimit*Math.random());
	
	// create ID string
	var id = 'banner' + rndNumber;

	//change the mainimage location
	document.images['mainbanner'].src = document.getElementById(id).href;
}

//random image picker right
function pickImageRight(upperlimit){
	// get a random number in the specified range (0 - upperlimit)
	var rndNumber = Math.round(upperlimit*Math.random());
	
	// create ID string
	var id = 'bannerright' + rndNumber;

	//change the mainimage location
	document.getElementById(id).style.display = "inline";
}

function forward(href) {
	if(href && href.value) {
		if(href.options[href.selectedIndex]) {
			location.href = href.value+"#"+href.options[href.selectedIndex].text;
		} else {
			location.href = href.value;
		}
	}
}

function openWin(img, varWidth, varHeight) {
	if (varWidth==0){
		varWidth=790;
	}
	if (varHeight==0){
		varHeight=570;
	}
	window.open(img.href, '', 'toolbar=no , width=' + varWidth + ', height= ' + varHeight);
}

function openPopup(href, varWidth, varHeight) {
	if (varWidth==0){
		varWidth=790;
	}
	if (varHeight==0){
		varHeight=570;
	}
	window.open(href, '', 'toolbar=no,scrollbars=1,status=0,location=0,resizable=1,width=' + varWidth + ',height=' + varHeight);
}

function email(prefix, ext) {
	location = "mailto:"+prefix+"@ricoh."+ext;
}


if (document.innerWidth) {
	frameWidth = document.innerWidth;
	frameHeight = document.innerHeight;
} else if (document.documentElement && document.documentElement.clientWidth) {
	frameWidth = document.documentElement.clientWidth;
	frameHeight = document.documentElement.clientHeight;
} else if (document.body) {
	frameWidth = document.body.clientWidth;
	frameHeight = document.body.clientHeight;
}


// ActiveX Object Workaround

function reActiveX()
{
  // Test user agent
  var strAgent = navigator.userAgent.toUpperCase();
  var nIEIdx = strAgent.indexOf("MSIE");
  if (nIEIdx == -1)
  {
    // If user agent does not look like IE, return -- this is not needed.
    return;
  }

  // Build arrays of elements to rewrite
  var doaEmbeds = document.getElementsByTagName("embed");
  var doaObjects = document.getElementsByTagName("object");
  var doaApplets = document.getElementsByTagName("applet");
 
      // Iterate through objects, rewriting as we go
      // EMBED
      for (var raxi = 0; raxi < doaEmbeds.length; raxi++ )
  {
            var doRewriteObj = doaDomObjsToRewrite[raxi];
    var doParentObj = doRewriteObj.parentNode;
            
            var strHTML = doParentObj.innerHTML;
            
            doParentObj.removeChild(doRewriteObj);
            doParentObj.innerHTML = strHTML;
      }
      // OBJECT
      for (var raxj = 0; raxj < doaObjects.length; raxj++ )
  {
            var doRewriteObj = doaObjects[raxj];
    var doParentObj = doRewriteObj.parentNode;
            
            var strHTML = doParentObj.innerHTML;
            
            doParentObj.removeChild(doRewriteObj);
            doParentObj.innerHTML = strHTML;
      }
      // APPLET
      for (var raxk = 0; raxk < doaApplets.length; raxk++ )
  {
            var doRewriteObj = doaApplets[raxk];
    var doParentObj = doRewriteObj.parentNode;
            
            var strHTML = doParentObj.innerHTML;
            
            doParentObj.removeChild(doRewriteObj);
            doParentObj.innerHTML = strHTML;
      }
      
      return;
}


function check_emailfriendform(form) {

var name1 = form.fld1.value;
var email1 = form.fld2.value;
var name2 = form.fld3.value;
var email2 = form.fld4.value;

if(!(name1 != "" && name2 != "" && emailCheck(email1) && emailCheck(email2))) {
alert("Please fill in all fields");
return false;
}

return true;
}
// get the browser information

function getOsName( )

{

	var userOs      = "" ;

	var regexResult = "" ;

	var moreInfo    = true ;

	var usrAgent    = navigator.userAgent.toUpperCase( ) ;



	if ( usrAgent.indexOf("WIN") != -1 ) userOs = "Windows" ;

	if ( usrAgent.indexOf("MAC") != -1 ) userOs = "MacOS" ;

	if ( usrAgent.indexOf("X11") != -1 ) userOs = "UNIX" ;



	return userOs ;

}



function getBrowserName( )

{

	var userBrowser = "" ;

	var appName     = navigator.appName.toUpperCase( ) ;



	if ( appName.indexOf("NETSCAPE")  != -1 ) userBrowser = "Netscape" ;

	if ( appName.indexOf("MICROSOFT") != -1 ) userBrowser = "Explorer" ;



	return userBrowser ;

}



function getBrowserVersion( )

{

	var version    = "" ;

	var start      = 0  ;

	var end        = 0  ;

	var usrBrowser = getBrowserName( ) ;

	var usrAgent   = navigator.userAgent.toUpperCase( ) ;

	var appVersion = navigator.appVersion ;



	if ( usrBrowser == "Netscape" )

	{

		start   = appVersion.indexOf(" ",0) ;

		version = appVersion.substring(0,start) ;

	}

	if ( usrBrowser == "Explorer" )

	{

		start   = appVersion.indexOf("MSIE ",0) + 5 ;

		end     = appVersion.indexOf(";",start) ;

		version = appVersion.substring(start,end) ;

	}



	return version ;

}


function printStyleSheet( )
{
	var WIN_IE4_SRC = "/system/win_ie.css" ;
	var WIN_IE5_SRC = "/system/win_ie.css" ;
	var WIN_NN4_SRC = "/system/win_nn4.css" ;
	var WIN_NN6_SRC = "/system/win_ie.css" ;
	var WIN_OPERA_SRC = "/system/win_ie.css" ;

	var MAC_IE4_SRC = "/system/mac_ie.css" ;
	var MAC_IE5_SRC = "/system/mac_ie.css" ;
	var MAC_NN4_SRC = "/system/mac_nn4.css" ;
	var MAC_NN6_SRC = "/system/mac_nn.css" ;
	var MAC_OPERA_SRC = "/system/mac_nn.css" ;

	// put the browser information in variable
	var os      = getOsName( ) ;
	var browser = getBrowserName( ) ;
	var version = getBrowserVersion( ).charAt( 0 ) ;

	var cssSrc = null ;

	if ( os == "Windows" )
	{
		if ( browser == "Explorer" )
		{
			if ( version == 4 )
			{
				cssSrc = WIN_IE4_SRC ;
			}
			if ( version >= 5 )
			{
				cssSrc = WIN_IE5_SRC ;
			}
		}
		else if ( browser == "Netscape" )
		{
			if ( version == 4 )
			{
				cssSrc = WIN_NN4_SRC ;
			}
			if ( version >= 5 )
			{
				cssSrc = WIN_NN6_SRC ;
			}
		}
		else if ( browser == "OPERA" )
		{
			cssSrc = WIN_OPERA_SRC ;
		}else cssSrc = WIN_IE5_SRC ;
	}
	else if ( os == "MacOS" )
	{
		if ( browser == "Explorer" )
		{
			if ( version == 4 )
			{
				cssSrc = MAC_IE4_SRC ;
			}
			if ( version >= 5 )
			{
				cssSrc = MAC_IE5_SRC ;
			}
		}
		else if ( browser == "Netscape" )
		{
			if ( version == 4 )
			{
				cssSrc = MAC_NN4_SRC ;
			}
			if ( version >= 5 )
			{
				cssSrc = MAC_NN6_SRC ;
			}
		}
		else if ( browser == "OPERA" )
		{
			cssSrc = MAC_OPERA_SRC ;
		}else cssSrc = MAC_IE5_SRC;

	}else cssSrc = WIN_IE5_SRC ;

	// output the stylesheet
	if ( cssSrc )
	{
	               // if there is a global variable called strPublicationUrl, prefix that to the path
		if (strPublicationUrl && strPublicationUrl.length > 1) {
			cssSrc = strPublicationUrl + cssSrc;
		}
		document.open( ) ;
		document.write( '<LINK REL="stylesheet" TYPE="text/css" HREF="' + cssSrc + '">' ) ;
		document.close( ) ;
	}
}


printStyleSheet( ) ;
function Show_Text_Block2(Menu_nr)
{
var Text_Block = '';
for (i=1; i<6; i++)
	{
	Text_Block = document.getElementById('text' + i);
	if (typeof Text_Block == 'object') 
		{
		Text_Block.style.display = 'none';
		document.getElementById('link' + i).className = "localnav006699boldclass5th";
		}
	}
// show the selected text block and highlight the selected link
document.getElementById('text'+Menu_nr).style.display = '';
document.getElementById('link'+Menu_nr).className = "localnavff0000boldclass5th";

}


function Show_Text_Block(Click_Menu)
// old one can be removed if every product page is republished see show_text_block2
{
switch (Click_Menu) {
case text1:
Show_This(text1)
Active_Link(link1)
Hide_This(text2)
Hide_This(text3)
Hide_This(text4)
Hide_This(text5)
InActive_Link(link2)
InActive_Link(link3)
InActive_Link(link4)
InActive_Link(link5)
break
case text2:
Show_This(text2)
Active_Link(link2)
Hide_This(text1)
Hide_This(text3)
Hide_This(text4)
Hide_This(text5)
InActive_Link(link1)
InActive_Link(link3)
InActive_Link(link4)
InActive_Link(link5)
break
case text3:
Show_This(text3)
Active_Link(link3)
Hide_This(text1)
Hide_This(text2)
Hide_This(text4)
Hide_This(text5)
InActive_Link(link1)
InActive_Link(link2)
InActive_Link(link4)
InActive_Link(link5)
break
case text4:
Show_This(text4)
Active_Link(link4)
Hide_This(text1)
Hide_This(text2)
Hide_This(text3)
Hide_This(text5)
InActive_Link(link1)
InActive_Link(link2)
InActive_Link(link3)
InActive_Link(link5)
break
case text5:
Show_This(text5)
Active_Link(link5)
Hide_This(text1)
Hide_This(text2)
Hide_This(text3)
Hide_This(text4)
InActive_Link(link1)
InActive_Link(link2)
InActive_Link(link3)
InActive_Link(link4)
break
}
}
function Show_This(Click_Menu)
{
Click_Menu.style.display = "";
}
function Hide_This(Click_Menu)
{
Click_Menu.style.display = "none";
}

function Active_Link(oLink)
{
//oLink.style.color = "#ff0000";  //;"localnavff0000boldclass5th";
oLink.className = "localnavff0000boldclass5th";
}
function InActive_Link(oLink)
{
//oLink.style.color = "#006699";  //"localnav006699boldclass5th";
oLink.className = "localnav006699boldclass5th";
}
