function OpenUrl(Url)
{
    window.open(Url);
}

function ConfirmDel()
{
    if (confirm('Confirma remoção de registo?')) 
        return true; 
    return false;
}

function readCookie(name) {
	var namearg = name + "=";
	var nlen = namearg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + nlen;
		if (document.cookie.substring(i, j) == namearg) {
			var endpos = document.cookie.indexOf (";", j);
			if (endpos == -1) endpos = document.cookie.length;
			var f = unescape(document.cookie.substring(j, endpos));
			return unescape(document.cookie.substring(j, endpos));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return 0;
}

function deleteCookie(name) {
    try{
       if (readCookie(name)) {
         document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
       }
    }
	catch(e)
	{
		
	}
}

function writeCookie(name, value, expiry) {
	//alert('name: ' + name + ' value: ' + value);
	var expdate = new Date();	
	if(expiry) { //horas
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * expiry);
		document.cookie = name + "=" + value + "; expires=" + expdate.toGMTString();
	}
	else {
		document.cookie = name + "=" + value;
	}
}

function ShowFile(ImgId, Width, Height)
{
	var w = window.open('ShowFile.aspx?ImgId=' + ImgId + '&Width=' + Width + '&Height=' + Height,'','toolbar=no,location=no,directories=no,status=no,menubar=no,width=200,height=200,resizable=no,top=100,left=100');
}

function ShowPluginsFile(Img, Width, Height)
{
	var w = window.open(Img);
}

function PrintIt(Url)
{
	var w = window.open(Url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,width=630,height=600,resizable=no,top=100,left=100,scrollbars=no');
}

function OpenLst()
{
	var w = window.open('MyHealthLst.aspx','','toolbar=no,location=no,directories=no,status=no,menubar=no,width=630,height=600,resizable=no,top=100,left=100,scrollbars=no');
}

function updateData (id, cols, current, record_id, edit, url) {
	try {
		window.location = url + record_id;

		var oTable = document.getElementById(id);
		var row = document.frm.rows.value;
		cols--;
		var index = 1;
		while (index <= row) {
			if ( index % 2 == 1) {
				for (var i = 0; i < cols; i++)
					oTable.rows[index].cells[i].style.background = "#FFFFFF";
				
				oTable.rows[index].style.background = "#FFFFFF";
			} else {
				for (var i = 0; i < cols; i++)
					oTable.rows[index].cells[i].style.background = "#EFEFEF";
				
				oTable.rows[index].style.background = "#EFEFEF";								
			}				
			index++;				
		}
			
		for (var i=0; i < cols; i++)
			oTable.rows[current + 1].cells[i].style.background = "#BDC7D3";
	}
	catch(e)
	{
		
	}
}

function initialValidation()
{
    if (typeof(Page_Validators) == "undefined") 
    {
        return true;
    }
    var i;
    for (i = 0; i < Page_Validators.length; i++) 
    {
        ValidatorValidate(Page_Validators[i], "", null);
    }
}

function clickButton(e, buttonid){ 
      var evt = e ? e : window.event;

      var bt = document.getElementById(buttonid);

      if (bt){ 

          if (evt.keyCode == 13){ 

                bt.click(); 

                return false; 

          } 

      } 

}

function doingValidateDate(val) {

	var oDate = document.all[val.controltovalidate];
	var sDate = oDate.value;
	sDate = Replace(sDate, '-', '/');
	sDate = Replace(sDate, '.', '/');
	if (sDate == '') return true;

	var iDay, iMonth, iYear;
	
	var arrValues;
						
	var today = new Date();
	
	arrValues = sDate.split('/');
	
	iDay = arrValues[0];
	
	iMonth = arrValues[1];
	
	iYear = arrValues[2];
	
	if ((iMonth == null) || (iYear == null)) return false;
	
	if ((iDay > 31) || (iMonth > 12) || (iYear < 1900 || iYear > 3100)) return false;
	
	var dummyDate = new Date(iYear, iMonth - 1, iDay);
	
	if ((dummyDate.getDate() != iDay) || (dummyDate.getMonth() != iMonth - 1) || (dummyDate.getFullYear() != iYear)) return false;
	
	return true;
}
