/*		
 Title		: Java support script for Selex Communications Ltd website 
 Name		: marine_2009.js
 Author		: Mal Phillips 
 History	:
			: 17-Apr-2008 
 			: Added header area.  Changed all quotes (") to single apostrophes (')
			: to assist client-side distinction between Java code and .Net code
			:
			: 25-Dec-2008
			: Included code to resize menu area suitably for it's paired content iFrame
			:
			: 29-Jan-2009
			: Code to validate form completion added.
*/


var stopload=false;

function preload(doc) {
  if(stopload == true) {
    stopload=false;
    return;
    }
  if(getfile(parent.frames['main'].location.href) != doc)
    parent.frames['main'].location.href=doc;}

function checkmenu(doc, doload) {
  stopload = doload;
  if(getfile(parent.frames['menu'].location.href) != getfile(doc))
    parent.frames['menu'].location.href=doc;
  else
    stopload=false;
  }
	
function getfile(fullname) {
  var filename, i;
  for(i = fullname.length; i >= 0; i--) {
    if(fullname.charAt(i) == '/')
      break;
    }
  i++;
  filename = fullname.substring(i,fullname.length);
  return filename;
  }
	
function GoPage(selObj,restore) {
  var pagename,framename,i,optval;
	optval = selObj.options[selObj.selectedIndex].value;
	for(i = optval.length; i >= 0; i--) {
	  if(optval.charAt(i) == '@')
		  break;
	}
	stopload = false;
	if(i < 0) {
	  parent.location.href=optval;
	}
	else {
	  pagename = optval.substring(0,i);
	  framename = optval.substring(i + 1,optval.length);
		parent.frames[framename].location.href=pagename;
	}

if (restore) selObj.selectedIndex=0;

}

function GetDefStatMsg() {
 return 'Serving Mariners since 1900';
}


/*		
   The menu element will always be drawn after the main content frame.  If the menu
   is longer than the body, it will be truncated.  Make sure the menu's IFrame is
   at least long enough to show all of it's components.
*/

function resizeIframe()  {
/*		
  var height = document.body.scrollHeight;
  height -= 198;
  if(height<600) {height=600};
  document.getElementById("home_menu").style.height = height + "px";

*/
  document.getElementById("home_menu").style.height = "620px";
}

function resizeBody() {
  var height = document.getElementById("home_menu").scrollHeight;
  var menumin = document.body.scrollHeight;
  if(menumin > height) 
    {
    document.body.height = height + "px";	  
	};
}


function resizeIframeMain()  {
  var height = document.body.clientHeight;
  height = document.body.clientHeight;
  height -= 142;
  document.getElementById("home_menu").style.height = height + "px";
}


function SubMenuShow(div){

var div2 = "PSCMenu";
  if (div2 != div)
  { if(document.getElementById(div2))
    { lay2 = eval(document.getElementById(div2).style);
      if(lay2.visibility="visible")
        {lay2.visibility="hidden";lay2.display="none";}
  }}

div2="MediaCentre";
if (div2 != div) 
  { if(document.getElementById(div2))
  {
  lay2=eval(document.getElementById(div2).style);
  if(lay2.visibility="visible")
    {lay2.visibility="hidden";lay2.display="none";}
  }}

div2="SupportMenu";
if (div2 != div) {
  if(document.getElementById(div2))
  {
  lay2=eval(document.getElementById(div2).style);
  if(lay2.visibility="visible")
    {lay2.visibility="hidden";lay2.display="none";}
  }}

div2="MIDASMenu";
if (div2 != div) {
  if(document.getElementById(div2))
  {
  lay2=eval(document.getElementById(div2).style);
  if(lay2.visibility="visible")
    {lay2.visibility="hidden";lay2.display="none";}
  }}

viewable=document.getElementById(div).style.visibility;
if(viewable=="hidden"){viewable="visible"}
else if(viewable=="visible"){viewable="hidden"}
var z=(viewable=="hidden")?false:true;
var vis=(z)?"visible":"hidden";
var disp=(z)?"":"none";
lay=eval(document.getElementById(div).style);
lay.visibility=vis;
lay.display=disp;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_validateForm() 
  {
  if (document.getElementById)
    {
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) 
	{
	test=args[i+2]; 
	val=document.getElementById(args[i]);
    if (val) 
      { 
      nm=val.name; 
      if ((val=val.value)!="") 
        {
        if (test.indexOf('isEmail')!=-1) 
          {
  	      p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) 
	        errors += '- You need to supply a valid e-mail address.\n';
          } 
        else if (test!='R') 
          { 
	      num = parseFloat(val);
          if (isNaN(val)) 
	        errors += '- ' + nm + ' must contain a number.\n';
          if (test.indexOf('inRange') != -1) 
	        {
	        p=test.indexOf(':');
            min=test.substring(8,p); 
	 	    max=test.substring(p+1);
            if (num<min || max<num) 
		      errors+='- ' + nm + ' must contain a number between '+min+' and '+max+'.\n';
		    }
	      }
        }
      else if (test.charAt(0) == 'R') 
	    {
		// Expand any reserved variable names //
		if (nm=='enquirer')	 {nm='Name'};
		if (nm=='email')	 {nm='Email address'};
		if (nm=='telephone') {nm='Telephone number'};
        errors += '- ' + nm + ' must be entered.\n';
		}
      }
    }
if (errors) 
  alert('Required fields need completion:\n' + errors);
  document.MM_returnValue = (errors == '');
  }
}