var defaultBackground = '';
var expandwidth = 0;
var expandheight = 0;
var maxheight = 0;
var maxwidth = 0;
var InnerWindow;
var iFrame;
function ItemCheck(cb,value)
{

  var checklist = document.getElementById('ctl00_ContentPlaceHolder1_FormCDA_txtCheckList');
 
  if(!cb.checked)
  {
    checklist.value = replaceCharacters(checklist.value,','+ value ,'');
  }
  else
  {
  checklist.value = replaceCharacters(checklist.value,','+ value ,'');
    if(checklist.value.length < 1)
       checklist.value = ',' + value + ',';
    else
       checklist.value =  checklist.value  + value + ',';
  }
 
}
function replaceCharacters(origString,inChars,outChars) {  
        var newString = origString.split(inChars);  
        return newString = newString.join(outChars);  
 }

function ShowImageManager(id)
{

 document.getElementById('Overlaybox').style.display = 'block';
 document.getElementById('iframeImage').src = 'ImageManager.aspx?productid=' + id;
 
}

function CloseOverlayBox()
{
document.getElementById('Overlaybox').style.display = '';
 document.getElementById('iframeImage').src = '';
}


function ShowInnerWindow(pagename,left,top,height,width,customposition)
{

 var leftpos = 0;
 var halfwidth = 0;
 if(!customposition)
 {
  halfwidth = document.body.clientWidth/2;
  leftpos = halfwidth - (width/2);
  defaultBackground = document.body.style.backgroundColor;
  document.body.style.backgroundColor ='Gray';
 }  
 else
 {
   leftpos = left;   
 }

 InnerWindow = document.getElementById('InnerWindow');
 InnerWindow.style.display = 'block';

 //set width to 0
  InnerWindow.style.width=0;
  InnerWindow.style.height = 0;
  expandwidth = 0;  
  expandheight = 0;
  InnerWindow.style.left = left;
  InnerWindow.style.top = top;
    
  iFrame = document.getElementById('iFrame');
  iFrame.src = pagename;  
}


function ExpandWidthAnimation()
 {
   expandwidth += 40;
   InnerWindow.style.width = expandwidth;
   if(expandwidth <= maxwidth)
   {
     setTimeout('ExpandWidthAnimation()',1);
   }
 }

function ExpandHeightAnimation()
 {
   expandheight += 40;
   InnerWindow.style.height = expandheight;
   if(expandheight <= maxheight)
   {
    setTimeout('ExpandHeightAnimation()',1);
   }
 }
 
function ResizeDialog(width,height,fixposition)
{

  InnerWindow.style.display = 'block';
  iFrame.width = width;
  iFrame.height = height - 20;
  
  maxwidth = width;
  maxheight = height;
  
  if(!fixposition)
  {
   var halfwidth = document.body.clientWidth/2;
   var leftpos = halfwidth - (width/2);
   InnerWindow.style.left = leftpos;
  }
  
     //Start expand animation
   ExpandWidthAnimation();
   ExpandHeightAnimation();
 
}
function CloseInnerWindow()
{
  document.getElementById('InnerWindow').style.display = 'none';
  document.getElementById('iFrame').src = '';
}

function CloseModelDialog()
{
  document.getElementById('InnerWindow').style.display = 'none';
  document.getElementById('iFrame').src = '';
  document.body.style.backgroundColor=defaultBackground;
}


function RoleSelected(cb,id)
{
 var txtRole = 'ctl00_ContentPlaceHolder1_FormView1_txtViewableBy';
 var checklist = document.getElementById(txtRole);

if(!cb.checked)
  {
    checklist.value = replaceCharacters(checklist.value,','+ id ,'');
  }
  else
  {
  checklist.value = replaceCharacters(checklist.value,','+ id ,'');
    if(checklist.value.length < 1)
       checklist.value = ',' + id + ',';
    else
       checklist.value =  checklist.value  + id + ',';
  }
}

var content = '';
var win;
function PrintCDA()
{
   content = document.getElementById('PrintCDAForm').innerHTML;
   win = window.open('CDAPrint.aspx','CDAFrom','left=20,top=20,width=1000,height=900,toolbar=0,resizable=0,directory=0,menubar=0,status=0,location=0');
   setTimeout("AssignContent()",1000);
}

function AssignContent()
{
  win.document.getElementById('CDAPrintForm').innerHTML = content;
  win.print();
  win.close(); 
}

function showcal(sFieldName,events)
{ 
var sParameters;
sParameters = "txtField=" + sFieldName;

ShowInnerWindow("/Controls/Calc.aspx?" + sParameters, events.clientX,events.clientY,180,200,true);
}

function CheckPasswordLength(sender, args)
  {   
   if(args.Value.length >= 4)
    args.IsValid = true;
   else 
   args.IsValid = false;
  }


