//  site specific JavaScript for the Nexcare EWCD site.

// IMPORTANT:  This writes the height of the products manually to prevent glitches 
// when rendering without JavaScript
document.write("<style>.product { height: 215px; }</style>");
// END FIX




// BEGIN JAVASCRIPT HOVER TOOLTIP CODE 

// position of the tooltip relative to the mouse in pixel //
var offsetx = 8;
var offsety =  8;


function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 

var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip) {
	if(!document.getElementById('tooltip')) newelement('tooltip');
	var lixlpixel_tooltip = document.getElementById('tooltip');
	lixlpixel_tooltip.innerHTML = tip;
	lixlpixel_tooltip.style.display = 'block';
	document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
	//document.onmousemove = '';
}




/* Used for Flash popups
 * Example on usage:
 * <a href='javascript:popupFlash("_CSEMBED...",height,width,"New Window Title");'>LinkText</a>
 * NOTE:  The var popupwin = null; should only be stated once in this document.
 */
var popupwin = null;

function popupFlash(fileURL,fileWidth,fileHeight,popupTitle) {
	// Position the window in the Middle of the Screen
	var winl = (screen.width-fileWidth)/2;   // px from the left
	var wint = (screen.height-fileHeight)/2; // px from the top
	// The following two lines prevents an IE error. (creates a blank window, if one doesn't already exist)
	popupwin=window.open("","NewWindow","top="+wint+",left="+winl+",width=200,height=200");
	popupwin.window.close();
	
	var flash_insert="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0' width='"+fileWidth+"' height='"+fileHeight+"'><param name='movie' value='"+fileURL+"'><param name=quality value=high><embed src='"+fileURL+"' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+fileWidth+"' height='"+fileHeight+"'></embed></object>";
	popupwin=window.open("","NewWindow","toolbar=no,location=no,scrollbars=no,directories=no,status=no,menubar=no,top="+wint+",left="+winl+",width="+fileWidth+",height="+fileHeight+"");
	popupwin.document.write("<ht"+"ml><head><title>"+popupTitle+"</title><style type='text/css'> html, body { overflow: hidden; margin:0; padding:0; background-color:#fff } </style></head><bo"+"dy>"+flash_insert+"</bo"+"dy></ht"+"ml>");
	popupwin.window.focus();
}








/* Form Validation
 * FUNCTION LIST:
 *   disableEnterKey()			Disables the Enter Key
 *   isblanks(s)				Checks for empty input fields
 *   checkOnSubmit(emailID)		Runs when the form is submitted
 								(this function requires the ones below it)
 *   removeSpace(src)			Removes spaces from a string
 *   emailBadChars(string)		Checks for bad characters in an email string
 *   isEmailOkay(valueCheck)	Runs the above two functions on the email ID
 */
 

// Disables the Enter Key
function disableEnterKey() { 
	if (window.event.keyCode == 13) {
	 window.event.keyCode = 0; 
	 }
} 

// Used to check for empty input fields
function isblank(s) {
	if ((s == null) || (s == "")) return true;
	for(var i = 0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

/* Script to remove the spaces in the string 
 * @param src ---string in which the spaces are to be removed
 */
function removeSpace(src) {
	var result="";
	var inPtr=0;
	// Loop to check the white spaces
	for(inPtr=0; inPtr < src.length; inPtr++) {
		if(src.charAt(inPtr) != ' ') {//check if the character is white space
			result+=src.charAt(inPtr);
		} // end of check for the character is white space
	} // End of loop
	return result;
}

/* Script to check the bad characters in the mail
 * @param string ----contains the mail string in which bad charaters 
                     are to be checked */  
function emailBadChars(string) {
	if (!string) return false;
	var iChars = "*|,\":<>[]{}`\';()&$#%";
	// Loop to check the string
	for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i)) != -1) { //condition to check for bad chars
			return true;
		} // End of condition
	} // End of loop
	return false;
} // End of emailBadChars()                 



// Script to check whether the the email format is ok
function isEmailOkay(valueCheck) {
	var result = true;
	if (emailBadChars(valueCheck) == true) {	//Check for badcharacters
		   alert("We're sorry, but the email address you entered contains invalid characters.\r\n"+
			"Please re-enter your email address.");
		result = false;
	}	// End of check for bad characters
	else {	// Else for not having bad characeters
		if(valueCheck.length < 7) {				//check length of email
				alert("We're sorry, but the email address you entered does not contain enough characters to be valid.\r\n"+
				"Please re-enter your email address.");
				result = false;
		} // End of check length
		else {
		  if(valueCheck.indexOf('@') < 1
				|| valueCheck.lastIndexOf('.') < valueCheck.indexOf('@')+2
				|| valueCheck.lastIndexOf('.') == valueCheck.length - 1
				|| valueCheck.lastIndexOf('@') == valueCheck.length - 1)  {	 	//Check for  @, . in the email
			alert("We're sorry, but the email address you entered does not follow the pattern x@x.x\r\n"+
			"Please re-enter your email address.");
			result = false;
		  }// End of check for @ . in email
		}
	} // End of else for not having bad characters
	return result;
} // End of isEmailOkay()

function changeTabColor(tab,newColor)
{
if(document.getElementById(tab)){
 elem = document.getElementById(tab);
 elem.style.color = newColor;
}
}

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
	document.write("<style>.product { height: 450px; }</style>");
	document.write("<style>.productlong { height: 550px; }</style>");
    return results[1];
}
function printable(){
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) {
  var divs = document.getElementsByTagName("div");
  // Iterate through all DIVs in array
  for(var i = 0; i < divs.length; i++){
    // If current DIV is using "tdfvisOff" styling,
    // change it to use "visOn" styling
    if(divs[i].className == "tdfvisOff") {
      divs[i].className = "visOn";
	  document.write("<style> .conright { display: none; }</style>");
    // If current DIV is using "visOn" styling,
    // change it back to use "tdfvisOff" styling
    } else if(divs[i].className == "visOn") {
      divs[i].className = "tdfvisOff";
  } }
	} else {
printLocation = window.location.search = '?printable=t';
window.location = printLocation;
}
}
