/*------------------------------------------------------*/
/*                 General functions				    */
/*------------------------------------------------------*/

function general_AddEvent(object, eventName, fn) {
	if (document.addEventListener) object.addEventListener(eventName, fn, false);
	else object.attachEvent('on' + eventName, fn); 
}

function general_GetWindowHeight() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetHeight;
	} else {
		return window.innerHeight;
	}
}

function general_GetWindowWidth() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetWidth;
	} else {
		return window.innerWidth;
	}
}

var datCDate = new Date();
datCDate.setMonth(datCDate.getMonth()+2);

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function mdlNewLink(intPageID)
		{
			var rng = document.selection.createRange();
			if (rng!=null) {
				if (rng.htmlText != '')	{	
				
					booOK = window.showModalDialog(mybase + "PageModalDialogs/mdlNewLink.aspx?p=" + intPageID,window,"dialogWidth:590px; dialogHeight:250px; center:yes; edge:sunken; help:yes; status:yes; resizable:no;"); //310
				
					if (booOK != null){
					//document.Form1.Command.value = "NewLink";
					if(booOK.indexOf('.pdf') != -1){ //Makes PDF links open in a new window
						
						tt  =   document.selection.createRange().text ;      
						str =  "<a href=\" " + booOK + "\" target=\"_blank\">" +   tt + "</a>";
						rng.pasteHTML(str);

					}else{	
						document.execCommand("CreateLink", false, booOK);
					}
						
					}
				}
			}
		}
		
function mdlRenamePage(intPageID, intParentID){

			var retVal = window.showModalDialog(mybase + "PageModalDialogs/mdlRenamePage.aspx?p=" + intPageID,window,"dialogWidth:370px; dialogHeight:340px; center:yes; edge:sunken; help:yes; status:yes; resizable:no;"); //310
			switch (retVal)
			{
				case "delete" :
					window.location = mybase + "index.aspx?p=" + intParentID;
					break;
				case "refreshDoc" :
					window.location = mybase + "index.aspx?p=" + intPageID;
					break;
				default :
					break;
			}
		}
		
		function UploadImage(){
			strResultValue = window.showModalDialog(mybase + 'PageModalDialogs/mdlImageUpload.aspx','','dialogWidth: 730px; dialogHeight:650px; center: yes; help: no; resizable: yes;');
		}
		
		function mdlAddPage(){
			NewPageID = window.showModalDialog(mybase + "PageModalDialogs/mdlNewPage.aspx","","dialogWidth:325px; dialogHeight:325px; center: yes; help:yes; status:no; resizable:no;"); //'110
			if (NewPageID != "" && typeof(NewPageID)!="undefined"){
				window.parent.location = mybase + "index.aspx?p=" + NewPageID
			}
		}	
		
		function fnOpenWindow(url, windowName, w, h)
		{
			var x;
			var y;
			x=(screen.width/2-(w/2));
			y=(screen.height/2-(h/2));
			var oWin = window.open(url, windowName, 'scrollbars=yes, resizable=yes, toolbar=no, menubar=no, location=no, height=' + h + ', width=' + w + ', left=' + x + ', top=' + y)
			// Focus this window if one is already open in the background
			oWin.focus();
		}
		
		function fnOpenWindowModal(url, brefresh, w, h)
		{			
			var retValue = window.showModalDialog(url,"","dialogWidth:" + w + "px; dialogHeight:" + h + "px; center:yes; edge:sunken; help:yes; status:yes; resizable:yes;");
			if (brefresh == true)
			{
				location.reload(true);
			}
			else
			{
				return retValue;
			}
		}
		
		function index(intHomePage)
		{
			window.location= mybase + "index.aspx?p=" + intHomePage;
		}		
		
		

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };









