// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//

//JR		
function UserLogin()
{
	if(validateString(document.getElementById('txtUserName'),'Please complete Username.') 
		&& validateString(document.getElementById('txtPass'),'Please complete Password.'))						 
	{		
		document.location = '?frontend_action=user_login&UserName=' + document.getElementById('txtUserName').value +'&Passw=' + document.getElementById('txtPass').value;								
	}
}

function showTaskVolunteers(dayID)
{				
		document.location.target = '_new';
		document.location.href = 'http://10.0.0.3/php/crossroad/index.php?frontend_action=show_task_volunteers&dayID=' +dayID;		
} 

function showDailyVolunteers(dayID)
{				
		document.location.target = '_new';
		document.location.href = 'http://10.0.0.3/php/crossroad/index.php?frontend_action=show_daily_volunteers&dayID=' +dayID;		
}

function onEnterLogin(event)
{      
    if(event.keyCode == 13)
    {    
        UserLogin();
    }
} 

// ***** Popup Menus **********

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}



function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}


//POPUP DIV JS FUNCTIONS
function toggle(div_id) 
{	
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) 
		el.style.display = 'block';
	else
		el.style.display = 'none';
}

function blanket_size(popUpDivVar) 
{	
	if (typeof window.innerWidth != 'undefined') 
	{	
		viewportheight = window.innerHeight;
	} 
	else 
	{		
		viewportheight = document.body.clientHeight;				
	}
	
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) 
	{				
		blanket_height = viewportheight;
	} 
	else 
	{		
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) 
		{			
			blanket_height = document.body.clientHeight;
			blanket_width = document.body.clientWidth;
		} 
		else 
		{			
			blanket_height = document.body.scrollHeight;
			blanket_width = document.body.clientWidth;			
		}
	}
	
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	blanket.style.width = blanket_width + 'px';	

	
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height= blanket_height/2-225; //150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) 
{
	if (typeof window.innerWidth != 'undefined') 
	{
		viewportwidth = window.innerHeight;
	} 
	else 
	{
		viewportwidth = document.documentElement.clientHeight;
	}
	
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) 
	{
		window_width = viewportwidth;
	} 
	else 
	{
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) 
		{
			window_width = document.body.parentNode.clientWidth;
		} 
		else 
		{
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname) 
{
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

//Info Detail Popup
var IB=new Object;
var posX=0;posY=0;
var xOffset=10;yOffset=10;

function ShowHelpbox(texte) 
{
  contenu="<TABLE border=0 cellspacing=0 cellpadding="+IB.NbPixel+"><TR bgcolor='"+IB.ColContour+"'><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD width=250px><FONT size='-1' face='arial' color='"+IB.ColTexte+"'>"+texte+"</FONT></TD></TR></TABLE></TD></TR></TABLE>&nbsp;";
	      
  var finalPosX=posX-xOffset;
  if (finalPosX<0) 
  	finalPosX=0;
  
  if (document.layers) 
  {
    document.layers["bulle"].document.write(contenu);
    document.layers["bulle"].document.close();
    document.layers["bulle"].top=posY+yOffset;
    document.layers["bulle"].left=finalPosX;
    document.layers["bulle"].visibility="show";
  }
  if (document.all) 
  {
    bulle.innerHTML=contenu;
    document.all["bulle"].style.top=posY+yOffset;
    document.all["bulle"].style.left=finalPosX;
    document.all["bulle"].style.visibility="visible";
  }
  
  else if (document.getElementById) 
  {
    document.getElementById("bulle").innerHTML=contenu;
    document.getElementById("bulle").style.top=posY+yOffset;
    document.getElementById("bulle").style.left=finalPosX;
    document.getElementById("bulle").style.visibility="visible";
  }
}

function getMousePos(e) 
{
  if (document.all) 
  {
  	posX=event.x+document.body.scrollLeft; 
  	posY=event.y+document.body.scrollTop;
  }
  else 
  {
  	posX=e.pageX; 
  	posY=e.pageY; 
  }
}

function HideInfoBox() 
{
	if (document.layers) 
	{
		document.layers["bulle"].visibility="hide";
	}
	if (document.all) 
	{
		document.all["bulle"].style.visibility="hidden";
	}
	else if (document.getElementById)
	{
		document.getElementById("bulle").style.visibility="hidden";
	}
}

function InitInfoBox(ColTexte,ColFond,ColContour,NbPixel) 
{
	IB.ColTexte=ColTexte;IB.ColFond=ColFond;IB.ColContour=ColContour;IB.NbPixel=NbPixel;
	if (document.layers) 
	{
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
		document.write("<div style=\"white-space:nowrap\"><LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER></div>");
	}
	if (document.all) 
	{
		document.write("<div style=\"white-space:nowrap\"><DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV></div>");
		document.onmousemove=getMousePos;
	}
	
	else if (document.getElementById) 
	{
		document.onmousemove=getMousePos;
	  document.write("<div style=\"white-space:nowrap\"><DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV></div>");
	}
}

