/* ============================== Brefere.com ================================ */
/* ---- start of sharing ---- */
function emailafriend() {
	location.href = 'mailto:?subject=' + escape(document.title) + '&body=%0A%0A%0A' + escape(location.href) ;
}
function writefbshare() {
	if (location.href=='http://brefere.com/') {
		document.write('<a title="Share on Facebook" name="fb_share" type="button_count" share_url="http://brefere.com/fbapps/bcom.nsf/pages/splash?opendocument&t='+ escape(document.title)+'"></a>');
	}else{
		document.write('<a title="Share on Facebook" name="fb_share" type="button_count" share_url="'+ location.href +'&t='+ escape(document.title)+'"></a>');
	}
}
/* ---- start of login ---- */
function showlogin() {
	document.getElementById("LoginSubform").style.display="";	
	checkCookie(); 
}
function hidelogin() {
	document.getElementById("LoginSubform").style.display = "none";	
}
/* ---- main navigation ---- */
/* this function is called to resolve the IE6 CSS glitch for the main navigator*/
function startList() {
	if (document.all&&document.getElementById){navRoot = document.getElementById("mainnav");
	for (i=0; i<navRoot.childNodes.length; i++){node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {node.onmouseover=function(){this.className+=" over";}
	node.onmouseout=function(){this.className=this.className.replace(" over", "");}}}}
}
function isQuantityKey(evt){
	//only allows "0123456789"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 47 && charCode < 58)
		return true;
	return false;
}
function isQuantityDecimal(evt){
	//only allows "0123456789."
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode==46 | (charCode > 47 && charCode < 58))
		return true;
	return false;
}
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 displaySceenResolution() {
	 var iw, ih; // Set inner width and height
 	if (window.innerWidth == null) {
  		iw = document.body.clientWidth;
 		 ih=document.body.clientHeight;
	 } else {
		  iw = window.innerWidth;
		  ih = window.innerHeight;
 	}
 	document.write("Your current screen resolution is "+screen.width+"x"+screen.height);
}
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 openimage(imgURL) {
	//default value is available screen dimensions can not be returned
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {w = screen.availWidth; h = screen.availHeight;}
	//set the popup windows width and height
	var popW = 640, popH = 480;
	//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(imgURL, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function isNumberKey(evt){
	//only allows "0123456789./-"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 31 || (charCode > 44 && charCode < 58))
		return true;
	return false;
}
function isAlphaKey(evt){
	//only allows "a-z and A-Z and -"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 33 || charCode==45 || ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)))
		return true;
	return false;
}
function isAlphaNumKey(evt){
	//only allows "0123456789 and a-z and A-Z and -"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 33 || charCode==45 || ((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)))
		return true;
	return false;
}
function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}
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 SEARCH  ---------------------------*/
function ExecuteSearch(defaultvalue) {
	var sfld = document.getElementById("searchfld");
	var db = window.location.pathname;
	var firstpart = db.split(".nsf");
	var dbpath = firstpart[0] + ".nsf";
	var ftq = sfld.value;
	if (ftq==defaultvalue) {return false;}
	var lftq = ftq.toLowerCase();
	window.open(dbpath +'/' + searchviewname + '?SearchView&Query='+ftq+'*&ViewRef='+searchviewname+'&SearchOrder=4&Start=1&Count=50','_top');
}
function kill_boxes() {
	for( i=0; i<document.images.length ; i++ ){
		if( document.images[i].src.indexOf('vwicnsr1.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr2.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr3.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr4.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr5.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr6.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr7.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if	
	} // end for
}
/* ---------------------- 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('BcomUsername');
	if (username!=null && username!=""){
		document._BcomLogin.username.value = username;
		document.getElementById("rememberme").checked=true;
		document._BcomLogin.password.focus();
  	}else{
  		document._BcomLogin.username.value = '';
		document.getElementById("rememberme").checked=false;
		document._BcomLogin.username.focus();
  	}
};
function unloadcheck() {
	//set cookie if checkbox has been selected and username is not blank
	username = document._BcomLogin.username.value;
	password = document._BcomLogin.password.value;
	if (username!='' && password!=''){
		if (document.getElementById("rememberme").checked==true){
			setCookie('BcomUsername',username,365)
		}else{
			setCookie('BcomUsername','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;
}
/* ------------ contact ---------- */
function emailme() {
	location.href = 'm'+'a'+'i'+'l'+'t'+'o'+':'+'f'+'r'+'a'+'n'+'k'+'@'+'b'+'r'+'e'+'f'+'e'+'r'+'e'+'.'+'c'+'o'+'m'+'?subject=Brefere.com' ;
}

