version = navigator.appVersion.toLowerCase();
agent = navigator.userAgent.toLowerCase();
ie = (version.indexOf('msie')>-1);
win = (version.indexOf('windows')>-1);
opera = (agent.indexOf('opera')>-1);

function getE( Id ) {
	return document.getElementById( Id )  ;
}

function GetE( Id ) {
	return getE( Id );
}

function isset(varname) {
  return (typeof(window[varname])!= 'undefined');
}

function isSet(varname) {
  return (isset(varname));
}

function var_dump ( obj ) {
	var details;
	var fieldContents;
	var tab = "  "
	if (arguments[1]) { tab += arguments[1]; }
  for (var field in obj) {
    fieldContents = obj[field];
    if (typeof(fieldContents) == "function") {
      fieldContents = "(function)";
    }
    details += tab + field + " (" + typeof(fieldContents) + "): " + fieldContents + "\n";
    if (typeof(fieldContents) == "object") {
    	details += var_dump (fieldContents,tab)
		}
  }
  return details;
}

var urlprocess = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}

function toggleList (w) {
/*
 * Opens and closes folders (expandable sitemap)
 */
	ul=w.nextSibling.nextSibling.nextSibling;

	if(ul)
		if (ul.nodeName.toLowerCase()=="ul")
			if(ul.className=="off"){
				ul.className="on"
				w.className="open on"
			} else {
				ul.className="off"
				w.className="open off"
			}
	return false;
}

function toggleDisplay (Id) {
/*
 * Shows and hides elements of the given Id 
 */
	if (document.getElementById(Id)) {
		if (document.getElementById(Id).style.display == "block") {
			document.getElementById(Id).style.display = "none";
		} else {
			document.getElementById(Id).style.display = "block";
		}
	return true;
	} else {
	return false;
	}
}

function writePrint(Text) {
	document.write('\074a class="Print" href=\"javascript:window.print();\"\076'+Text+'\074span\076\074/span\076\074/a\076');
}

function writeAddToFavorite(Text,URL,WebName) {
	if ((opera) && (win)) return false;
	else if ((ie) && (win)) document.write('\074a class="AddToFavorite" href='+"'javascript:window.external.addFavorite(\""+URL+"\",\""+WebName+"\")'"+'\"\076'+Text+'\074span\076\074/span\076\074/a\076 \074span class="Separator"\076|\074/span\076');
	return false;
}

/*
 * Opens gallery picture
 */

function OpenGalleryImage (Address) {
	width = 820;
	leftPos = (window.screen.width/2)-(width/2);
	height = (window.screen.height-200);
	topPos  = ((window.screen.height)/2)-(height/2)-30;
	CloseGalleryImageWindow ();
	return window.open (Address,"ImageWindow","width="+width+", height="+height+", left="+leftPos+", top="+topPos+",dependent=yes, titlebar=no, scrollbars=yes, resizable=yes, status=no");
}

function CloseGalleryImageWindow () {
	if (window.ImageWindow && !window.ImageWindow.closed)	ImageWindow.close()
}

/* Perform functions on unload */
function LeavePage () {
	CloseGalleryImageWindow ();
}

function removeElementById (Id) {
	if (!document.getElementById) return false;
	if (!document.getElementById(Id)) return false;
	return document.getElementById(Id).parentNode.removeChild(document.getElementById(Id));
}
function scrollPageToId(id) {
	if (!document.getElementById) return false;
	if (!document.getElementById(id)) return false;
	scrollPageToObj ( document.getElementById(id) );
}

function scrollPageToObj( obj ) {
	var topPos = 0;
	var leftPos = window.pageXOffset || document.documentElement.scrollLeft;
	var offset = 0;
	if (arguments[1]) offset = arguments[1];  
	if (obj.offsetParent) {
		topPos = obj.offsetTop
		while (obj = obj.offsetParent) {
			topPos += obj.offsetTop
		}
	}
	topPos += offset;
	if (topPos<0) topPos = 0;
	window.scrollTo(leftPos,topPos);
}


/*
 * Article rating
 */
 
var articleratingDiv;

function SubmitArticleRating ( Script ) {

	Script += "&rating=" + getE("RatingValue").value;
	Script += "&" + "ArticleRating" + "Submit";
	
	return PM_ajax.openHttpRequest ( "GET", Script, true, "articleratingHandleServerResponse()" );

}

function articleratingHandleServerResponse () {

	// vote in the poll
	var Div = document.getElementById ( "ArticleRating" );
	var response = PM_ajax.XmlHttp.responseText;
	Div.innerHTML = response;

}

/*
 * Article rating end
 */

function ActivateJavascriptStyles() {
	// this function should be called right after the body tag
	// it makes it possible to create special css definitions just by
	// editing the css file without any need for extra scripting
	// these css definitions will be available only if javascript is on
	// in the html code you do not have to check whether JS is on or off any more 
	var js_on = "JS_On";
	if (document.body.className == "")
		document.body.className = js_on
	else
		document.body.className += " " + js_on
}

function RegisterFieldsetSwitcher ( id ) {
	if ( getE(id+"Switcher") && getE(id+"Content") ) {
		if (getE(id+"Switcher").checked) {
			getE(id+"Content").style.display = ""
		} else {
			getE(id+"Content").style.display = "none"
		}
	}
}


var commentReply = {
	active : false ,                              // status of the entire plugin (set true after everything is loaded)
	activationAllowed : false ,                   // status of the entire plugin (set true before the entire structure is loaded)
	idsArray : new Array() ,                      // array with comment ids 
	divId : false ,                               // active comment Id
	formHTML : false ,                            // just a reference to the main form 
	jsFormHTML : false ,                          // will be used to store the predefined HTML
	jsFormHTMLFakeAS : false ,                    // will be used to store the predefined HTML without anti-spam question
	localFormName : "CommentFormLocalForm",       // prefix of the local form Id  
	submitButton : "LocalCommentSubmit",          // submit button Id
	translations : Array(),                       // predefined translations
	replyButtonDisplayStyle : false,              // enables hiding of "reply to" buttons
	currentTRClass : "",                          // enables dynamic generation of different classes for odd and even lines in local form
	fakeAntiSpamQuestion : false,                 // (dis)allows js to fill in anti-spam question 
	smileysDiv : "",                              // activates smileyhelp 

	loadHTML : function ( sHTML ) {
		// loads the predefined HTML definition to be used as the local form
		this.jsFormHTML = sHTML[0]+sHTML[1]+sHTML[2];  
		this.jsFormHTMLFakeAS = sHTML[0]+sHTML[2];  
	} ,

	activate : function () {
		// halt activation if the HTML definition not found
		if (!this.jsFormHTML) return false
		if (this.fakeAntiSpamQuestion) this.jsFormHTML = this.jsFormHTMLFakeAS;
		// just in case...
		if (!document.getElementById) return false
		// translate form labels
		for(i in this.translations) {
			this.jsFormHTML = this.jsFormHTML.replace("%%"+i+"%%",this.translations[i])
		}
		// We're (almost) ready to rock'n'roll
		this.activationAllowed = true
	} ,

	launchActive : function () {
		// OK, we're REALLY ready to rock'n'roll
		this.active = this.activationAllowed
	} ,


	hideRelTree : function () {
		if (!this.activationAllowed) return
		// hide the select with reply to values
		if ( document.getElementById("AddCommentRelTR") ) document.getElementById("AddCommentRelTR").style.display = "none"
		// save reference to the main form
		this.formHTML = document.getElementById("CommentFormMain");
	} ,

	writeLink : function(Text,Id,commentId) {
		// function writes out 'Reply to' buttons
		if (!this.activationAllowed) return
		this.idsArray[Id] = commentId;
		t = '<a href="#CommentFormMain" id="ReplyToCommentId'+Id+'" onclick="return commentReply.getReplyForm(\''+Id+'\')" class="CommentReply">'+Text+'<span></span></a>'
		document.write(t)
	} ,
	
	translateAntiSpamQuestion : function () {
		// Translates the anti-spam question
		if (document.getElementById("AntiSpamQuestionTextCommentForm")) {
			this.translations["AntiSpamQuestionText"] = document.getElementById("AntiSpamQuestionTextCommentForm").innerHTML;
			this.jsFormHTML = this.jsFormHTML.replace("%%AntiSpamQuestionText%%",this.translations["AntiSpamQuestionText"])
		}
	} ,

	getReplyForm : function (Id) {
		if (!this.formHTML || !this.active) return false;
		cId = this.idsArray[Id];
		// store values from the old local form in the main form (if there is any)
		this.saveValues();
		// Read the antispam question and update the local form with the translation
		this.translateAntiSpamQuestion();
		// create new form container and fill it with predefined HTML
		newDiv = document.createElement("div");
		newDiv.setAttribute("id",this.localFormName+Id);
		newDiv.innerHTML = commentReply.jsFormHTML;
		document.getElementById(cId).appendChild(newDiv);
		commentReply.writeSmileys ("SmileysAutoAddExtra");
		// set the trigger and load values
		this.divId = Id
		// fill the new local form with values 
		this.loadValues()
		// scroll to form
		scrollPageToId(this.localFormName+Id,-70);
		// disable link (does not jump to main form)
		return false;
	} ,

	cancelReply : function () {
		if (!this.formHTML || !this.active) return false;
		// store values from the local form in the main form (if there is any)
		this.saveValues();
		// reset the "reply to" value
		if (document.getElementById("AddCommentRelId")) document.getElementById("AddCommentRelId").value = 0;
		// show the real form
		this.showRealForm();
		// scroll to the main form
		scrollPageToId("CommentFormMain");
		// disable link (does not jump to main form)
		return false;
	} ,

	loadValue : function(t) {
		// reads value of the "main form" and stores it in the "local form"
		if (document.getElementById("LocalComment"+t) && document.getElementById("AddComment"+t))
			document.getElementById("LocalComment"+t).value = document.getElementById("AddComment"+t).value
	} ,

	loadValues : function () {
		// load values from the main form
		this.loadValue("Name")
		this.loadValue("Email")
		this.loadValue("WWW")
		this.loadValue("Title")
		this.loadValue("Comment")
		// Load anti-spam answer
		if (document.getElementById("FormVerificationAnswer") && document.getElementById("LocalFormVerificationAnswer")) 
			document.getElementById("LocalFormVerificationAnswer").value = document.getElementById("FormVerificationAnswer").value
		// Hide the real form
		this.hideRealForm()
		// Hide the "Reply Button"
		if (this.divId) {
			this.replyButtonDisplayStyle = document.getElementById('ReplyToCommentId'+this.divId).style.display; 
			document.getElementById('ReplyToCommentId'+this.divId).style.display = 'none';
		}
	} ,

	saveValue : function (t) {
		// reads value of the "local form" and stores it in the "main form"
		if (document.getElementById("LocalComment"+t) && document.getElementById("AddComment"+t))
			document.getElementById("AddComment"+t).value = document.getElementById("LocalComment"+t).value
	} ,

	saveValues : function () {
		if (!this.divId) return false
		// store form values in the main form
		this.saveValue("Name")
		this.saveValue("Email")
		this.saveValue("WWW")
		this.saveValue("Title")
		this.saveValue("Comment")
		// Save anti-spam answer
		if (document.getElementById("FormVerificationAnswer") && document.getElementById("LocalFormVerificationAnswer")) 
			document.getElementById("FormVerificationAnswer").value = document.getElementById("LocalFormVerificationAnswer").value
		// store the "reply to" value
		if (document.getElementById("AddCommentRelId")) document.getElementById("AddCommentRelId").value = this.divId
		// kill the "local form"
		removeElementById (this.localFormName+this.divId);
		// show (restore) reply button
		if (this.replyButtonDisplayStyle) document.getElementById('ReplyToCommentId'+this.divId).style.display = this.replyButtonDisplayStyle
			else document.getElementById('ReplyToCommentId'+this.divId).style.display = 'inline'
		// kill reference to the local form
		this.divId = false
	} ,
	
	getTRClass : function () {
		if (this.currentTRClass == "OddRow")
			this.currentTRClass = "EvenRow"
		else
			this.currentTRClass = "OddRow"
		return this.currentTRClass; 
	} ,

	hideRealForm : function () {
		// hide the form
		this.formHTML.style.display = "none";
	} ,

	showRealForm : function () {
		// show the form
		this.formHTML.style.display = "";
	} ,

	submitComment : function () {
		this.saveValues();
		if (document.getElementById("AddCommentForm")) document.getElementById("AddCommentForm").submit();
		return false;
	} ,

	writeSmileys : function ( dId ) {
		getE(dId).innerHTML = this.smileysDiv;
	} ,
	
	writeSmiley : function ( text ) {
		this.writeSmilyToId("AddCommentComment",text)
		this.writeSmilyToId("LocalCommentComment",text)
	} ,
	
	writeSmilyToId : function ( id, text ) {
		if (getE(id)) {
			insertAtCursor(getE(id), text)
			// getE(id).value = getE(id).value + text;
		}
	}

}


//
// HTML definition of the local form.
// It should more or less correspond with the normal form HTML.
// If you change the main form, you may consider changing this code too
//

var sHTML = new Array();
sHTML[0] = ''
+ "\n" + '<!-- Add js generated comment form - start -->'
+ "\n" + '<div class="LocalCommentFormContainer"><div class="AddNewComments noprint">'
+ "\n" + '<h3>%%CommentNewComment%%</h3>'
+ "\n" + '<div class="LocalCommentCancelReply"><a href="#" onclick="return commentReply.cancelReply()" title="%%CommentCancelReplyTitle%%">%%CommentCancelReply%%<span></span></a></div>'
+ "\n" + '<form class="AddCommentForm">'
+ "\n" + '	<div>'
+ "\n" + '		<table class="StandardForm">'
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th><label for="LocalCommentName">%%FormItemName%%:</label></th>'
+ "\n" + '				<td><input type="text" value="" id="LocalCommentName" name="LocalCommentName" /></td>'
+ "\n" + '			</tr>'
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th><label for="LocalCommentEmail">%%FormItemEmail%%:</label></th>'
+ "\n" + '				<td><input type="text" value="" id="LocalCommentEmail" name="LocalCommentEmail" /></td>'
+ "\n" + '			</tr>'
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th><label for="LocalCommentWWW">%%FormItemWWW%%:</label></th>'
+ "\n" + '				<td><input type="text" value="" id="LocalCommentWWW" name="LocalCommentWWW" /></td>'
+ "\n" + '			</tr>'
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th><label for="LocalCommentTitle">%%CommentItemTitle%%:</label></th>'
+ "\n" + '				<td><input type="text" value="" id="LocalCommentTitle" name="LocalCommentTitle" /></td>'
+ "\n" + '			</tr>'
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th><label for="LocalCommentComment">%%CommentItemCommentText%%:</label></th>'
+ "\n" + '				<td>'
+ "\n" + '					<textarea id="LocalCommentComment" name="LocalCommentComment" cols="40" rows="8" ></textarea>'
+ "\n" + '					<div id="SmileysAutoAddExtra" class="SmilesAutoAdd"></div>'
+ "\n" + '				</td>'
+ "\n" + '			</tr>';
sHTML[1] = ''
+ "\n" + '			<tr class="LocalAntiSpamProtection" id="LocalAntiSpamProtection">'
+ "\n" + '				<th><label for="LocalFormVerificationAnswer">%%AntiSpamQuestion%%:</label></th>'
+ "\n" + '				<td>'
+ "\n" + '					<p><span class="AntiSpamQuestionText">%%AntiSpamQuestionText%%</span>'
+ "\n" + '					<input type="text" value="" id="LocalFormVerificationAnswer" name="LocalFormVerificationAnswer" class="AntiSpamQuestion" /></p>'
+ "\n" + '				</td>'
+ "\n" + '			</tr>';
sHTML[2] = ''
+ "\n" + '			<tr class="' + commentReply.getTRClass() + '">'
+ "\n" + '				<th>&nbsp;</th>'
+ "\n" + '				<td><input type="submit" value="%%CommentItemAddComment%%" id="LocalCommentSubmit" class="SubmitButton" onclick="return commentReply.submitComment()" /></td>'
+ "\n" + '			</tr>'
+ "\n" + '		</table>'
+ "\n" + '	</div>'
+ "\n" + '</form>'
+ "\n" + '</div></div>'
+ "\n" + '<!-- Add js generated comment form - end -->'

commentReply.loadHTML ( sHTML );
