<!--

// Script Source for Guest Book v2.2
// ©2003 Gurgen Alaverdian www.gurgensvbstuff.com

// Translate following variables to support your Language.
// NOTE: Only public pages alert messages are translated. Admin and Control pages alerts remain in English.

// ***************** Begin Lingual Variables ****************************************

	var strMandatory = "-- Mandatory Field --";
	var strValidate1 = "    -- Your comment contains ";
	var strValidate2 = " characters. Only ";
	var strValidate3 = " allowed. Please revise!    ";
	var strValidate4 = "    -- Your comment possibly contains a harmful code. Please revise!    ";
	var strValidate5 = "    -- Name must be specified!    ";
	var strValidate6 = "    -- Email format is invalid!    ";
	var strValidate7 = "    -- Please state your comment!    ";
	var strValidate8 = "Please fix the following errors and resubmit:";
	var strValidate9 = "    -- Selected image is not attached. Click on 'monitor' icon to attach.";
	
	var strStyle1 = "select text, click ";
	var strStyle2 = " Click without selection to start range. Click again to end range.";


// ****************** End Lingual Variables ******************************************


function init() {

document.postnew.fName.value = strMandatory;
document.postnew.fComment.value = strMandatory;

}


function GetLost(oform){
	if (oform.value == strMandatory){
		oform.value = "";
	}

}

function submitform(oform)
{

	if (oform.fName.value == strMandatory){
		oform.fName.value = "";
	}
	
	if (oform.fComment.value == strMandatory){
		oform.fComment.value = "";
	}


var errorm = "";
var uname = (oform.fName.value);
var uname = uname.replace(/\s/g, "");
var email = (oform.fEmail.value);
var ePat = (/(\w+)@(\w+)\.(\w+)/);
var matchEmail=email.match(ePat);
var comment = (oform.fComment.value);
var icomment = comment.replace(/\s/g, "");
var ASPCodePat = /<%(.|\n)*%>|<script(.|\n)*script>|<style(.|\n)*style>|<meta[\s]/gi;
var testForASP = comment.match(ASPCodePat);
var cLenght = comment.length;
var maxChr = (oform.maxPost.value);
var fimg = (document.prev);


	if (cLenght > maxChr){

		var errorm = (strValidate1 + cLenght + strValidate2 + maxChr + strValidate3 + "\n");
		var trap = ("error");
		
	}

	if (testForASP !== null){
		var errorm = errorm + (strValidate4 + "\n");
		var trap = ("error");
	}


	if (uname == "") {
		var errorm = errorm + (strValidate5 + "\n");
		var trap = ("error");
	}
	if (email !== "") {
		if (matchEmail == null){
			var errorm = errorm + (strValidate6 + "\n");
			var trap = ("error");
		}	
	}
	if (icomment == "") {
		var errorm = errorm + (strValidate7 + "\n");
		var trap = ("error");
	}

	if (fimg.selpic.value !== "" && oform.tempimg.value == "") {
		var errorm = errorm + (strValidate9 + "\n");
		var trap = ("error");
	}
		

	if (trap == "error") {
		alert (strValidate8 + "\n" + "\n" + errorm);
	}
	else {
		 var longPat = /((\S){60})/g;
		 var testComment = (comment);
		 oform.fComment.value = testComment.replace(longPat, "$1" + "\n");
		 oform.submitFlag.value = "post";
		 oform.submit();
	     }
}

function popup(url,wname,params)
{
PopWin = window.open(url,wname,params);
PopWin.focus();
}

function Save_Message(action)
{

	if (action == "save"){
		var conf = window.confirm("Are you sure you want to save changes?");
		if (!conf){
		return
		}
		else
			document.postnew.action.value = "save"
			document.postnew.submit();
	}

	if (action == "clear"){
		var conf = window.confirm("This action will clear the comment in the database! Continue?");
		if (!conf){
		return
		}
		else
		document.postnew.action.value = "clear"
    		document.postnew.submit();
	}
	
}

function sm(val,isnn) {

	if (isnn == 1){
		GetLost(window.opener.document.postnew.fComment);
		var selFrom = window.opener.document.postnew.fComment;
	}else{
		var myParent = window.parent.dialogArguments["DIALOGOPENER"];
		GetLost(myParent.document.postnew.fComment);
		var selFrom = myParent.document.postnew.fComment;
	}

	if (selFrom.storedRange) {
		 selFrom.storedRange.text = val;

	}else{
    		 selFrom.value += val;
  	}
}

function checkAll(oChkBox)
{
var bStatus = oChkBox.checked;
var docFrm = document.forms["admin"];
    for (i=0; i < docFrm.elements.length; i++) {
    	if (docFrm.elements[i].type == "checkbox") {
			docFrm.elements[i].checked = bStatus;
       }
    }
}

function popup(url,wname,params)
{
PopWin = window.open(url,wname,params);
PopWin.focus();
}

function sting(cform)
{
var n = (cform.T1.value);
var p = (cform.T2.value);
var c = (cform.T3.value);
if (p !== c) {
	alert("Password does not match.");
	cform.T2.value = ("");
	cform.T3.value = ("");
	return
}
if (n == "" | p == "") {
	var conf = window.confirm("Name or Password is blank. Do you want to continue?");
	if (!conf) {
	return
	}
}
cform.submit();
}


function feedback(reportform)
{


	if (typeof(document.forms[reportform].report) == "object"){
			alert(document.forms[reportform].report.value);
		
	}

	if (typeof(document.forms[reportform].refreshBook) == "object"){
		window.location=window.location
		window.opener.location=window.opener.location
	}
}

function archive()
{

var arch = document.frmarchive.D1.options[document.frmarchive.D1.selectedIndex].value;

		if (arch == "2"){
			if (window.confirm("You are about to Archive All messages from Guest Book.")){
				frmarchive.submit();
			}
			else
				return
		}
		else
			if (window.confirm("You are about to archive messages older than " + arch + " days from Guest Book.")){
				frmarchive.submit();
			}
}

function showArchive(oform)
{

	if (oform.options.length == 0){
		alert("Archive List is Empty!");
		return
	}

var selArch = oform.options[oform.selectedIndex].value;
popup("archive.asp?arch=" + selArch + "&Page=1","archive","toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=1000,height=700");

}

function delarchive()
{

	if (document.frmarchdel.D2.options.length == 0){
		alert("Archive List is Empty!");
		return
	}
	if (window.confirm("You are about to delete selected Archive.")){
		frmarchdel.submit();
	}
}


function searchGuestBook(){
	var sTarget = document.search.D1.options[document.search.D1.selectedIndex].value;
	var sType = document.search.D2.options[document.search.D2.selectedIndex].value;
	var sDate = document.search.D3.options[document.search.D3.selectedIndex].value;
	var searchStr = document.search.T1.value;
	var matchCase = document.search.C1.checked;
	var checkStr = searchStr.replace(/\s/g, "");
	if (checkStr == "")
		return alert("Please specify a String to search.");
	if (sType !== "3"){
		var searchStr = searchStr.replace(/[^A-Za-z0-9\s_]/g, "");
		var tempSplit = searchStr.split(" ");
		var searchStr = "";
		for (var i=0; i < tempSplit.length; i++){
			if (tempSplit[i] !== ""){
				var searchStr = searchStr + "+" + tempSplit[i];
			}
		}
		searchStr = searchStr.replace(/\+/, "");
	}
	document.search.action = "search.asp?Target=" +  escape(sTarget) + "&string=" + escape(searchStr) + "&type=" + sType + "&Displ=1&Date=" + sDate + "&case=" + matchCase;
	document.search.submit();

}


function saveTheme(){

var tname = (frmColor.fTname.value);
var tname = tname.replace(/\s/g, "");
var tPatt = /[^\w-]/g;
var checkName=tname.match(tPatt);

	if (tname == "") {
		alert("    -- Please Specify a name of the Theme!");
		return;
	}

	if (checkName !== null){
		alert("    -- Only Alphanumeric values,  ‘-‘ and ‘_’ allowed as a Theme Name!");
		return;
	}

	document.frmColor.sTheme.value = "save"
	document.frmColor.submit();
}

function delTheme()
{

	if (document.frmColor.tList.options.length == 0){
		alert("Themes List is Empty");
		return
	}
	if (window.confirm("You are about to delete selected Theme.")){

		document.frmColor.ThemeConfig.value = "delete"
		document.frmColor.submit();
	}
}

function loadTheme()
{

	if (document.frmColor.tList.options.length == 0){
		alert("Themes List is Empty");
		return
	}
	if (window.confirm("You are about to load selected Theme. If you have not saved current configuration it will be overridden!")){

		document.frmColor.ThemeConfig.value = "load"
		document.frmColor.submit();
	}
}


function selectPages(perPage, pageNumber, pageName)
{

	document.cookie = "Page="+pageNumber+";path=/";
	document.cookie = "PerPage="+perPage+";path=/";
	window.location = pageName;
}

function ShowColor(colorValue)
{
	Color.style.backgroundColor = colorValue;
	var stripValue = colorValue.replace("#", "");
	frmColor.frmhex.value=stripValue;
}

function buffer(oForm) {
  	var iRange = document.selection.createRange();
  	oForm.storedRange = iRange.duplicate();
}


function postStyle(image,iLocation,iStyle) {

	GetLost(document.postnew.fComment);
	var oForm = document.postnew.fComment;

	switch(iStyle){
		case "bold":
			var sTag = "[b]";
			var eTag = "[/b]";
			var sImage = "b.jpg";
			var eImage = "b1.jpg";
			var sID = "sbold";
			var eID = "ebold";
			if (image.id=="sbold") {var iStart = true;}
			break;
		case "it":
			var sTag = "[i]";
			var eTag = "[/i]";
			var sImage = "i.jpg";
			var eImage = "i1.jpg";
			var sID = "sit";
			var eID = "eit";
			if (image.id=="sit") {var iStart = true;}
			break;
		case "us":
			var sTag = "[u]";
			var eTag = "[/u]";
			var sImage = "u.jpg";
			var eImage = "u1.jpg";
			var sID = "sus";
			var eID = "eus";
			if (image.id=="sus") {var iStart = true;}
			break;

	}

	if (iStart) {
		if (oForm.storedRange) {
			if (oForm.storedRange.text.length > 0) {
    				oForm.storedRange.text = sTag+oForm.storedRange.text+eTag;
			}else{
				oForm.storedRange.text = sTag;
				var iSwitch = true;
			}
		}else{
    			oForm.value += sTag;
			var iSwitch = true;
  		}				
		if (iSwitch) {
			image.src = iLocation+eImage;
			image.id = eID;
		}
				
	}else{
		if (oForm.storedRange) {
			if (oForm.storedRange.text.length > 0) {
    				oForm.storedRange.text += eTag;
			}else{
				oForm.storedRange.text = eTag;
			}
		}else{
    			oForm.value += eTag;
  		}				
		image.src = iLocation+sImage;
		image.id = sID;
	}

}

function cStyle(iStyle) {

	switch (iStyle) {
	
	case "bold" : document.all.help.innerHTML="<font size=1><b>Bold</b> - " + strStyle1 + "|<b>B</b>|." + strStyle2 + "</font>"; break;
	case "itl" : document.all.help.innerHTML="<font size=1><i>Italic</i> - " + strStyle1 + "|<i>I</i>|." + strStyle2 + "</font>"; break;
	case "usr" : document.all.help.innerHTML="<font size=1><u>Underscore</u> - " + strStyle1 + "|<u>U</u>|." + strStyle2 + "</font>";
	
	}
}

function animate(iButton, action){

iButton.style.border = "2px "+action;

}

function moveoffline(ID, action)
{
	
	switch (action) {
	case "offline":
		var conf = window.confirm("This action will take comment offline. Continue?"); break;
	case "online":
		var conf = window.confirm("This action will move record into online database. Continue?"); break;		
	case "delete":
		var conf = window.confirm("This action will completely remove selected comment(s) from database \nas well as delete a picture attached to this comment. Continue?"); break;
	}

	if (conf){
	popup("adminmisc.asp?ID="+ID+"&act="+action,"move","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=10,height=10")
	}

}

//-->



