// JavaScript Document
var d = document, dE = d.documentElement;
var fixIEwidth = 0;

/*<![CDATA[*/
function IEHoverPseudo() {

	var navItems = document.getElementById("menu").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent"; }
		}
	}

}
/*]]>*/



/*	This is to toggle the home page
	descriptions on and off when
	the user hovers over the grid	*/
function toggleExpandDesc(sect) {
    document.getElementById("homeText-intro").style.display = 'none';
	if (sect == "company") {
		document.getElementById("homeText-company").style.display = 'block';
	} else
	if (sect == "host") {
		document.getElementById("homeText-host").style.display = 'block';
	} else
	if (sect == "products") {
		document.getElementById("homeText-products").style.display = 'block';
	} else
	if (sect == "join") {
		document.getElementById("homeText-join").style.display = 'block';
	}
}

function toggleCloseDesc() {
	document.getElementById("homeText-intro").style.display = 'block';
    document.getElementById("homeText-company").style.display = 'none';
	document.getElementById("homeText-host").style.display = 'none';
	document.getElementById("homeText-products").style.display = 'none';
	document.getElementById("homeText-join").style.display = 'none';
}


/*	This is to disable certain fields
	in the registration for based on
	Australia or New Zealand residency	*/
function dsblflds() {
	if(document.registerfrm.country.value == "NZL")
	{
		document.registerfrm.state.disabled=true;
		document.registerfrm.postcode.disabled=true;
	} else {
		document.registerfrm.state.disabled=false;
		document.registerfrm.postcode.disabled=false;
	}
}

/*
  -------------------------------------------------------------------------
	                Validation Script in JavaScript
                                Version 2.0
	Copyright 2003 JavaScript-coder.com. All rights reserved.
	You use this script in your Web pages, provided these opening credit
    lines are kept intact.
	The Form validation script is distributed free from JavaScript-Coder.com

	In return, you are requested to add a link to JavaScript-Coder.com, 
	making it easy for others to find this script.
	You can get the code for the link from: 
	http://www.javascript-coder.com/gen/link-to-us.phtml 

	If you want to get your site listed in the members' page, 
	send an email to: support@javascript-coder.com 

    You may not reprint or redistribute this code without permission from 
    JavaScript-Coder.com.
	
	JavaScript Coder
	It precisely codes what you imagine!
	Grab your copy here:
		http://www.javascript-coder.com/
    -------------------------------------------------------------------------  
*/
/*function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}*/
function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	/*if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}*/
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
    this.itemobj.focus();
		return false;
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}


function ValidateChkboxContactInterest()
{
	var count = 0;
	var count2 = 0;
	var count3 = 0;
	var return1 = 0;
	var return2 = 0;
	var return3 = 0;
	
	for (j=1; j<=5; j++){
	if (eval('document.contactfrm.mag'+j+'.checked') == false)
		count2++;
		
	}
	if (count2 < 5) {
		var return1 = 1;
	}
	else
	{
		alert("Please let us know if you’ve seen 1 of our magazine advertorials, by checking at least 1 box.");
	}


	/*var return1 = 1;*/

	if (return1 == 1)
	{
		for (k=1; k<=10; k++){
		if (eval('document.contactfrm.seen'+k+'.checked') == false)
			count3++;
			
		}
		if (count3 < 10) {
			var return2 = 1;
		}
		else
		{
			alert("Please let us know if you have seen a Lorraine Lea Linen ad");
		}
	}
	
	if (return2 == 1)
	{
		for (i=1; i<=5; i++){
		if (eval('document.contactfrm.interest'+i+'.checked') == false)
			count++;
			
		}
		if (count < 5) {
			var return3 = 1;
		}
		else
		{
			alert("Please enter an area of interest");
		}
	}
	
	if (return1 == 1 && return2 == 1 && return3 == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function V2validateData(strValidateStr,objValue,strError) 
{ 
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
        case "req": 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
            if(!objValue.value.match(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name+": Invalid characters found "; 
              }//if                                                               
              alert(strError); 
              return false;                   
            }//if 
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
		 
		 // This is a custom valifation for LLL and absolute form names are being used
		 
		 case "regphone": 
          { 
		  	if(document.registerfrm.country.value == "AUS")
			{	//check to see if the number in AUS is longer than 10
				 if(eval(objValue.value.length) >  10) 
				 { 
				   alert("Please enter your phone number including area code"); 
				   return false; 
				 }//if 
				 //check to see if the number in AUS is less than 10
				 if(eval(objValue.value.length) <  10) 
				 {         
				   alert("Please enter your phone number including area code"); 
				   return false;                 
				 }//if 
		 	 }//if
			 if(document.registerfrm.country.value == "NZL")
			 {	//check to see if the number in NZ is longer than 9
				 if(eval(objValue.value.length) >  9) 
				 { 
				   alert("Please enter your phone number including area code"); 
				   return false; 
				 }//if 
				 //check to see if the number in NZ is less than 9
				 if(eval(objValue.value.length) <  9) 
				 {         
				   alert("Please enter your phone number including area code"); 
				   return false;                 
				 }//if 
		 	 }//if
             break; 
          }//case regphone 
		  
		  case "regkit": 
          { 
		  	if(document.registerfrm.country.value == "NZL")
			 {	//check to see if the kit number in NZ starts with 9
				 if(eval(objValue.value) <  9000) // this takes the entire number and makes sure it is above 9000
				 { 
				   alert("Please enter a correct kit number"); 
				   return false; 
				 }//if  
		 	 }//if
             break; 
          }//case regkit 
		  
		  case "regpostcode": 
         { 
		 if(document.registerfrm.country.value == "AUS")
			{	//check to see if the number in AUS is longer than 10
			   if(document.registerfrm.postcode.value.length == 0) 
			   { 
				  alert("Please enter a postcode"); 
				  return false; 
			   }//if 
			   if(eval(objValue.value.length) >  4) 
				 { 
				   alert("Please enter a correct postcode"); 
				   return false; 
				 }//if 
				 //check to see if the number in AUS is less than 10
				 if(eval(objValue.value.length) <  4) 
				 {         
				   alert("Please enter a correct postcode"); 
				   return false;                 
				 }//if 
			  var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               	alert("Please enter a correct postcode"); 
                return false; 
              }//if 
			}//if 
           break;             
         }//case required 
		  
		  case "conphone": 
          { 
		  	if(document.contactfrm.country.value == "AUS")
			{	//check to see if the number in AUS is longer than 10
				 if(eval(objValue.value.length) >  10) 
				 { 
				   alert("Please enter your phone number including area code"); 
				   return false; 
				 }//if 
				 //check to see if the number in AUS is less than 10
				 if(eval(objValue.value.length) <  10) 
				 {         
				   alert("Please enter your phone number including area code"); 
				   return false;                 
				 }//if 
		 	 }//if
			 if(document.contactfrm.country.value == "NZL")
			 {	//check to see if the number in NZ is longer than 9
				 if(eval(objValue.value.length) >  9) 
				 { 
				   alert("Please enter your phone number including area code"); 
				   return false; 
				 }//if 
				 //check to see if the number in NZ is less than 9
				 if(eval(objValue.value.length) <  9) 
				 {         
				   alert("Please enter your phone number including area code"); 
				   return false;                 
				 }//if 
		 	 }//if
             break; 
          }//case conphone

		case "conpcode": 
          { 
		  	if(document.contactfrm.country.value == "AUS")
			{	//check to see if the number in AUS is longer than 10
				 if(eval(objValue.value.length) >  4) 
				 { 
				   alert("Please enter your postcode"); 
				   return false; 
				 }//if 
				 //check to see if the number in AUS is less than 10
				 if(eval(objValue.value.length) <  4) 
				 {         
				   alert("Please enter your poscode"); 
				   return false;                 
				 }//if 
		 	 }//if
			 if(document.contactfrm.country.value == "NZL")
			 {	//check to see if the number in NZ is longer than 9

		 	 }//if
             break; 
          }//case conpcode
		case "constate": 
          { 
		  	if(document.contactfrm.country.value == "AUS")
			{	//check to see if the number in AUS is longer than 10
				 if(eval(objValue.value.length) <  1) 
				 {         
				   alert("Please enter your state or region"); 
				   return false;                 
				 }//if 
		 	 }//if
			 if(document.contactfrm.country.value == "NZL")
			 {	//check to see if the number in NZ is longer than 9

		 	 }//if
             break; 
          }//case conpcode
    }//switch 
    return true; 
}






//start thickbox code

//add event function
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

//remove event function
function removeEvent( obj, type, fn )
{
	EventCache.remove(obj, type, fn);
}

//flush all events on page unload
var EventCache = function()
{
var listEvents = [];
return {
listEvents : listEvents,
add : function(node, sEventName, fHandler)
{
listEvents.push(arguments);
},
remove : function(node, sEventName, fHandler)
{
var i, item;
for(i = listEvents.length - 1; i >= 0; i = i - 1) {
if(node == listEvents[i][0] && sEventName == listEvents[i][1] && fHandler == listEvents[i][2]) {
item = listEvents[i];
if(item[0].removeEventListener) {
item[0].removeEventListener(item[1], item[2], item[3]);
}
if(item[1].substring(0, 2) != "on") {
item[1] = "on" + item[1];
}
if(item[0].detachEvent) {
item[0].detachEvent(item[1], item[0][sEventName+fHandler]);

}
item[0][item[1]] = null;
}
}
},
flush : function()
{
var i, item, eventtype;
for(i = listEvents.length - 1; i >= 0; i = i - 1) {
item = listEvents[i];
if(item[0].removeEventListener) {
item[0].removeEventListener(item[1], item[2], item[3]);
}
eventtype = item[1];
if(item[1].substring(0, 2) != "on") {
item[1] = 'on' + item[1];
}
if(item[0].detachEvent) {
item[0].detachEvent(item[1], item[2]);
item[0].detachEvent(item[1], item[0][eventtype+item[2]]);
}
item[0][item[1]] = null;
}
}
}
}();

//flush'em
addEvent(window,'unload',EventCache.flush);


//adding event functions to specific links using jquery:

// Full expands a tree with a given ID
function expandTree(treeId) {
  var ul = document.getElementById(treeId);
  if (ul == null) { return false; }
  expandCollapseList(ul,nodeOpenClass);
}

// Fully collapses a tree with a given ID
function collapseTree(treeId) {
  var ul = document.getElementById(treeId);
  if (ul == null) { return false; }
  expandCollapseList(ul,nodeClosedClass);
}

function blockEvents(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "");
		if(evt.target){
		evt.preventDefault();
		}else{
		evt.returnValue = false;
		}
}

// $(document).ready(function(){

// $("a.expandAll").click(function(e){expandTree('treemenu1');blockEvents(e);});
// $("a.collapseAll").click(function(e){collapseTree('treemenu1');blockEvents(e);});
// $("ul.treemenu").find("a").click(function(){$("ul.treemenu").find("a").removeClass("treeMenuFocus");this.className = 'treeMenuFocus'});
// $("a.printButton").click(function(e){window.print();blockEvents(e);});

// });

//end thickbox code

/* Make external links pop
*******************************************************************************/
function popExLinks() {
	var aTags = d.getElementsByTagName("a");
	
	for( var i=0; i<aTags.length; i++ ) 
	{
		// all non-javascript/mailto href attributes pointing to external locations  or if it's a pdf document
		if (aTags[i].href.indexOf(document.hostpayments) == 0) {
			// Do nothing
		}
		else if( (aTags[i].href.indexOf("http://") == 0 && aTags[i].href.indexOf("http://"+d.domain) != 0) || (aTags[i].href.indexOf("https://") == 0 && aTags[i].href.indexOf("https://"+d.domain) != 0) || aTags[i].href.indexOf("http://") == 0 && aTags[i].href.indexOf(".pdf") > 5 || aTags[i].href.indexOf("http://") == 0 && aTags[i].href.indexOf(".html") > 5) 
		{
			aTags[i].target = "_blank";
		}
	}
}

/* Disable right click on images
*******************************************************************************/
function right() {
	function clickIE() {if (document.all) {(message);return false;}}
	function clickNS(e) {if 
	(document.layers||(document.getElementById&&!document.all)) {
	if (e.which==2||e.which==3) {(message);return false;}}}
	if (document.layers) 
	{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
	else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
	document.oncontextmenu=new Function("return false")
}

/* Perform on page load/unload
*******************************************************************************/

function init() {
	window.defaultStatus = "Lorraine Lea Linen";
}

window.onload = function(e) {
	// startList;
	if (d.getElementById) {
		if (d.all) {
			IEHoverPseudo();
		}
	
	
		// Opera wont switch css sometimes unless we do it onload! POS!
		if (navigator.userAgent.indexOf('Opera') != -1) {
			init();
		}
	
		popExLinks();

		right();
	}
};
window.onunload = function(d) {
	if (d.getElementById) {
	}
};

if (d.all && !window.opera && fixIEwidth == 0) {
	
}

function inputFocus() {
	d.frmLogin.UserID.focus();
}

/* Perform as soon as we can!
*******************************************************************************/
init();
