var DialogOptions = 'center: yes; ' +
					'resizable: no; ' +
					'scroll: no; ' +
					'status: no; ' +
					'help: no; ' +
					'minimize: yes; '

var WindowOption = 'toolbar=no, ' +
                   'location=no, ' +
                   'directories=no, ' +
                   'status=no, ' +
                   'scrollbars=no, '

var CursorX;
var CursorY;

var bDataChanged = false;

function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) 
{
  CursorX = (window.Event) ? e.pageX : event.clientX;
  CursorY = (window.Event) ? e.pageY : event.clientY;
  //window.status=CursorX+':'+CursorY;
}
                    
function OpenDialog(URL, DialogAruments, Width, Height, Modal)
{
	var Options = DialogOptions +
					  'dialogWidth: ' + Width + 'px; ' + 
					  'dialogHeight: ' + Height + 'px;'
	if (Modal)
		return window.showModalDialog(URL, DialogAruments, Options);
	else
		return window.showModelessDialog(URL, DialogAruments, Options);
}

function OpenWindow(URL, WindowName, Width, Height, Resizable)
{
	var Left = (screen.width - Width) / 2;
	var Top = (screen.height - Height) / 2;

	var Options = WindowOption +
					  'top=' + Top + ', ' + 
					  'left=' + Left + ', ' + 
					  'width=' + Width + ', ' + 
					  'height=' + Height;
	
	if (Resizable)
		Options = Options + ', resizable=yes;'
	else	
		Options = Options + ', resizable=no;'	
				  
	return window.open(URL, WindowName, Options);
}

function TextWidth(Text,ElementClass)
{
	if (document.createElement) 
	{
		var returnedWidth = 0;
		var rulerSpan = document.createElement('span');
		rulerSpan.className = ElementClass;
		rulerSpan.setAttribute('style','visibility:hidden;');
		rulerSpan.innerHTML = Text;
		window.document.body.appendChild(rulerSpan);
		returnedWidth = rulerSpan.offsetWidth;
		window.document.body.removeChild(rulerSpan);
		rulerSpan = null;
	}
	return returnedWidth;
}

function GetFixedText(text,width,ElementClass)
{
	var txt = new String(text);
	if (TextWidth(txt,ElementClass)>width)
	{
		while (TextWidth(txt + ' ...',ElementClass) > width)
		{
			txt = txt.substr(0,txt.length-1);
		}
	txt += ' ...';
	}
	return txt;
}

function SetTitle(Category,SubCategory)
{
	window.top.document.all.PageTitle.innerHTML = Category;
	window.top.document.all.PageSubTitle.innerHTML = SubCategory;
}

function OpenLegalNotice(Path,Lang)
{
	OpenWindow(Path + 'legal_notice.aspx?lang='+Lang,'',600,500,false);
}

function OpenPrivacyPolicy(Path,Lang)
{
	OpenWindow(Path + 'privacy_policy.aspx?lang='+Lang,'',600,500,false);
}

/*function OpenMenuItem(ActionType)
{
	alert(ActionType);
	var MainForm = document.forms.main_form;
	switch (ActionType)
	{
		case ('TasksMenuItem'):
		{
			MainForm.action = 'WebForms/Tasks/TasksIndex.aspx';
			MainForm.submit();
			break;
		}
		case ('ProjectsMenuItem'):
		{
			
			MainForm.action = 'web_forms/contacts/index.aspx';
			MainForm.submit();
			break;
		}
		case ('PatientsMenuItem'):
		{
			
			MainForm.action = 'web_forms/contacts/index.aspx';
			MainForm.submit();
			break;
		}
	}
}*/

function ShowPopupWin(lsPopupBasePageUrl, lsPopupUrl,lsPopupTitle,lsPopupWidth,lsPopupHeight,lsUpdateListFunction)
{
	
	var loSendArgs = new Object();	
	
	loSendArgs.Location = lsPopupUrl;
	loSendArgs.Title = lsPopupTitle;
	
	lbRetVal = window.showModalDialog(lsPopupBasePageUrl,
		loSendArgs,'dialogWidth:' + lsPopupWidth + 'px;dialogHeight:' + lsPopupHeight + 'px;resizable:no;scroll:no;status:no;help:no;minimize:no;');
	return lbRetVal;
}

function GetXmlHttpObject()
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
} 


function CheckKeyDown()
{
    if(event.keyCode==39 || event.keyCode==37 || event.keyCode==46 ||event.keyCode==8 ||event.keyCode==9)
		return;
	if ((event.keyCode < 48 || event.keyCode > 57)&&(event.keyCode < 96 || event.keyCode > 105))
	{
		event.returnValue=false;
	}
}

function CheckLettersOnly()
{
    if ((event.keyCode >= 48 && event.keyCode <= 57)||(event.keyCode >= 96 && event.keyCode <= 105))
	{
		event.returnValue=false;
	}
	
}

function MoveToNextInput(Item, MaxLength, ItemToMove)
{
    if (Item.length == MaxLength)
        ItemToMove.focus();
}
function CheckPaste()
{
	var data = window.clipboardData.getData("Text");
	if(isNaN(data))
	{
		//alert(data);
		window.event.returnValue=false;
	}
}

function MessageBox(Type, Message, Height, RootPath)

{

            var WindowOptions = 'center: yes; resizable:no; scroll:no; status:no; help:no; '; 

            if (!RootPath) RootPath = '';

            

            var ReturnValue = window.showModalDialog(RootPath + 'includes/MsgBox/message_box.aspx?type=' + Type, Message, WindowOptions + 'dialogWidth: 350px; dialogHeight:' + Height + 'px;');

            return ReturnValue;

}

function ClickElement(element)
{  
    try
	{
	    var evt = element.ownerDocument.createEvent('MouseEvents');
	    evt.initMouseEvent('click', true, true, element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
	    element.dispatchEvent(evt)
	}
    catch(err)
    {
        element.fireEvent("onclick")
    }
}

function GetDateFormatToCompare(sDate)
{
    var sDay, sMonth, sYear;
    var sDateParts;
    sDateParts = sDate.split("/");
    sDay = sDateParts[0];
    sMonth = sDateParts[1];
    sYear = sDateParts[2];
    return sYear + sMonth + sDay;
}       

function CompareDates(sDate, sDateToCompare)
        {
            if (sDate == "" || sDateToCompare == "")
                return -2;
            if (sDate == sDateToCompare)
                return 0;                   // Dates are the same.
            else
            {
                if(sDate > sDateToCompare)
                    return 1;               // Date is latter than the compared date.
                else
                    return -1;              // Date is earlier than the compared date.
            }
        }
 
function ResizeWindowByContentX(Dialog, Move)
{
	var Difference = document.body.scrollWidth - document.body.clientWidth;
	
	if (Dialog)
	{
		window.dialogWidth = (eval(window.dialogWidth.slice(0, window.dialogWidth.length - 2)) + Difference) + 'px';
		if (Move) window.dialogLeft = (eval(window.dialogLeft.slice(0, window.dialogLeft.length - 2)) - (Difference / 2)) + 'px';
	}
	else
	{
		window.resizeBy(Difference, 0);
		if (Move) window.moveBy(-1 * (Difference / 2), 0);
	}
}

function ResizeWindowByContentY(Dialog, Move)
{
	var Difference = document.body.scrollHeight - document.body.clientHeight;
	
	if (Dialog)
	{
		window.dialogHeight = (eval(window.dialogHeight.slice(0, window.dialogHeight.length - 2)) + Difference) + 'px';
		if (Move) window.dialogTop = (eval(window.dialogTop.slice(0, window.dialogTop.length - 2)) - (Difference / 2)) + 'px';
	}
	else
	{
		window.resizeBy(0, Difference);
		if (Move) window.moveBy(0, -1 * (Difference / 2));
	}
	
	return window.dialogHeight;
}

function EmailCheck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1){ return false }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
	if (str.indexOf(at,(lat+1))!=-1){ return false }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
	if (str.indexOf(dot,(lat+2))==-1){ return false }
	if (str.indexOf(" ")!=-1){ return false }
	return true					
}