
// DIP
var DIPenabled = true;	
/* Add onload event for the top right eip status */
// addLoadEvent(updateStatusBug);		
/* Translation functions */
var lang = "en_US";
var translations = {
"yourcomments":{"en":"Fan Feedback"},
"latestcomments":{"en":"Latest Feedback"},
"postedby":{"en":"Posted By"},
"ondate":{"en":" on "},
"charremain1":{"en":""},
"charremain2":{"en":" characters remain"},
"thankyou":{"en":"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."},
"submitanother":{"en":"Submit another comment?"},
"errfirstname":{"en":"Please enter your name."},
"errlastname":{"en":"Please enter your last name."},
"erremail1":{"en":"Please enter your Email address."},
"erremail2":{"en":"Email address seems incorrect (check @ and .'s)"},
"erremail3":{"en":"The username doesn't seem to be valid."},
"erremail4":{"en":"Destination IP address is invalid!"},
"erremail5":{"en":"The domain name doesn't seem to be valid."},
"erremail6":{"en":"The address must end with a domain, or two letter country code."},
"erremail7":{"en":"This address is missing a hostname!"},
"errcountry":{"en":"Please choose a country."},
"errcomment":{"en":"Please enter a comment."},
"errterms":{"en":"Please accept the Terms and Conditions."},
"commentsposted":{"en":"comments posted"}
// "":{"en":"","fr":"","es":""}
};
var weekday = { "weekdays":[
{"en":"Sunday" }, 
{"en":"Monday" }, 
{"en":"Tuesday" }, 
{"en":"Wednesday"},
{"en":"Thursday" }, 
{"en":"Friday" },
{"en":"Saturday" }
]
};
var month = {"months":[
{"en":"January" }, 
{"en":"February" }, 
{"en":"March" }, 
{"en":"April" }, 
{"en":"May" }, 
{"en":"June" }, 
{"en":"July" }, 
{"en":"August" }, 
{"en":"September"},
{"en":"October" },
{"en":"November" },
{"en":"December" }
]
};
var responseActionResult = "isnull"; 
function translate(keyid) {
var returnStr = "";
var sh_lang = lang.substring(0,2);
// console.debug(sh_lang);
try
{
returnStr = eval("translations[keyid]."+sh_lang);
}
catch(err)
{
// console.error(err);
returnStr = keyid;
}
return returnStr;
}
function getLongDate(dateObj)
{
var longDate = "";
// date format: weekday month date, year
longDate = weekday.weekdays[dateObj.getUTCDay()].en +", " + dateObj.getUTCDate() + " " +month.months[dateObj.getUTCMonth()].en+ ", " + dateObj.getUTCFullYear()
//console.debug(longDate);
return longDate;
}
// IP Address capture
var ip_address;
function alertIP(ipval) {
// alert(">> ipval: " + ipval);
ip_field = document.getElementById('ip_address');
if (ip_field != null)
{
ip_field.value = ipval;
}
}			
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
function sendToActionScript() {
ip_field = document.getElementById('ip_address').value;
if (ip_field == "")
{
thisMovie("iptracker").getUserIP();
}
}
function textCounter(field,cntfield,maxlimit) 
{
var maxChar = "";
if (field.value.length > maxlimit) 
{ // if too long...trim it!
field.value = field.value.substring(0, (maxlimit));
if (cntfield != "")
{
document.getElementById(cntfield).innerHTML = "Characters Remaining - 0";
} else {
alert("Characters Remaining - 0");
}
} else {
if (cntfield != "")
{
document.getElementById(cntfield).innerHTML = "Characters Remaining - " + (maxlimit - field.value.length);
}
}
}
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";
}
}
var firstsubmit = true;
function reportComment(id)
{
if (id != null && id != "")
{
var postURL = "/eipatron/reportComment.do";
var postQuery = "c="+id;
// call the ajax function
$.ajax({
url: postURL,
data: postQuery,
type: 'POST',
dataType: 'xml',
timeout: 15000,
error: function(){
// alert('An error has occured, please reload the page.');
},
success: function(xml) {
onReportResponse(xml, id)
}
});
}
}
function onReportResponse(xmlDoc,id)
{
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// get the div info
var msgTxt = "";
// if response is not successful show errors
if (status == "Success")
{
msgTxt = 	"<b>Comment Reported</b>";
} else {
// default message
msgTxt = "An error has occurred. Please try to submit your comment again.";
// 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>";
}
}
}
if (document.getElementById('reportLink_'+id) != null)
{
document.getElementById('reportLink_'+id).innerHTML = msgTxt;
}				
}			
function submitForm(form,divid)
{
var postURL = "";
var postQuery = "";
var emailQuery = "";
var subscribe = false;
var measureId = "CommentCount_"+pageId+"_comment_submit";
if (!firstsubmit)
{
return;
}
// check for a comment
if (divid == "commentform" || divid == "replyform")
{
if (!commentValidate(form))
{
// there are errors so return false
return false;
} 
}
// validated, set submit flag to false
firstsubmit = false;
// get the action from the form
if (replyId != null && replyId != '')
{
postURL += "/eipatron/replyNoLogin.do";
} else {
postURL += 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 if (form.elements[i].type == "checkbox")
{
if(form.elements[i].name == "news" && form.elements[i].checked)
{
subscribe = true;
}
} else {
var elementValue = form.elements[i].value;
// combine the ip and email
if (form.elements[i].name == "emailAddress")
{
// add the value to the newsletter queryStr
emailQuery += (emailQuery.length == 0)?"":"&";
emailQuery += "Email="+encodeURIComponent(elementValue);
// get the ip
var ipaddr = document.getElementById('ip_address');
if (ipaddr != null)
{
// prepend it to the email addr
elementValue = ipaddr.value + "|" + elementValue;
}
}
if (form.elements[i].name == "firstName")
{
emailQuery += (emailQuery.length == 0)?"":"&";
emailQuery += "FirstName="+encodeURIComponent(elementValue);
}
if (form.elements[i].name == "lastName")
{
emailQuery += (emailQuery.length == 0)?"":"&";
emailQuery += "LastName="+encodeURIComponent(elementValue);
}
// update the submission info
// c
if (form.elements[i].name == "c")
{
elementValue = pageId;
}
// c
if (form.elements[i].name == "parent")
{
elementValue = replyId;
}
// subject
if (form.elements[i].name == "subject")
{
elementValue = pageTitle;
}
if (form.elements[i].name != undefined) {
// first item starts the query str
postQuery += (i == 0)?"":"&";
postQuery += encodeURIComponent(form.elements[i].name) + "=" + encodeURIComponent(elementValue);
}
}
}
//alert(postQuery);
if (form.elements[i].name == "type")
{
measureId = 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;
case "replyform":
responseAction = onCommentResponse;
break;
default:
responseAction = onCommentResponse;
}				
// make a measurement call
measureComment(measureId);
if(!subscribe)
{
emailQuery = "";
}
/* if (window.console && window.console.error) {
console.error(postURL+"?"+postQuery);
} */			
// call the ajax function
$.ajax({
url: postURL,
data: postQuery,
type: 'POST',
dataType: 'xml',
timeout: 15000,
error: function(){
// alert('An error has occured, please reload the page.');
},
success: function(xml){
var comment_cookie = 'UserName='+document.getElementById('firstName').value+'&Country='+document.getElementById('country').value;
if (document.location.href.indexOf('noreg')>-1) { writeSessionCookie('USOpenUser',comment_cookie); }
responseActionResult = responseAction(xml,emailQuery);
if(showResponseMessage) {
showResponseMessage(responseActionResult, replyId);
}
}
});
// form submitted without errors
return true;
}
function onCommentResponse(xmlDoc,email) {
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// get the div info
var msgDiv = document.getElementById('msgbox');
var msgTxt = "";
// if response is not successful show errors
if (status == "Success")
{
msgTxt = "<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 may not appear on "+
"the site.</b>";
/*
msgTxt = "<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 may not appear on "+
"the site.</b><br/><a href='javascript:void(0)' class='blue2' "+
"onClick='document.getElementById(\"postmsg\").style.display=\"none\";'><b>"+ 
"Submit another comment?</b></a>";
*/
// clear the form
var thisForm = document.getElementById('comment_form');
if (thisForm != null)
{
thisForm.reset();
}
// set firstsubmit flag to true
firstsubmit = true;
// if they want to subscribe to the email call the email function
if (email != null && email != "")
{
emailSubscribe(email);
}
if (document.getElementById('close') != null)
{
document.getElementById('close').innerHTML = '<a href="javascript:void(0)" class="closebtn" id="closebtn"><b>Close</b></a>';
}				
} else {
// default message
msgTxt = "An error has occurred. Please try to submit your comment again.";
// allow resubmit
firstsubmit = true;
// 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 = "<b>Please <a href='javascript:void(0)' onclick='popOver(\"login\");'>sign in</a> to submit your comment</b>";
} else {
msgTxt = "<b>"+errorTxt+"</b>";
}
}
// change the close button to hide the msg box instead of closing window
if (document.getElementById('close') != null)
{
document.getElementById('close').innerHTML = '<a href="javascript:void(0)" onClick="document.getElementById(\'postmsg\').style.display = \'none\';"><b>Close</b></a>';
}				
}
msgDiv.innerHTML = msgTxt;
if (document.getElementById('postmsg') != null)
{
document.getElementById('postmsg').style.display = 'block';
}
return status;
}
function emailSubscribe(email)
{
if (email != null && email != "")
{
/* if (window.console && window.console.error) {
console.error("http://assets.tennis.com.au/email_newsletter/subscribe.asp?"+email);
} */
var emailFrm = document.createElement('iframe');
emailFrm.style.display = 'none';
emailFrm.src = 'http://assets.tennis.com.au/email_newsletter/subscribe.asp?'+email;
document.body.appendChild(emailFrm);
return;
}			
}
/* 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(xmlDoc)
{
var commentHTML = "";
var parentCmt = "";
// 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 = '';
cdate = '';
id = '';
depth = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "id": id = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "depth": depth = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
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": cdate = 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;
}
}
var indent = "";
if (depth > 1) 
{ 
commentHTML += "<div class='replyItem' id='replyItem_"+parentCmt+"_"+j+"'>";
}
else
{
commentHTML += "<div class='commentItem'>";
parentCmt = id;
}
// write the report stuff
if (id != "")
{
commentHTML += "<div id='reportLink_"+id+"' class='reportLink'><a href='javascript:void(0);' onClick='reportComment("+id+")'>Report Comment</a></div>";
}
if (name != "")
{
commentHTML += "<div class='fanInfo'>" + name;
if (country != "")
commentHTML += ", " + country;
if (cdate != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime(cdate);
// format the date by users locale
commentHTML += "<span class='dateInfo'> on " + d.toLocaleString() + "</span>";
}
commentHTML += "</div>";
}
if (body != "")
commentHTML += "" + body + "";
if (depth == 1) // write the reply stuff
{
commentHTML += '<div class="replyBar">';
commentHTML += '	<div id="replyToggle_'+id+'" class="replyToggle"><a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+id+'\')">Close Replies</a>&nbsp;&nbsp;&nbsp;|</div>'
commentHTML += ' ';
commentHTML += '	<div id="replyLink_'+id+'" class="replyLink"><a class="reply" href="JavaScript:setReply(\''+id+'\')">Reply</a></div>';
commentHTML += ' <div id="replyForm_'+id+'" class="replyForm"></div>';
commentHTML += '</div>';
}
commentHTML += "</div>";
}
// alert(commentHTML);
commentsDiv = document.getElementById('comments');
commentsDiv.innerHTML = commentHTML;
}
//}
}
function getCommentsDesc(xmlDoc)
{
var commentHTML = "";
var parentCmt = "";
var replies = new Array();
// 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 = commentNodes.length -1; i > -1; i--) 
{
commentData = commentNodes.item(i).childNodes;
commentCell = '';
cdate = '';
id = '';
depth = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "id": id = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "depth": depth = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
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": cdate = 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;
}
}
var indent = "";
if (depth > 1) // this is a reply, add it to an array
{ 
//if (window.console) { console.debug("reply "+id); }
replies.push([id,depth,name,country,cdate,body]);
//if (window.console) { console.debug("total replies "+replies.length+" : "+replies); }
}
else
{
//if (window.console) { console.debug("comment "+id); }
commentHTML += "<div class='commentItem'>";
// write the report stuff
if (id != "")
{
commentHTML += "<div id='reportLink_"+id+"' class='reportLink'><a class='blueLink4' href='javascript:void(0);' onClick='reportComment("+id+")'>Report Comment</a></div>";
}
if (name != "")
{
commentHTML += "<div class='fanInfo'>" + name;
if (country != "")
commentHTML += ", " + country;
if (cdate != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime(cdate);
// format the date by users locale
commentHTML += "<span class='dateInfo'> on " + d.toLocaleString() + "</span>";
}
commentHTML += "</div>";
}
if (body != "")
commentHTML += "" + body + "";
if (depth == 1) // write the reply stuff
{
commentHTML += '<div class="replyBar">';
commentHTML += '	<div id="replyToggle_'+id+'" class="replyToggle">';
if (replies.length > 0)
{
commentHTML += '<a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+id+'\')">Close Replies</a>' + '&nbsp;&nbsp;&nbsp;|';
}
commentHTML += '</div>';
commentHTML += '	<div id="replyLink_'+id+'" class="replyLink"><a class="reply blueLink4" href="JavaScript:setReply(\''+id+'\')">Reply</a></div>';
commentHTML += ' <div id="replyForm_'+id+'" class="replyForm"></div>';
commentHTML += '</div>';
}
commentHTML += "</div>";
parentCmt = id;
// if there are replies, write their divs here
for (k = replies.length -1; k > -1; k--)
{
//if (window.console) { console.debug("writing reply "+replies[k][0]); }
commentHTML += "<div class='replyItem' id='replyItem_"+parentCmt+"_"+k+"'>";
// write the report stuff
if (id != "")
{
commentHTML += "<div id='reportLink_"+replies[k][0]+"' class='reportLink'><a class='blueLink4' href='javascript:void(0);' onClick='reportComment("+replies[k][0]+")'>Report Comment</a></div>";
}
if (replies[k][1] != "")
{
commentHTML += "<div class='fanInfo'>" + replies[k][2];
if (country != "")
commentHTML += ", " + replies[k][3];
if (cdate != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime(replies[k][4]);
// format the date by users locale
commentHTML += "<span class='dateInfo'> on " + d.toLocaleString() + "</span>";
}
commentHTML += "</div>";
}
if (body != "")
commentHTML += "" + replies[k][5] + "";
commentHTML += "</div>";
}
// reset the array
replies = new Array(); 		 	
}
}
// alert(commentHTML);
commentsDiv = document.getElementById('comments');
commentsDiv.innerHTML = commentHTML;
}
}
function getCommentsPg(xmlDoc)
{
var commentHTML = "";
// 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;
var startId = '';
if (countNode.length > 0)
{
count = countNode[0].childNodes[0].nodeValue;
}
if (count > 0)
{
// Set the comment count
if (pgCmt)
{
commentCount(count -1);
} else {
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 = '';
cdate = '';
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": cdate = 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 += "<div class='aihComment'>";
//if (subject != "")
//	commentHTML += "<b>Re:" + subject + "</b><br/>";
if (name != "")
{
commentHTML += "<div id='fanInfoATE'>" + name;
//if (state != "")
//	commentHTML += ", " + state;
if (country != "")
commentHTML += ", " + country;
commentHTML += "</div>";
}
if (body != "")
commentHTML += body + "<br/>";
if (cdate != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime(cdate);
// format the date by users locale
commentHTML += d.toLocaleString();
}
commentHTML += "</div>";
}
if (maxCmt > 0 && count > maxCmt)
{
commentHTML += "<p class='newsBackToTop' align='right'><a href='javascript:void(0)' onclick='loadComments(pageId,0)'>View All Comments</a></p>";
}
if (count > 0)
{
commentHTML += "<p class='newsBackToTop' align='right'><a href='#'>Back to Top</a></p>";
}
// alert(commentHTML);
commentsDiv = document.getElementById('comments');
commentsDiv.innerHTML = commentHTML;
}
//}
}
function loadComments(pgid,cnt,cts,intl)
{
if (pgid != null)
{
var nNVP = "";
var sNVP = "";
var iNVP = "";
if (cnt != null && cnt > 0)
{
nNVP = "&n="+cnt;
}
if (cts != null && cts != '')
{
sNVP = "&start="+cts;
}
if (intl != null && intl != '')
{
iNVP = "&interval="+intl;
}
var commentURI = "/eipatron/discussionThread.do?c="+pgid+nNVP+sNVP+iNVP;
$.ajax({
url: commentURI,
type: 'GET',
dataType: 'xml',
success: function(xml){
getComments(xml)
}
});
}			
}
function commentCount(n)
{
var commentCount = document.getElementById('commentsCount');
if (commentCount != null)
{
//					commentCount.innerHTML = '<a href="#commentBox">' + n + ' comments posted</a>';
commentCount.innerHTML = n + ' comments posted';
}
}
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)
{
var msgDiv = document.getElementById('commentmessage');
//alert(msgDiv);
if (msgDiv != null)
{
msgDiv.innerHTML = msg;
} else {
// check for an element specific div
var errDiv = document.getElementById('e_'+eName);
if (errDiv != null)
{
errDiv.innerHTML = msg;
errDiv.style.display = "block";
} else {
alert(msg);
}
}
}
function clearError(eName)
{
// on error set e_<form.element.name>.innerhtml to errormsg
var errorDiv = document.getElementById('e_'+ eName);
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 f name
if (form.elements[j].name == "firstName")
{
if (form.elements[j].value == "")
{
setError(form.elements[j].name,"Please enter your user name.");
regValid = false;
return regValid;
}
else
{
// clean the entry
form.elements[j].value = scrubText(form.elements[j].value);
} 
}
// check l name
/* if (form.elements[j].name == "lastName")
{
if (form.elements[j].value == "")
{
setError(form.elements[j].name,"Please enter your last name.");
regValid = false;
return regValid;
}
} */
// check email
/* if (form.elements[j].name == "emailAddress")
{
if (form.elements[j].value != "")
{
// check email format
var errorTxt = emailCheck2(form.elements[j].value);
if (errorTxt != "")
{
setError(form.elements[j].name, errorTxt);
// form.elements[j].value = "";
regValid = false;
return regValid;
}
}
else
{
setError(form.elements[j].name,"Please enter your Email address.");
regValid = false;
return regValid;
}
} */
// check country
if (form.elements[j].name == "country")
{
if (form.elements[j].selectedIndex == 0)
{
setError(form.elements[j].name,"Please choose a country.");
regValid = false;
return regValid;
}
}
// check comment
if (form.elements[j].name == "comment")
{
if (form.elements[j].value == "")
{
setError(form.elements[j].name,"Please enter a comment.");
regValid = false;
return regValid;
}	
else
{
form.elements[j].value = scrubText(form.elements[j].value);
}	
}
// check t's and c's
/* if (form.elements[j].name == "terms")
{
if (form.elements[j].type == "checkbox" && !form.elements[j].checked)
{
setError(form.elements[j].name,"Please accept the Terms and Conditions.");
regValid = false;
return regValid;
}	
} */
}
return regValid;
}
function countryLookup(ccode)
{
countryName = ccode;
if (myCountries != null)
{
for (i=0; i < myCountries.countries.length; i++)
{
if (myCountries.countries[i].ctrycode == ccode)
{
countryName = myCountries.countries[i].ctryname;
}
}
}
return countryName;
}
function scrubText(instr)
{
var newstr = "";
for (i =0; i < instr.length; i++)
{
if (instr.charCodeAt(i) > 30 && instr.charCodeAt(i) < 256)
{
newstr += instr.charAt(i);
}
else 
{
newstr += "_";
}
}
return newstr;
}
function charAlert(instr)
{
var allChars = document.getElementById('charDiv');
allChars.innerHTML = "";
for (i = instr; i > 0; i--)
{
allChars.innerHTML += String.fromCharCode(i) + "<br/>";
}
}
function emailCheck2 (emailStr) 
{
var errMsg = "";
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) 
{
errMsg = "Email address seems incorrect (check @ and .'s)";
return errMsg;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) 
{
errMsg = "The username doesn't seem to be valid.";
return errMsg;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) 
{
for (var i=1;i<=4;i++) 
{
if (IPArray[i]>255) 
{
errMsg = "Destination IP address is invalid!";
return errMsg;
}
}
return errMsg;
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
errMsg = "The domain name doesn't seem to be valid.";
return errMsg;
}
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) 
{
errMsg = "The address must end with a domain, or two letter country code.";
return errMsg;
}
if (len<2) 
{
errMsg = "This address is missing a hostname!";
return errMsg;
}
return errMsg;
}		
function measureComment(id) {
var refPage = document.location.href.substring(0,document.location.href.indexOf(".html"));
var url = refPage + "_" + id + ".html";
// alert(url);
if (window.sa_onclick){
sa_onclick(url);
}
}
function closeReply(id,state)
{
var commentDiv = document.getElementById('comments');
if (commentDiv != null)
{
if (id != null && id != "")
{
var replyDivs = commentDiv.getElementsByTagName('div');
for (i =0; i < replyDivs.length; i++)
{
if (replyDivs[i].id.indexOf("replyItem_"+id) > -1)
{
if (window.console && window.console.debug)
console.debug(replyDivs[i].style.display);
if (replyDivs[i].style.display == "none")
{
replyDivs[i].style.display = "block";
// set the text to close
if (document.getElementById('replyToggle_'+id) != null)
{
document.getElementById('replyToggle_'+id).innerHTML = '<a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+id+'\',\'none\')">Close Replies</a>' + '&nbsp;&nbsp;&nbsp;|';
}
} else {
replyDivs[i].style.display = "none";
// set the text to close
if (document.getElementById('replyToggle_'+id) != null)
{
document.getElementById('replyToggle_'+id).innerHTML = '<a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+id+'\',\'display\')">Open Replies</a>' + '&nbsp;&nbsp;&nbsp;|';
}
}
}
}
} else {
var stateFlg = "";
if (state != null && state !="")
{
stateFlg = state;
} else {
stateFlg = "none";
}
var replyDivs = commentDiv.getElementsByTagName('div');
for (i =0; i < replyDivs.length; i++)
{
if (replyDivs[i].className == "replyItem")
{
if (window.console && window.console.debug)
console.debug("plonk!!?! "+ stateFlg);
replyDivs[i].style.display = stateFlg;
}
if (replyDivs[i].className == "replyToggle" && replyDivs[i].innerHTML != "")
{
var replyId = replyDivs[i].id.substring((replyDivs[i].id.lastIndexOf('_')+1));
if (window.console && window.console.debug)
console.debug(replyId);
if (state == "none")
{
replyDivs[i].innerHTML = '<a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+replyId+'\',\'block\')">Open Replies</a>' + '&nbsp;&nbsp;&nbsp;|';
} else {
replyDivs[i].innerHTML = '<a class="blueLink4" href="javascript:void(0)" onClick="closeReply(\''+replyId+'\',\'none\')">Close Replies</a>' + '&nbsp;&nbsp;&nbsp;|';
}
}
}
var commentReplyBtn = document.getElementById('commentReply');
if (commentReplyBtn != null)
{
if (state == "none")
{
commentReplyBtn.innerHTML = '<a class="white" href="javascript:void(0)" onclick="closeReply(\'\',\'block\')">Open All Replies</a>';
} else {
commentReplyBtn.innerHTML = '<a class="white" href="javascript:void(0)" onclick="closeReply(\'\',\'none\')">Close All Replies</a>';
}
}
}
}
}		
function setReply(id)
{
if (id != null && id != '')
{
// load the pop up
replyId = id;
document.getElementById('replyForm_'+replyId).innerHTML = 
'<div id="divComments'+replyId+'" class="divComments">' +
'<iframe style="width:100%";" id="ifComments'+replyId+'" scrolling="auto" marginheight="0" marginwidth="0" frameborder="0"></iframe>' +
'</div>';
showCommentForm(replyId);
} // if id
} //function setReply
