
if(navigator.userAgent.indexOf("Mac") !=-1){ var is_mac=true;}
if(navigator.userAgent.indexOf("MSIE") !=-1){ var is_ie=true;}
if(navigator.userAgent.indexOf("Gecko") !=-1){ var is_gecko=true;}
if(is_mac && is_ie){ document.write("<link rel='stylesheet' type='text/css' media='all' href='css/mac_ie.css' />"); }

/*document.onkeydown =
    function (evt) { 
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER
      {
		document.getElementById('btnSearch').click;
      //var searchTerm = 'search-results.aspx?page=1&query='+ document.forms['kwSearch'].elements.searchI.value;
      //   document.location=searchTerm;
         return false;

      }
    }
  */
function submitSearch(){
	document.forms['kwSearch'].action ='search-results.aspx?page=1&query='+document.forms['kwSearch'].elements.searchI.value;
	document.forms['kwSearch'].submit();
}  
    

  
function newWin(URL){
  aWindow=window.open(URL,"newWindow");
  if (!aWindow.opener) aWindow.opener=self;  
}

function newWinPopup(URL, nm, w, h, gw, gh)
{
  if(is_gecko){ w = gw; h = gh; }
  aWindow=window.open(URL, nm, "toolbar=no,width="+w+",height="+h+",status=yes,scrollbars=yes,resize=no,menubar=no");
  if (!aWindow.opener){ aWindow.opener=self; } 
}

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}




/* on dropdown select go to appropriate internal link */
function findLink(strValue) 
{
document.location=strValue;
}

/* colors tables in a striped fashion */
function stripe() {
	var even = false;

	var evenColor = arguments[1] ? arguments[1] : "#FFFFFF";
	var oddColor = arguments[2] ? arguments[2] : "#ECF1F5";

	var table = document.getElementsByTagName("table");
	if (! table) { return; }

	for(var g=0; g<table.length; g++){  //for all tables
   		var tbodies = table[g].getElementsByTagName("tbody"); //get child tags
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");
			for (var i = 0; i < trs.length; i++) {
        		// avoid rows that have a class attribute
        		// or backgroundColor style
        		if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {  // get all the cells in this row...
      	    		var tds = trs[i].getElementsByTagName("td");
        	  		for (var j = 0; j < tds.length; j++) {         // and iterate through them...
            			var mytd = tds[j];
            			// avoid cells that have a class attribute
           		 		// or backgroundColor style
            			if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
              				mytd.style.backgroundColor =
                			even ? evenColor : oddColor;
            			}
          			}
        		}
        		// flip from odd to even, or vice-versa
        		even =  ! even;
      		}
		}
	}
}

// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
}




function initValidate(type){

	document.getElementById('submitBtn').onclick = function(){validate(type)};

}

function validate(type){

document.getElementById('formMessage').innerHTML = "";
messageStr = "";
isValid = true;


if(type == 'enquiry'){


var myExp = /^.+@.+\..{2,4}$/;
var form  = document.forms['submitToCMS'];
var email = form.emailTxt.value;

	if(form.fnameTxt && form.fnameTxt.value == "first name" | form.fnameTxt.value == ""){ isValid = false; messageStr = 'first name missing<br />';}
	if(form.lnameTxt && form.lnameTxt.value == "last name" | form.lnameTxt.value == ""){ isValid = false; messageStr = 'last name missing<br />';}
	if(form.emailTxt && form.emailTxt.value == "mail@here.com" | form.emailTxt.value == ""){isValid = false; messageStr += 'email missing<br />';}
	if(form.emailTxt && form.emailTxt.value != "" && myExp.test(email) == false){isValid = false; messageStr += 'invalid email<br />'; }
	if(form.enquiryTxt && form.enquiryTxt.value == "feedback" | form.enquiryTxt.value == ""){isValid = false; messageStr += 'enquiry missing<br />';}
	if(form.enquiryTxt && form.enquiryTxt.value.length > 500){isValid = false; messageStr += 'enquiry exceeds character limit, please rephrase';}
	
	if(!isValid)
		document.getElementById('formMessage').innerHTML = messageStr;
	else{

		document.forms['submitToCMS'].action = "actions/Enquiry.aspx";
		document.forms['submitToCMS'].submit();
		
		}
	
	return isValid;
	
	}
	
else if(type == 'search'){

var form  = document.forms['Search'];

	if(form.queryTxt && form.queryTxt.value == "Search Terms" | form.queryTxt.value == ""){ isValid = false; messageStr = 'Search query missing<br />';}
	if(form.resultsTxt && form.resultsTxt.value == "10" | form.resultsTxt.value == "" |  isNaN(form.resultsTxt.value)){isValid = false; messageStr += 'results to display missing<br />';}
	
	if(!isValid)
		document.getElementById('formMessage').innerHTML = messageStr;
	else
		document.location='advanced-search-results.aspx?page=1&query='+document.forms['Search'].elements.queryTxt.value + '&display=' + document.forms['Search'].elements.resultsTxt.value + '&searchtype=' + document.forms['Search'].elements.matchSel.value + '&orderby=' + document.forms['Search'].elements.orderSel.value;
	
	return isValid;



}
	
	
}



function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.href &&
anchor.rel == "external"){
anchor.target = "_blank";
}
}
}


/* clears text from text boxes */
function clearItem(objElement, value) 
{ 
if(objElement.value == value)
objElement.value="" 
}

/* POP UP'S*/
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	else tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=100,top=200";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
