function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function dialogMask(strAction){
	
	var dialogmask;
	
	switch(strAction){
		
		case 'open':
			if(!document.getElementById('dialog-mask')){
				dialogmask = document.createElement('div');
			    dialogmask.id = 'dialog-mask';
			    document.body.appendChild(dialogmask);
			    dialogmask.style.height = content.offsetHeight + 'px';
			    }
			else{	
				dialogmask = document.getElementById('dialog-mask');
    			dialogmask.style.visibility = "visible";
    			}

			break;
			
		case 'close':
			document.getElementById('dialog-mask').style.visibility = "hidden";
	}
	
}

function closeDialog(strName){
	//alert(strName);
	//document.getElementById('dialog'+strName).innerHTML='test';
	$("#dialog"+strName).dialog( "close" );
}

function openDialog(strName,strQuery){
	
	var oDialog;
	
	if(!document.getElementById('dialog'+strName)){
		oDialog = document.createElement('div');
	    oDialog.id = 'dialog'+strName;
	    document.body.appendChild(oDialog);
	    oDialog.style.height = content.offsetHeight + 'px';
	    }
	else{	
		oDialog= document.getElementById('dialog'+strName);
		oDialog.style.visibility = "visible";
		}

	
	switch(strName){
		
		case 'AddNewFriend':
			
			dialogMask('open');
			oDialog.title = 'Add new friend?';
			ajaxDraw('dialog'+strName,'/Includes2/Dialog/index.asp?Action=AddNewFriend&'+strQuery);
			$( "#dialog"+strName ).dialog({ width: 600});
			$( "#dialog"+strName ).bind( "dialogbeforeclose", function(event, ui) {
			  dialogMask('close');
			});
			
			break;
			
		case 'FriendsInCommon':
		
			dialogMask('open');
			oDialog.title = 'Friends in common';
			ajaxDraw('dialog'+strName,'/Includes2/Dialog/index.asp?Action=FriendsInCommon&'+strQuery);
			$( "#dialog"+strName ).dialog({ width: 400});
			$( "#dialog"+strName ).bind( "dialogbeforeclose", function(event, ui) {
			  dialogMask('close');
			});
			
			break;

		default:
			dialogMask('open');
			oDialog.title = 'Message';
			ajaxDraw('dialog'+strName,'/Includes2/Dialog/index.asp?Action=Message&Type='+strName+'&'+strQuery);
			$( "#dialog"+strName ).dialog({ width: 400});
			$( "#dialog"+strName ).bind( "dialogbeforeclose", function(event, ui) {
			  dialogMask('close');
			});
			
			break;

		
	}
		
}

function setDialogTitle(strType,strMessage){
	
	$('#dialog'+strType).dialog("option","title",strMessage);
	
}

/* Dialog Speceifc functions */

function addNewFriendSendRequest(lngID,oFrm){
	
	ajaxDraw('return','/Includes2/AjaxFuncs/index.asp?AAction=AddNewFriend&ID='+lngID+'&'+getFormValues(oFrm,''));
	closeDialog('AddNewFriend');
	
}

