			/* Add onload event for the top right eip status */
// addLoadEvent(updateStatusBug);		
/* */
function decodeHex(str)
{
// Strip out non alpha/num chars
str = str.toUpperCase().replace(new RegExp("s/[^0-9A-Z]//g"));
var result = "";
var nextchar = "";
// loop through the input string
for (var i=0; i<str.length; i++)
{
nextchar += str.charAt(i);
// every 2nd char, add a % and unescape
if (nextchar.length == 2)
{
result += unescape("%"+nextchar);
nextchar = "";
}
}
return result;
}
/* */
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{ 
c_start=c_start + c_name.length+1; 
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
} 
}
return "";
}
/* */
function deleteCookie(c_name, path, domain) 
{
if (getCookie(c_name))
{
document.cookie = c_name + "=" + 
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
}
/* */
function submitForm(form,divid)
{
var postQuery = "";
// check for a comment
if (divid == "commentform")
{
if (!commentValidate(form))
{
return;
}
}
firstsubmit = false;
// get the action from the form
postQuery += form.action;
// Loop through the form elements and add them to the query str
for (i =0; i < form.elements.length; i++)
{
// add validation
// skip the sd field since we are doing ajax
if (form.elements[i].name != "sd")
{
if (form.elements[i].type == "radio")
{
if(form.elements[i].checked)
{
// first item starts the query str
postQuery += (i == 0)?"?":"&";
postQuery += encodeURIComponent(form.elements[i].name) + "=" + encodeURIComponent(form.elements[i].value);						
}
} else {
// first item starts the query str
postQuery += (i == 0)?"?":"&";
postQuery += encodeURIComponent(form.elements[i].name) + "=" + encodeURIComponent(form.elements[i].value);
}
}
}
var responseAction = "";
// set this as the div on display
activeDiv = divid;
// set the responseAction function
switch (divid)
{
case "commentbox":
responseAction = onCommentResponse;
break;
case "commentform":
responseAction = onCommentResponse;
break;
default:
responseAction = onCommentResponse;
}				
// call the ajax function
loginAjax = new Ajax();
loginAjax.makeRequest('POST', postQuery, responseAction, true);
}
/* */
function onCommentResponse() {
if(loginAjax.checkReadyState() == "success")
{
var xmlDoc = loginAjax.request.responseXML;
// get status
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// get the div info
var msgDiv = document.getElementById('commentmessage');
var msgTxt = "";
// if response is not successful show errors
if (status == "Success")
{
document.location.href = "/en_US/ff/success.html";
/*msgTxt = 	"<p><b>Thank You for submitting a comment. Your comment will be reviewed and will appear on "+
"the site if possible. Due to the large volume of submissions all comments cannot appear on "+
"the site.</b></p><p><b>Submit another comment?</b></p>";
// clear the form
var thisForm = document.getElementById('comment_form');
if (thisForm != null)
{
thisForm.reset();
} */
} else {
// default message
msgTxt = "<p>An error has occurred. Please try to submit your comment again.</p>";
// get the error message
var errorNodes = xmlDoc.getElementsByTagName("error");
var errorTxt = errorNodes[0].childNodes[0].nodeValue;
if (errorTxt != null && errorTxt != "")
{
if (errorTxt == "User is not logged in")
{
// 
msgTxt = "<p><b>Please <a href='javascript:void(0)' onclick='popOver(\"login\");'>sign in</a> to submit your comment</b></p>";
} else {
msgTxt = "<p><b>"+errorTxt+"</b></p>";
}
}
}
msgDiv.innerHTML = msgTxt;					
}
}
/* Comments Functions */
/* */
function checkUser()
{
// check for the session cookie 
userCookie = getCookie("eipatron");
// alert(userCookie);
var commentBox = document.getElementById('commentform');
var signinBox = document.getElementById('signinbox');
// if cookie's empty, etc make them sign in
if (userCookie == null || userCookie == "")
{
if (signinBox != null)
{
signinBox.style.display = 'block';
}
if (commentBox != null)
{
commentBox.style.display = 'none';
}
} else {
if (signinBox != null)
{
signinBox.style.display = 'none';
}
if (commentBox != null)
{
commentBox.style.display = 'block';
}				
}
}
/* */
function convertMS(responseTxt)
{
// alert(responseTxt);
// Mozilla and Netscape browsers
if (document.implementation.createDocument) {
var parser = new DOMParser()
doc = parser.parseFromString(responseTxt, "text/xml")
// MSIE
} else if (window.ActiveXObject) {
doc = new ActiveXObject("Microsoft.XMLDOM")
doc.async="false"
doc.loadXML(responseTxt)
}
return doc;
}
var commentAjax = new Ajax();
/* */
function getComments()
{
var commentHTML = "";
if(commentAjax.checkReadyState() == "success") {
var xmlDoc = commentAjax.request.responseXML;
// get status
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// if status = success
if (status == "Success")
{					
// set the count
var countNode = xmlDoc.getElementsByTagName("count");
var count = 0;
if (countNode.length > 0)
{
count = countNode[0].childNodes[0].nodeValue;
}
if (count > 0)
{
// Set the comment count
commentCount(count);
}
// get comment node
var commentNodes = xmlDoc.getElementsByTagName("comment");
// loop through and set the comments div comments
for (i=0;i<commentNodes.length;i++) {
commentData = commentNodes.item(i).childNodes;
commentCell = '';
date = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "name": name = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "subject": subject = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "country": country = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "date": date = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "state": state = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "body": body = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
default:break;
}
}
commentHTML += "<p>";
//if (subject != "")
//	commentHTML += "<b>Re:" + subject + "</b><br/>";
if (body != "")
commentHTML += body;
commentHTML += "</p>";
commentHTML += "<b>Posted "; 		 	
if (name != "")
{
commentHTML += "by " + name;
if (state != "")
commentHTML += ", " + state;
if (country != "")
commentHTML += ", " + country;
}
if (date != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime(date);
// format the date by users locale
commentHTML += " on " + d.toLocaleString();
}
commentHTML += "</b>";
}
// alert(commentHTML);
commentsDiv = document.getElementById('comments');
commentsDiv.innerHTML = commentHTML;
}
}
}
/* */
function commentCount(n)
{
var commentCount = document.getElementById('commentsCount');
if (commentCount != null)
{
commentCount.innerHTML = "<a href='#commentBox'>" + n + " comments posted</a>";
}
}
/* */
function eipValidation(divid)
{
var isValid = true;
// get the container
var eipContain = document.getElementById('eipcontainer');
var eipForms = null;
// get the form
if (eipContain != null)
{
eipForms = eipContain.getElementsByTagName('form');
}
for (i =0; i < eipForms.length; i++)
{
// switch to diff function based on divid, passing the form
switch(divid)
{
case "register":
isValid = registerValidate(eipForms[i]);
break;
case "signin":
isValid = signinValidate(eipForms[i]);
break;
case "forgotpw":
isValid = forgotpwValidate(eipForms[i]);
break;
case "profile":
isValid = profileValidate(eipForms[i]);
break;
case "revalidate":
isValid = revalidateValidate(eipForms[i]);
break;
default:
isValid = signinValidate(eipForms[i]);
}
}
// return var
// get the general error div
var gen_error_div = document.getElementById('gen_error');
if (gen_error_div != null)
{
if (!isValid)
{
// set the general error
gen_error_div.innerHTML = "We're sorry. We encountered some errors in the form. "+
"Please review and correct the errors as marked in the "+
"highlighted fields below.";
// gen_error_div.className = "p_error";
gen_error_div.style.display = "block";
// resize the iframe
} else {
gen_error_div.innerHTML = "";
gen_error_div.style.display = "none";
}
}
parent.resizeFrame(getDivSize());
return isValid;
}
function setError(eName,msg)
{
// on error set e_<form.element.name>.innerhtml to errormsg
var errorDiv = document.getElementById('commentmessage');
if (errorDiv != null)
{
errorDiv.innerHTML = msg;
errorDiv.style.color = "red";
errorDiv.style.fontWeight = "bold";
errorDiv.style.display = "block";
}
// 	set p_<form.element.name>.class to p_error
//var errorP = document.getElementById('p_'+ eName);
//if (errorP != null)
//	errorP.className = "p_error";
//var errorF = document.getElementById(eName);
//if (errorF != null)
//{
//	errorF.style.background = "#E0AFAF";
//}
}
function clearError(eName)
{
// on error set e_<form.element.name>.innerhtml to errormsg
var errorDiv = document.getElementById('commentmessage');
if (errorDiv != null)
{
errorDiv.innerHTML = "";
errorDiv.style.display = "none";
}
// 	set p_<form.element.name>.class to p_error
var errorP = document.getElementById('p_'+ eName);
if (errorP != null)
errorP.className = "";
var errorF = document.getElementById(eName);
if (errorF != null)
{
errorF.style.background = "#FFFFFF";
}
}
function commentValidate(form)
{
var regValid = true;
// loop through form elements
for (j =0; j < form.elements.length; j++)
{
// check fname
if (form.elements[j].name == "firstName")
{
if (form.elements[j].value == "")
{
setError(form.elements[j].name,"Please enter your first name.");
regValid = false;
}
}
// check comment
if (form.elements[j].name == "comment")
{
if (form.elements[j].value == "" || form.elements[j].value == "Enter your comment here.")
{
setError(form.elements[j].name,"Please enter a comment.");
regValid = false;
}
}
}
return regValid;
}
