//verify existing cookies
function get_cookie(Name)
{
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0)
    {
      offset = document.cookie.indexOf(search)
      // if cookie exists
      if (offset != -1)
      {
        offset += search.length;
        // set index of beginning of value
        end = document.cookie.indexOf(";", offset);
        // set index of end of cookie value
        if (end == -1) end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
      }
     }
    return returnvalue;
}

function get_used_language()
{
  if (document.location.href.indexOf("/fr") != -1) return "fr";
  if (document.location.href.indexOf("/en") != -1) return "en";
  if (document.location.href.indexOf("/ro") != -1) return "ro";
}

//functions for canceling some events 
function CancelEvent()
{
   var isNS4 = (navigator.appName=="Netscape")?1:0;

   if(!isNS4)
      event.returnValue = false;
   else
      return false;
}

function CancelF5()
{
    var isNS4 = (navigator.appName=="Netscape")?1:0;

    if(!isNS4)
    {
       if(event.keyCode == 116)
       {
          window.event.keyCode = 0;
          event.returnValue = false;
       }
   }
   else
   {
      if (event.which == 116)
      {
        return false;
      }
   }
}

function unsetButtons()
{
   document.getElementById("MenuCat1").className="MenuOut";
   document.getElementById("MenuCat2").className="MenuOut";
   document.getElementById("MenuCat3").className="MenuOut";
   document.getElementById("MenuCat4").className="MenuOut";
   document.getElementById("MenuCat5").className="MenuOut";
   document.getElementById("MenuCat6").className="MenuOut";
}

// functions for Menu Behaviour
function setButton(obj)
{
    unsetButtons();
    obj.className="MenuSelected";
}

function ChangeSubmenu(page)
{
    var FrameHeight = 0;
    var lang = get_used_language();
  	
    tmplpath = "tmpl/";
    news_root_path = "../news/";

    //Load the default page into frame
    switch(page)
    {
	case 0: break;

	case 1: FrameHeight = 203;
	        frames.MainFrame.document.location.href = tmplpath + "vocation.html";
		 break;

	case 2: FrameHeight = 203;
		 frames.MainFrame.document.location.href = tmplpath + "competences.html";
		 break;

	case 3: FrameHeight = 176;
	        frames.MainFrame.document.location.href = tmplpath + "externalisation.html";
		 break;

	case 4: FrameHeight = 176;
	   	 frames.MainFrame.document.location.href = tmplpath + "aviation.html";
		 break;

	case 5: FrameHeight = 72;
	        frames.MainFrame.document.location.href = tmplpath + "jobs.html";
		 break;

	case 6: FrameHeight = 72;
	        frames.MainFrame.document.location.href = news_root_path + "communiques.php";
		 break;
    }

   //Load Submenu
    document.getElementById("SubCatFrame").height = FrameHeight;
    document.getElementById("SubCatRow").height = FrameHeight;
    frames["SubCatFrame"].document.location.href="menu/menu" + page + ".html";
}

//functions for submenu behaviour
function LoadFrame(page){

    var lang = get_used_language();
	
    var tmplpath="tmpl/";

    //first, change all menu classes
    unsetButtons();

    //load news page
    document.getElementById('SubCatRow').height = 220;
    document.getElementById('SubCatFrame').height = 240;
    frames['SubCatFrame'].document.location.href =  "menu/news.html";
    frames['MainFrame'].document.location.href = tmplpath + page;

    //daca nu reincarcam imaginea, se opreste animatia... la linkurile din footer...
    document.getElementById('sag01').src = '../img/sag01.gif';
/*
    if (lang == "en")
	document.getElementById('flag_img').src='../img/flag-fr.gif';

    if (lang == "fr")
      document.getElementById('flag_img').src='../img/flag-uk.gif';
	if (lang == "ro")
      document.getElementById('flag_img').src='../img/flag-ro.gif';
	  */
}

//----------------------------------------------
function LoadStartPages()
{
  if(self.screen)
  {
    if(screen.height>800)
    {
       document.getElementById("CutPage").topmargin = 100;
    }
  }

  LoadFrame('accueil.html');

//    document.onkeypress = CancelF5;
    document.oncontextmenu = CancelEvent;
}

//functions for  Search button behaviour
function SearchPages(aString)
{
    var lang = get_used_language();

    parent.document.getElementById("MainFrame").src = "../news/search.php?text=" + escape(aString) + "&lang=" + lang;
}

function EnterOnSearch(aString, event)
{
    var isNS4 = (navigator.appName=="Netscape")?1:0;

    if(!isNS4)
    {
      if(event.keyCode == 13)
      {
         window.event.keyCode = 0;
         event.returnValue = false;
         SearchPages(aString);
      }
   }
   else
   {
      if (event.which == 13)
      {
	 SearchPages(aString);
        return false;
      }
   }
}

// display a new window with the myimage

function display(myimage) 
{
   html = "<HTML><HEAD><TITLE>Photo</TITLE>" +
	"</HEAD><BODY LEFTMARGIN=0 " +
	"MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>" +
	"<IMG SRC='" + myimage + "' BORDER=0 NAME=image " +
	"onload='window.resizeTo(document.image.width,document.image.height)'></CENTER>" +
	"</BODY></html>";

   popup=window.open('','image','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
   popup.document.open();
   popup.document.write(html);
   popup.document.focus();
   popup.document.close()
}

// display a new window with the aLink
function openLink(aLink) 
{
   popup=window.open(aLink,'','toolbar=1,location=0,directories=0,menuBar=1,scrollbars=1,resizable=1');
}

function MailThis(subject)
{
   alert(subject);
   window.location='mailto:jobs@kepler-rominfo.com?subject='+subject;
}



