// This begins the common functions used for the editor for the admin pages and the comment entry pages

<!--
// Opener used throughout the entire blog
function wOpen(url, w, h)
{
    // Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
        w += 32;
        h += 96;
	var win = window.open(url,
		'popup', 
		'width=' + w + ', height=' + h + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=yes, resizable=no');
	win.resizeTo(w, h);
	win.focus();
}

function confirmSubmit()
{
 var agree=confirm("Are you sure you want to delete this record?");
 if (agree)
	return true ;
 else
	return false ;
}

//Text Area Counter
function textCounter(field, countfield, maxlimit) 
{
 if (field.value.length > maxlimit) // if too long...trim it!
 field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
 else 
 countfield.value = maxlimit - field.value.length;
}

//thanks www.alexking.org
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;
  }

 }

//end www.alexking.org

//based on InsertAtCursor by alexking.org
//modified by Dave Sabol - desabol@gmail.com
//www.davesabol.com

function openerInsertAtCursor(myField, myValue) {
  //IE support
  if (opener.document.selection) {
    myField.focus();
    sel = opener.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;
  }
}


//end www.davesabol.com

function hrule(hr)
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, "[hr]");
	//{BlogForm.HtmlTextArea.value= BlogForm.HtmlTextArea.value+"<hr size=\"1\" \/>";
	}

// Begin Safari Specific Scripting
// This code was made necessary because Safari does not support InsertatCursor
// It will be removed when Apple decides to include support for this functionality

function underlineText(ul)
{
 var ulText=prompt("enter text to underline", "");
	if (ulText !=null && ulText !="" && ulText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[u]'+ulText+'[/u]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [u]"+ulText+"[/u]"; }
}

function boldText(bt)
{
 var boldText=prompt("enter text to bold", "");
	if (boldText !=null && boldText !="" && boldText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[b]'+boldText+'[/b]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [b]"+boldText+"[/b]"; }
}

function italicText(em)
{
 var italText=prompt("enter text to italicize", "");
	if (italText !=null && italText !="" && italText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[i]'+italText+'[/i]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [i]"+italText+"[/i]"; }
}

function alignLeft(al)
{
 var leftText=prompt("enter text to left align", "");
	if (leftText !=null && leftText !="" && leftText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[l]'+leftText+'[/l]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [l]"+leftText+"[/l]"; }
}

function alignCenter(ac)
{
 var centerText=prompt("enter text to center", "");
	if (centerText !=null && centerText !="" && centerText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[c]'+centerText+'[/c]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [c]"+centerText+"[/c]"; }
}

function alignRight(ar)
{
 var rightText=prompt("enter text to right align", "");
	if (rightText !=null && rightText !="" && rightText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[r]'+rightText+'[/r]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [r]"+rightText+"[/r]"; }
}

function addLink(lt)
{
var urllink = prompt("Url for the link:", "http://");
var linktext = prompt("Text for the link:", "");
	if (linktext !=null && linktext !="" && linktext !=" " && urllink !=null && urllink !="" && urllink !="http://")
	{insertAtCursor(document.BlogForm.HtmlTextArea, '[link='+urllink+']'+linktext+'[/link]');}
	//{ document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" <a href=\""+urllink+"\">"+linktext+"</a>";}
}

function addEmail(eml)
{
var mllink = prompt("Enter Email Address:", "");
var linktext = prompt("Text for the link:", "");
	if (linktext !=null && linktext !="" && linktext !=" " && mllink !=null && mllink !="" && mllink !=" ")
	{insertAtCursor(document.BlogForm.HtmlTextArea, '[mail='+mllink+']'+linktext+'[/mail]');}
	//{ document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" <a href=\"mailto:"+mllink+"\">"+linktext+"</a>";}
}

function addImage(a2)
{
 var addImg=prompt("Enter image url", "");
	if (addImg !=null && addImg !="" && addImg !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[img]'+addImg+'[/img]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [img]"+addImg+"[/img]"; }
}

function quoteText(qt)
{
 var quotText=prompt("enter quote text", "");
	if (quotText !=null && quotText !="" && quotText !=" ")
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '[quote]'+quotText+'[/quote]');}
	//document.BlogForm.HtmlTextArea.value=document.BlogForm.HtmlTextArea.value+" [quote]"+quotText+"[/quot]"; }
}

function fmtText(fmt)
	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '['+document.BlogForm.fmt_txt.options[document.BlogForm.fmt_txt.selectedIndex].value+'][/'+document.BlogForm.fmt_txt.options[document.BlogForm.fmt_txt.selectedIndex].value+']');
	//{NewEntryForm.HtmlTextArea.value= BlogForm.HtmlTextArea.fmt_txt.options[document.BlogForm.fmt_txt.selectedIndex].value);
}

function fntColor(fnt)

	{
	insertAtCursor(document.BlogForm.HtmlTextArea, '['+document.BlogForm.fnt_clr.options[document.BlogForm.fnt_clr.selectedIndex].value+'][/'+document.BlogForm.fnt_clr.options[document.BlogForm.fnt_clr.selectedIndex].value+']');
	//{NewEntryForm.HtmlTextArea.value= BlogForm.HtmlTextArea.fnt_clr.options[document.BlogForm.fnt_clr.selectedIndex].value);
	}


// End Safari Specific Scripting

function spcText(text)

	{insertAtCursor(document.BlogForm.HtmlTextArea, document.BlogForm.spc_txt.options[document.BlogForm.spc_txt.selectedIndex].value);}
	//{NewEntryForm.HtmlTextArea.value= BlogForm.HtmlTextArea.spc_txt.options[document.BlogForm.spc_txt.selectedIndex].value);

function formatText(el,tag) {
   // IE FORMAT TAG FUNCTION
   if (document.selection) {
        var selectedText = document.selection.createRange().text; 

        if (selectedText === "") { 
            var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]"; 
            insertAtCursor(document.BlogForm.HtmlTextArea, newText); 
      }
         
        if (selectedText !== "") { 
            var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]"; 

            document.selection.createRange().text = newText; 
      }
   }

   // MOZILLA/NETSCAPE FORMAT TAG FUNCTION
   if (el.setSelectionRange) {
 	el.value = el.value.substring(0,el.selectionStart) + "[" + tag +  "]" + el.value.substring(el.selectionStart,el.selectionEnd) + "[/" + tag + "]" +el.value.substring(el.selectionEnd,el.value.length)
  	}

    } 

// Allow multiple form actions and pop ups
// on one form by davesabol.com

function submitComment(form)
{
 form.target="_parent";
 form.action="blog_files/add_comment.asp";
 form.Submit.disabled=true;
 form.submit();
 return true;
}


function previewEntry(form)
{
 win=window.open('','myWin','width=500, height=400, toolbars=0'); 
 form.target='myWin';
 form.action='blog_files/popup_preview.asp';
 return true;
}


function submitEntry(form)
{
 var faction=document.BlogForm.faction.value 
 form.target='_parent';
 form.action=(faction);
 form.Submit.disabled=true;
 form.submit()
 return true;
}

// This ends the common functions used for the editor for the admin pages and the comment entry pages


// This begins the form validation functions used for the comment entry pages

function stopRKey(evt) {
	// http://www.mediacollege.com
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
document.onkeypress = stopRKey;

function checkName() 
// developed by Dave Sabol - desabol@gmail.com - Copyright 2005
{
	 // Name is a required field
	 if (document.BlogForm.COMMENT_NAME.value == "") // Check for null value
	 {
	 document.getElementById('NameError').innerHTML = ' <font style="color:red;">Required!</font>';
	 return (false);
	 }
	 document.getElementById('NameError').innerHTML = '';
	 return (true);
}

function checkEmail()
// developed by asppress.com - Copyright 2005
{
var tlds = ".ac .ad .ae .af .ag .ai .al .am .an .ao .aq .ar .as .at .au .aw .ax .az .ba .bb .bd .be .bf .bg .bh .bi .bj .bm .bn .bo .br .bs .bt .bu .bv .bw .by .bz .ca .cc .cd .cf .cg .ch .ci .ck .cl .cm .cn .co .cr .cs .cu .cv .cx .cy .cz .dd .de .dj .dk .dm .do .dz .ec .ee .eg .eh .er .es .et .eu .fi .fj .fk .fm .fo .fr .ga .gb .gd .ge .gf .gg .gh .gi .gl .gm .gn .gp .gq .gr .gs .gt .gu .gw .gy .hk .hm .hn .hr .ht .hu .id .ie .il .im .in .io .iq .ir .is .it .je .jm .jo .jp .ke .kg .kh .ki .km .kn .kp .kr .kw .ky .kz .la .lb .lc .li .lk .lr .ls .lt .lu .lv .ly .ma .mc .md .mg .mh .mk .ml .mm .mn .mo .mp .mq .mr .ms .mt .mu .mv .mw .mx .my .mz .na .nc .ne .nf .ng .ni .nl .no .np .nr .nu .nz .om .pa .pe .pf .pg .ph .pk .pl .pm .pn .pr .ps .pt .pw .py .qa .re .ro .ru .rw .sa .sb .sc .sd .se .sg .sh .si .sj .sk .sl .sm .sn .so .sr .st .su .sv .sy .sz .tc .td .tf .tg .th .tj .tk .tl .tm .tn .to .tp .tr .tt .tv .tw .tz .ua .ug .uk .um .us .uy .uz .va .vc .ve .vg .vi .vn .vu .wf .ws .ye .yt .yu .za .zm .zr .zw .com .net .org .mil .gov .edu .nato .info .int .name .biz .museum .pro .aero";
var myRegex = new RegExp("^[A-Za-z0-9\.\-_]+@[A-Za-z0-9\.\-_]+\.[A-Za-z]+[A-Za-z]+$")
var endofString = document.BlogForm.COMMENT_EMAIL.value.split('.');
var ending = endofString.length - 1;
var tld = endofString[ending];
var required = false;

	if (! document.BlogForm.COMMENT_EMAIL.value == "")
	{
		if (! document.BlogForm.COMMENT_EMAIL.value.match(myRegex)) // Check url syntax
		{
		 document.getElementById('EmailError').innerHTML = ' <font style="color:red;">Invalid email.</font>';
		 return false;
		}
		else if (tlds.search(tld) < 0) // Check for valid top-level domain
		{
		 document.getElementById('EmailError').innerHTML = ' <font style="color:red;">Check domain (.com, .net, .org, etc.).</font>';
		 return false;
		}
		else
		{
		 document.getElementById('EmailError').innerHTML = '';
		 return true;
		}
	}
	
	if (required && document.BlogForm.COMMENT_EMAIL.value == "") // Check for null value
	{
	 document.getElementById('EmailError').innerHTML = ' <font style="color:red;">Required!</font>';
	 return false;
	}
	
	if (! required && document.BlogForm.COMMENT_EMAIL.value == "") // Clear alert for blank field if not required
	{	
	 document.getElementById('EmailError').innerHTML = '';
	 return true;
	}
}


function checkUrl()
// developed by asppress.com - Copyright 2005
{
var tlds = ".ac .ad .ae .af .ag .ai .al .am .an .ao .aq .ar .as .at .au .aw .ax .az .ba .bb .bd .be .bf .bg .bh .bi .bj .bm .bn .bo .br .bs .bt .bu .bv .bw .by .bz .ca .cc .cd .cf .cg .ch .ci .ck .cl .cm .cn .co .cr .cs .cu .cv .cx .cy .cz .dd .de .dj .dk .dm .do .dz .ec .ee .eg .eh .er .es .et .eu .fi .fj .fk .fm .fo .fr .ga .gb .gd .ge .gf .gg .gh .gi .gl .gm .gn .gp .gq .gr .gs .gt .gu .gw .gy .hk .hm .hn .hr .ht .hu .id .ie .il .im .in .io .iq .ir .is .it .je .jm .jo .jp .ke .kg .kh .ki .km .kn .kp .kr .kw .ky .kz .la .lb .lc .li .lk .lr .ls .lt .lu .lv .ly .ma .mc .md .mg .mh .mk .ml .mm .mn .mo .mp .mq .mr .ms .mt .mu .mv .mw .mx .my .mz .na .nc .ne .nf .ng .ni .nl .no .np .nr .nu .nz .om .pa .pe .pf .pg .ph .pk .pl .pm .pn .pr .ps .pt .pw .py .qa .re .ro .ru .rw .sa .sb .sc .sd .se .sg .sh .si .sj .sk .sl .sm .sn .so .sr .st .su .sv .sy .sz .tc .td .tf .tg .th .tj .tk .tl .tm .tn .to .tp .tr .tt .tv .tw .tz .ua .ug .uk .um .us .uy .uz .va .vc .ve .vg .vi .vn .vu .wf .ws .ye .yt .yu .za .zm .zr .zw .com .net .org .mil .gov .edu .nato .info .int .name .biz .museum .pro .aero";
var myRegex = new RegExp("^(http|https)\://([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$")
var endofString = document.BlogForm.COMMENT_URL.value.split('.');
var ending = endofString.length - 1;
var tld = endofString[ending];
var required = false;

	if (! document.BlogForm.COMMENT_URL.value == "")
	{
		if (! document.BlogForm.COMMENT_URL.value.match(myRegex)) // Check url syntax
		{
		 document.getElementById('UrlError').innerHTML = ' <font style="color:red;">Invalid URL.</font>';
		 return false;
		}
		else if (tlds.search(tld) < 0) // Check for valid top-level domain
		{
		 document.getElementById('UrlError').innerHTML = ' <font style="color:red;">Check domain (.com, .net, .org, etc.).</font>';
		 return false;
		}
		else
		{
		 document.getElementById('UrlError').innerHTML = '';
		 return true;
		}
	}
	
	if (required && document.BlogForm.COMMENT_URL.value == "") // Check for null value
	{
	 document.getElementById('UrlError').innerHTML = ' <font style="color:red;">Required!</font>';
	 return false;
	}
	
	if (! required && document.BlogForm.COMMENT_URL.value == "") // Clear alert for blank field if not required
	{	
	 document.getElementById('UrlError').innerHTML = '';
	 return true;
	}
}


function checkComment() 
// developed by Dave Sabol - desabol@gmail.com - Copyright 2005
{
	 // Comments are a required.
	 if (document.BlogForm.COMMENT_TEXT.value == "") // Check for null value
	 {
	 document.getElementById('CommentError').innerHTML = ' <font style="color:red;">Your Comment is Required.</font>';
	 return (false);
}
 	document.getElementById('CommentError').innerHTML = 'Your Comment:';
 	return (true);
}

// End Validation Scripts

//-->