// JScript File

var pageIsDirty =false;

function PageIsDirty()
{
  pageIsDirty =true  

}

function VerfifyDelete(messageText)
{
  if(confirm(messageText) == false)
  {
    window.event.returnValue=false;
  }
}

function Logout()
{
	window.top.location.href="../applications/admin/logon.aspx";
}

function SetBackgroundOnInputs()
{
  //Change to edit stylesheet
  //document.styleSheets[0].href = "/Admin/App_Themes/ReleyeAdmin/Styles/EditAdmin.css";
  
  //Set readonly = false
  var aInputs = frmMain.getElementsByTagName("Input");  
	for (i=0;i<aInputs.length;i++)
	{
		var att = aInputs[i].getAttributeNode("ReleyeControlType")
		if (att != null && att.value != "Leadtext" && aInputs[i].className == "" && aInputs[i].type.toLowerCase() == "text")
		{
			aInputs[i].className = "DateBackground";
		} 
		else if(att == null && aInputs[i].className == "" && aInputs[i].type.toLowerCase() == "text")
		{
			aInputs[i].className = "DateBackground";
		}
	}
}

function EnableAdmin(value)
{
  //disable save button
  if (frmMain.btnSave != null)
    frmMain.btnSave.enabled = false;
    

  //Change to edit stylesheet
  //document.styleSheets[0].href = "/Admin/App_Themes/ReleyeAdmin/Styles/EditAdmin.css";
  
  //Set readonly = false
  var aInputs = frmMain.getElementsByTagName("Input");
  
  for (i=0;i<aInputs.length;i++)
  {
    var att = aInputs[i].getAttributeNode("ReleyeControlType")
    if (att != null && att.value == "Leadtext")
    {
      if (value)
      {
        aInputs[i].readOnly = false;
        aInputs[i].style.backgroundColor = 'lightgrey';
      }
      else
      {
        aInputs[i].readOnly = true;
        aInputs[i].style.backgroundColor = '';
      }       
    }
  }
 }



function CheckNumeric(o)
{
  if ( window.event.keyCode > 57 || window.event.keyCode < 48 && window.event.keyCode != 45)
  {
    window.event.returnValue=false
    return;
  }
  
  if (isNaN(o.value.replace('-','')))
  {
    o.value = "";
    return;
  }
}


function CheckDecimal(o)
{
  //And does not work properly
  //Does not give a shit about cultural info
//  if ( window.event.keyCode > 57 || window.event.keyCode < 48 && window.event.keyCode != 45 && window.event.keyCode != 44)
//  {
//    window.event.returnValue=false
//    return;
//  }
//  
//  if (isNaN(o.value.replace('-','').replace(',','')))
//  {
//    o.value = "";  
//    return;  
//  }
//    
//  
//  //Prec and scale 
//  var scale = o.getAttributeNode("Scale").value 
//  var precision = o.getAttributeNode("Precision").value -1
//  var arr = o.value.split(',');

//  if (arr.length == 2)
//  {
//  
//    var value1 = arr[0].replace('-','')
//    var value2 = arr[1].replace('-','')
//    //check scale
//    if (value1.length > scale && window.event.keyCode == 0)
//    {
//      o.value = "";  
//      return;  
//    }
//    else if (value1.length > scale)
//    {
//      window.event.returnValue=false
//      return;
//    } 

//    //check precision
//    if (value2.length > precision && window.event.keyCode == 0)
//    {
//      o.value = "";  
//      return;  
//    }
//    else if (value2.length > precision)
//    {
//      window.event.returnValue=false
//      return;
//    }     
//  } 
//  else
//  {
//    //add comma when added numbers are the same as scale
//    if (o.value.length == scale && window.event.keyCode != 44)
//      o.value += ',';
//    
//  }
    
  
}

/*Movable div*/
var dragapproved=false
var z,x,y,wxoffs,wyoffs,ofrm

function ShowInfoBox(div)
{
	div.style.visibility = '';
	div.style.top = event.y + 10;
	div.style.left = -120;
}

function moveobject()
{
	if (event.button==1 && dragapproved)
	{
		ofrm.style.pixelLeft=wxoffs+event.clientX
		ofrm.style.pixelTop=wyoffs+event.clientY
		if (ofrm.style.pixelLeft < 0)
		{
		  ofrm.style.pixelLeft = 0;
		}
		if (ofrm.style.pixelTop < 0)
		{
		  ofrm.style.pixelTop = 0;
		}
		return false
	}
}

function dragobject(divID,headerID)
{
	var elementid=event.srcElement.id;
	var pos=elementid.indexOf(headerID);
	if (pos>=0)
	{	
		dragapproved=true;
		ofrm=document.getElementById(divID);
		wxoffs=ofrm.style.pixelLeft-event.clientX;
		wyoffs=ofrm.style.pixelTop-event.clientY;
		document.onmousemove=moveobject;
	}
	if (!document.all)
		return;
}

function doSort(column, grid)
{
	var s = document.getElementById('SortColumn');
	if(s!=null)
	{
		s.value = column;
		if(grid != null)
		{
			var g = document.getElementById('SortGrid');
			if(g!=null)
			{
				g.value = grid;		
			}
		}
		frmMain.submit();
	}
}

function ltrim(argvalue) 
{
  while (1) 
  {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }
  return argvalue;
}

