//********************************************************************
//*-------------------------------------------------------------------
//* Licensed Materials - Property of IBM
//*
//* WebSphere Commerce
//*
//* (c) Copyright International Business Machines Corporation. 2003
//*     All rights reserved.
//*
//* US Government Users Restricted Rights - Use, duplication or
//* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//*
//*-------------------------------------------------------------------
//*
//////////////////////////////////////////////////////////
// Checks whether a string contains a double byte character
// target = the string to be checked
//
// Return true if target contains a double byte char; false otherwise
//////////////////////////////////////////////////////////
function containsDoubleByte (target) {
var str = new String(target);
var oneByteMax = 0x007F;
for (var i=0; i < str.length; i++){
chr = str.charCodeAt(i);
if (chr > oneByteMax) {return true;}
}
return false;
}
//////////////////////////////////////////////////////////
// A simple function to validate an email address
// It does not allow double byte characters
// strEmail = the email address string to be validated
//
// Return true if the email address is valid; false otherwise
//////////////////////////////////////////////////////////
function isValidEmail(strEmail){
// check if email contains dbcs chars
if (containsDoubleByte(strEmail)){
return false;
}
if(strEmail.length == 0) {
return true;
} else if (strEmail.length < 5) {
return false;
}else{
if (strEmail.indexOf(" ") > 0){
return false;
}else{
if (strEmail.indexOf("@") < 1) {
return false;
}else{
if (strEmail.lastIndexOf(".") < (strEmail.indexOf("@") + 2)){
return false;
}else{
if (strEmail.lastIndexOf(".") >= strEmail.length-2){
return false;
}
}
}
}
}
return true;
}
//////////////////////////////////////////////////////////
// This function will count the number of bytes
// represented in a UTF-8 string
//
// arg1 = the UTF-16 string
// arg2 = the maximum number of bytes allowed in your input field
// Return false is this input string is larger then arg2
// Otherwise return true...
//////////////////////////////////////////////////////////
function isValidUTF8length(UTF16String, maxlength) {
if (utf8StringByteLength(UTF16String) > maxlength) return false;
else return true;
}
//////////////////////////////////////////////////////////
// This function will count the number of bytes
// represented in a UTF-8 string
//
// arg1 = the UTF-16 string you want a byte count of...
// Return the integer number of bytes represented in a UTF-8 string
//////////////////////////////////////////////////////////
function utf8StringByteLength(UTF16String) {
if (UTF16String === null) return 0;
var str = String(UTF16String);
var oneByteMax = 0x007F;
var twoByteMax = 0x07FF;
var byteSize = str.length;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
if (chr > oneByteMax) byteSize = byteSize + 1;
if (chr > twoByteMax) byteSize = byteSize + 1;
}  
return byteSize;
}
// Changes to display disclaimers in print page
// function populate
// This function collects all the 'visible' disclaimers and puts in a pre-defined div
//Added nullchecks in the method inorder to fix the javascript errors occuring because of superscript tag:PSNM fix
function populate()
{
var supArr = document.getElementsByTagName('sup');
if(document.getElementById('disclaimerDiv')){
document.getElementById('disclaimerDiv').innerHTML="";
if(supArr)
{
for (i=0; i<supArr.length; i++){
if(supArr[i].getElementsByTagName('a')[0])
{
var ahref =supArr[i].getElementsByTagName('a')[0].getAttribute('href');
ahref=ahref.substring(ahref.indexOf('#')+1);
if(document.getElementById(ahref))
{
if(!hasHiddenParent(document.getElementById(ahref).parentNode)){
document.getElementById('disclaimerDiv').innerHTML=document.getElementById('disclaimerDiv').innerHTML+'<br>'+document.getElementById(ahref).innerHTML;
}
}
}
}
}
}
}
//An element ele is passed to this function to find if the element
// is coming from hover
function isHover(ele)
{
if (ele.nodeName == "BODY")
{
return false;
}
if ((ele.className == "product-popup"))
{
return true;
}
else{
return isHover(ele.parentNode);
}
}
// An element ele is passed to this function to find if the element is hidden
// Return: true -If there's any hidden element enclosing the passed element
// Return: false - otherwise
function hasHiddenParent(ele)
{
if (ele.nodeName == "BODY")
{
return false;
}
if ((ele.parentNode.style.visibility == 'hidden') || (ele.parentNode.style.display == 'none'))
{
return true;
}else{
return hasHiddenParent(ele.parentNode);
}
}
//Added for MR2#2388 START
function fnTrimTitle()
{
var oldTitle = document.title;
var newTitle = oldTitle.split("#identifier");
document.title = newTitle[0];
}
//Added for MR2#2388 END

