/*
  Copyright 2007, www.brancrew.net
  Author: Cezar Draghita: ticiisonline@yahoo.com
  Last modified: Mon, 20 Aug 2007 17:42:13 GMT
*/

/********************************************************
POP IT UP!
********************************************************/
function popup(file,width,height)
{
      var height = height;
      var width  = width;

      var left = Math.floor( (screen.width - width) / 2);
      var top  = Math.floor( (screen.height - height) / 2);
      var windowParams = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
      windowParams += ",toolbar=no,status=no,scrollbars=no,menubar=no,resizable=yes,location=no,directories=no";
      var win = window.open(file, '', windowParams);

      if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
      return win;
}
/********************************************************
FUNCTION TO VALIDATE SUBMISSION OF CONTACT FORM
********************************************************/
function checkContactForm(){
      x = document.contactForm;
      name = x.name.value;
      email = x.email.value;
      message = x.message.value;

      // Form validation:
      if(name == "" && email == "" && message == ""){
            alert("Unknown request.");
            return false;
      }
      else
      if(name == ""){
            alert("Please provide your name.");
            document.contactForm.name.focus();
            return false;
      }
      else
      if(email == ""){
            alert("Please provide your e-mail address.");
            document.contactForm.email.focus();
            return false;
      }
      else
      if(message == ""){
            alert("The message field cannot be blank.");
            document.contactForm.message.focus();
            return false;
      }

      return true;
}
/********************************************************
CONFIRM / UPDATE DATA - GIVES USER REAL TIME FEEDBACK
********************************************************/
var tipGlobalId;
function showTip(id){
      tipGlobalId = id;
      window.setTimeout("hideTip(tipGlobalId)", 3500);
      var tipPane = document.getElementById(id);
      if (tipPane){
            tipPane.className = 'tipOn';
            return false;
      }
}

function hideTip(id){
      var tipPane = document.getElementById(id);
      if (tipPane){
            tipPane.className = 'tipOff';
            return true;
      }
}
/********************************************************
CONFIRM DATA - TREE LIKE
********************************************************/
var openImg = new Image();
openImg.src = "images/collapse_on.jpg";
var closedImg = new Image();
closedImg.src = "images/collapse_off.jpg";

function swapIcon(img){
      objImg = document.getElementById(img);
      if(objImg.src.indexOf('collapse_off.jpg') >- 1)
      {
            objImg.src = openImg.src;
      }
      else
      {
            objImg.src = closedImg.src;
      }

      for(i = 1; i <= 4; i++)
      {
            if("icon"+i != objImg.id)
            {
                  document.getElementById("icon"+i).src = openImg.src;
                  //alert(objImg.id);
            }
      }
}

function showData(id){
      if (document.getElementById(id).style.display == 'none')
      {
            document.getElementById(id).style.display = '';
            // If the user changed the entries of a form,
            // switch back to that table and give real time feedback.
            document.getElementById(id+"_show_after").value = document.location.pathname+"#"+id;
      }
      else
      {
            document.getElementById(id).style.display = 'none';
      }

      for(i = 1; i <= 4; i++)
      {
            if("part_"+i != id)
            {
                  document.getElementById("part_"+i).style.display = 'none';
            }
      }
}
/********************************************************
COOKIES - create, read and erase  -> (C)Scott Andrew <-
********************************************************/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/********************************************************
DECLARATION - create dynamically content for the user
********************************************************/
function checkSize()
{
    var myWidth = 800;
	if( typeof( window.innerWidth ) == 'number' )
	{
		// Non-IE
		myWidth = window.innerWidth;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth ) )
	{
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	else if( document.body && ( document.body.clientWidth ) )
	{
		// IE 4 compatible
		myWidth = document.body.clientWidth;
	}
    return myWidth;
}
function showDeclaration(act)
{
      // Content creation
      var content = new Array();
      var index = 0;
      content[index++] = '<h1>Declaration</h1><br />I hereby certify that I have furnished all the information in good faith with the purpose of employment with your company and that all the data is true and can be proven against my original documents ( Passport, Seaman\'s book, professional certificates of discharge ), which I will produce at any time upon request by employing office, Master, Shipping Company and/or authorized authority. Should any discrepancy from all stated data arise, I will be fully responsible for the resulting consequences, including, but not limited to, full charges and costs caused by such fact to involved parties for my employment and for immediate repatriation from the ship.';
      content[index++] = '<br /><br /><br />';
      content[index++] = '<div align="center"><a href="javascript:void(\'0\');" onclick="document.Confirmation.submit();document.getElementById(\'ex_dis\').style.visibility = \'hidden\'">Continue</a>&nbsp;&nbsp;<a href="javascript:void(\'0\');" onclick="document.getElementById(\'ex_dis\').style.visibility = \'hidden\'">Decline</a></div></div>';
      document.getElementById("ex_dis").innerHTML = content.join("");
      document.getElementById("ex_dis").style.visibility = "visible";
      scrollTo(0,0);
}

/********************************************************
CHECKING IF THE GIVEN VALUE IT IS A NUMERIC ONE
********************************************************/
function isNumeric(sText, what)
{
      switch(what)
      {
            case "phone/mobile/fax":
                 var ValidChars = "0123456789.-";
                 break;
            case "date":
                 var ValidChars = "0123456789";
                 break;
            case "salary":
                 var ValidChars = "0123456789.";
                 break;
      }

      var IsNumber=true;
      var Char;


      for (i = 0; i < sText.length && IsNumber == true; i++)
      {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
            {
                  IsNumber = false;
            }
      }
      
      return IsNumber;
}

/********************************************************
SWITCH BETWEEN OBJECTS
********************************************************/
function switchObject(obj)
{
      switch(obj)
      {
            case "certified":
                 document.getElementById('certified_functions').style.display = 'inline';
                 document.getElementById('uncertified_functions').style.display = 'none';
                 break;
            case "uncertified":
                 document.getElementById('certified_functions').style.display = 'none';
                 document.getElementById('uncertified_functions').style.display = 'inline';
                 break;
      }
}

/********************************************************
APPEND SELECTED DATA VALUE TO OBJECT
********************************************************/
function fillInRank(data)
{
      rank = document.getElementById('rank');
      rank.value = '';
      
      if(data != -1)
      {
            rank.value = data;
      }
}

/********************************************************
E-MAIL ADDRESS VALIDATION
********************************************************/
function isEmail(email)
{
      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
      {
            return true;
      }
      return false;
}