/* ============================== AngeloSosa.com ================================ */
function openwindow(URL, popW, popH) {
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {w = screen.availWidth; h = screen.availHeight;}
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//open the popup window
	window.open(URL, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function preventsubmitonenter(){
	//only allow Enter key for TextArea fields
	if (typeof window.event != 'undefined') {
	        	document.onkeydown = function() {
               	 		if (event.srcElement.tagName.toUpperCase() == 'TEXTAREA'){
				/*allow*/
			}else {
               	         			return (event.keyCode != 13);
               			}
        		}
	} else {
        		document.onkeypress = function(e) {
                		if (e.target.nodeName.toUpperCase() == 'TEXTAREA') {
				/*allow*/
			}else{
                        			return (e.keyCode != 13);
     			}
		}
	}
}
function deletedoc(doctitle, returnpath){
	result=window.confirm('Do you really want to delete this entry' + doctitle + '?');
	if (result==true){
		location.href=returnpath
	} 
}
function checkAll(field){
	for (i = 0; i < field.length; i++){field[i].checked = true;}
}
function uncheckAll(field){
	for (i = 0; i < field.length; i++){field[i].checked = false ;}
}
/* ---------------------- Start of Remember Me Cookie  ---------------------------*/
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 setCookie(c_name,value,expiredays){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) + ";path=/"
};
function checkCookie() {
	username=getCookie('ASosaUsername');
	if (username!=null && username!=""){
		document._HiveLogin.username.value = username;
		document.getElementById("rememberme").checked=true;
		document._HiveLogin.password.focus();
  	}else{
  		document._HiveLogin.username.value = '';
		document.getElementById("rememberme").checked=false;
		document._HiveLogin.username.focus();
  	}
};
function unloadcheck() {
	//set cookie if checkbox has been selected and username is not blank
	username = document._HiveLogin.username.value;
	password = document._HiveLogin.password.value;
	if (username!='' && password!=''){
		if (document.getElementById("rememberme").checked==true){
			setCookie('ASosaUsername',username,365)
		}else{
			setCookie('AsosaUsername','deletecookie',-365)
		}
	}
}
/* ---------------------- End of Remember Me Cookie  ---------------------------*/
/* ---------------------- Helper Buttons in BlogBody forms  ---------------------------*/
function insertBoldTags(myField){
	findPositions(myField);
	var text = myField.value;
	if (startPosition!=endPosition) {
		var sbStr = text.substring(startPosition,endPosition);
		sbStr = '<b>'+ sbStr + '</b>';
		fillsFormattedString(text,sbStr,myField);
	}
}
function insertItalicTags(myField){
	findPositions(myField);
	var text = myField.value;
	if (startPosition!=endPosition) {
		var sbStr = text.substring(startPosition,endPosition);
		sbStr = '<i>'+ sbStr + '</i>';
		fillsFormattedString(text,sbStr,myField);
	}
}
function insertLinkTags(myField){
	findPositions(myField);
	var text = myField.value;
	if (startPosition!=endPosition) {
		var sbStr = text.substring(startPosition,endPosition);
		sbStr = '<a target="_blank" href="http://INSERTURLHERE">'+ sbStr + '</a>';
		fillsFormattedString(text,sbStr,myField);
	}
}
function findPositions(myField){
	var text = myField.value;
	if (document.selection) {
		// Internet Explorer
		var range = document.selection.createRange();
		var dpl = range.duplicate();
		if (range.text.length > 0) {
			dpl.moveToElementText(myField);
			dpl.setEndPoint("EndToEnd", range);
			startPosition = dpl.text.length-range.text.length;
			endPosition = startPosition + range.text.length;
		}
	}
	else {
		// Mozilla Firefox
		startPosition = myField.selectionStart;
		endPosition = myField.selectionEnd;
	}
}
function fillsFormattedString(text, selectedText, myField){
	// split textarea value into three pieces: before startPosition,
      	 // startPosition until endPosition, and after endPosition
	var str1 = text.substring(0,startPosition);
	var str2 = text.substring(startPosition,endPosition);
	var str3 = text.substring(endPosition,text.length);
	// replace str2 with formatted substring (selectedText)
	str2 = selectedText;
	// form the new string
	//formattedStr = str1 + '[' + str2 + ']' + str3;
	formattedStr = str1 + '' + str2 + '' + str3;
	myField.value = formattedStr;
}

