/* -------------------------------------- */
/* Expand/contract Nav functionality */
/* -------------------------------------- */
/*
function initMenu() {
  $('#leftNav ul').hide(); 
  $('#leftCol li.selected ul').show();


  $('#leftNav li a').click(
    function() {
      var checkElement = $(this).next();
      if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		  
        return false;
      }   
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#leftNav ul:visible').slideUp('normal');
		$('li.expanded').toggleClass('expanded');
		$(this).parents('li').addClass('expanded');

        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }

function initMenu() {
	$('#leftNav ul').hide(); 
	$('#leftCol li.selected ul').show();

	$('#leftNav li a').click(function(e) {

		if ($(this).parent(0).find('ul').children(':first').find('a').attr('href') != null) {
			e.preventDefault();
			window.location = $(this).parent(0).find('ul').children(':first').find('a').attr('href');
		}
		
	});
 }
*/

function initMenu() {

	$('.leftNav ul').css({'display':'none','position':'absolute','z-index':'100','width':'0'});
	
	$('.leftNav li').hover(function () {
		
		var menuTop = $(this).offset().top - 15;
		var menuLeft = $(this).offset().left + $('.leftNav').width()-5;	
		var menuLeft_ori = $(this).offset().left;
		
		$(this).addClass('selected');
		
		$('ul:first',this).css({'display':'block', 'top': menuTop, 'left': menuLeft});		
		
	}, function() {
	
		$(this).removeClass('selected');
		$('ul:first',this).hide();
	});
 }

$(document).ready(function() {initMenu();});

/* -------------------------------------- */
/* Font Resizer */
/* -------------------------------------- */
var min=9;
var max=17;
	function increaseFontSize() {
	   var p = document.getElementsByTagName('body');
	   for(i=0;i<p.length;i++) {
		  if(p[i].style.fontSize) {
			 var s = parseInt(p[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 11;
		  }
		  if(s!=max) {
			 s += 2;
		  }
		  p[i].style.fontSize = s+"px"
	   }
	}
	function decreaseFontSize() {
	   var p = document.getElementsByTagName('body');
	   for(i=0;i<p.length;i++) {
		  if(p[i].style.fontSize) {
			 var s = parseInt(p[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 11;
		  }
		  if(s!=min) {
			 s -= 2;
		  }
		  p[i].style.fontSize = s+"px"
	   }   
	}
	
	
	

/* -------------------------------------- */
/* Table Row stripping (JQuery) */
/* -------------------------------------- */
$(document).ready(function() {	
	$("table.factTable tbody tr:odd").addClass("odd");
	$("table.closingDates tr:odd").addClass("odd");	
	$("div.contentBox").before("<div class='contentBoxTop'></div>");
	$("#coverageStatus").hide();
});

function loadContent(state) {
	
	$("#coverageContent").slideToggle();
	$("#coverageStatus").show();
	$.ajax({
		type: "GET",
		url: "getDirectoryTable.php",
		data: "state=" + state,
		cache: false,
		success: function (html) {
			$("#coverageStatus").hide();	
			$("#coverageContent").html(html).slideToggle(2000);
			hideBackTop();
		}		
	});
	
}

function clearContent() {
	$("#coverageContent").html(' ');
}

function loadClosingDates(area) {
	
	var btns = new Array("metro","regional","local");
	var links = new Array("?Our-Products/Yellow-Pages-Directories-Closing-Dates/Metropolitan-Closing-Dates","?Our-Products/Yellow-Pages-Directories-Closing-Dates/Regional-Closing-Dates","?Our-Products/Yellow-Pages-Directories-Closing-Dates/Local-Closing-Dates");
	$.ajax({
		type: "GET",
		url: "getClosingDates.php",
		data: "area=" + area,
		cache: false,
		success: function (html) {
			$("#closingDatesResult").html(html);
		}
	});	
	
	for (var i=0; i<btns.length; i++) {
		if (btns[i]!=area) $("li."+btns[i]).removeClass("selected");
		else { 
			$("li."+area).addClass("selected");
			$("#viewClosingDates").attr("href",links[i]);
		}
	}
	
	
	
}

/* -------------------------------------- */
/* Target Blank Javascript (rel="external") */
/* -------------------------------------- */
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.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;


/* -------------------------------------- */
/* Detect Caps Lock */
/* -------------------------------------- */

function capLock(e){
 kc = e.keyCode?e.keyCode:e.which;
 sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
 if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
  document.getElementById('divMayus').style.display = 'block';
 else
  document.getElementById('divMayus').style.display = 'none';
}



/* -------------------------------------- */
/* Input fields hover default text */
/* -------------------------------------- */


var active_color = '#000'; // Colour of user provided text
var inactive_color = '#999'; // Colour of default text

$(document).ready(function() {
  $("input.default-value").css("color", inactive_color);
  var default_values = new Array();
  $("input.default-value").focus(function() {
	
	if (this.value=='password here:') {		
		$("input#display").hide();
		$("input.password-value").show();
		$("input.password-value").focus();
    }
	
	if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    $(this).blur(function() {

      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
  
  
  
  $("input.default-answer").focus(function() {
	
	if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
	  this.type='text';
    }
    $(this).blur(function() {	
      if (this.value == '') {
        this.value = default_values[this.id];
		this.type='password';
      }
    });
  });  
  
});

//change it
$(document).ready(function() {
	$("#heading").autocomplete('search.php', {
	}); 
	$("#heading1").autocomplete('search.php', {
	}); 
	$("#heading2").autocomplete('search.php', {
	}); 
	$("#heading3").autocomplete('search.php', {
	}); 
	$("#heading4").autocomplete('search.php', {
	});
});



/* -------------------------------------- */
/* display Backto Top   */
/* -------------------------------------- */
function hideBackTop() {
	
	var the_height = document.getElementById('copy').offsetHeight;
 

	if (the_height > 450) {
		document.getElementById('backToTop').style.visibility = 'visible';
	} else {
		document.getElementById('backToTop').style.visibility = 'hidden';
	}
}



/* -------------------------------------- */
/* Sitemap   */
/* -------------------------------------- */


function sitemapstyler(){
	var sitemap = document.getElementById("sitemap")
	if(sitemap){
		
		this.listItem = function(li){
			if(li.getElementsByTagName("ul").length > 0){
				var ul = li.getElementsByTagName("ul")[0];
				ul.style.display = "none";
				var span = document.createElement("span");
				span.className = "collapsed";
				span.onclick = function(){
					ul.style.display = (ul.style.display == "none") ? "block" : "none";
					this.className = (ul.style.display == "none") ? "collapsed" : "expanded";
				};
				li.appendChild(span);
			};
		};
		
		var items = sitemap.getElementsByTagName("li");
		for(var i=0;i<items.length;i++){
			listItem(items[i]);
		};
		
	};	
};



/* -------------------------------------- */
/* Form Validation						   */
/* -------------------------------------- */

function validateFreeListing() {
    var error = new Array();
	error[0] = validBusinessName(document.freelisting.elements["form[bus_name]"]);
	error[1] = validDirectoryHeading(document.freelisting.elements["form[bus_directory]"]);
	error[2] = validBusinessAddress1(document.freelisting.elements["form[bus_address1]"]);
	error[3] = validBusinessSuburb(document.freelisting.elements["form[bus_suburb]"]);
	error[4] = validBusinessPostcode(document.freelisting.elements["form[bus_postcode]"]);
	error[5] = validBusinessPhone(document.freelisting.elements["form[bus_phone]"]);
	
    error[6] = validFreeContactName(document.freelisting.elements["form[contact_name]"]);
    //error[7] = validCustomerId(document.freelisting.elements["form[customer_id]"]);
    error[7] = validFreeContactPhone(document.freelisting.elements["form[contact_phone]"]);
    error[8] = validContactEmail(document.freelisting.elements["form[contact_email]"]);
    for (i = 0; i < error.length; i++) if (error[i] != '') return false;
	return true;
}

function validateFreelisting2() {
	var error = new Array();
	error[0] = validFreeContactName(document.freelisting.elements["form[contactName]"]);
	error[1] = validFreeContactPhone(document.freelisting.elements["form[contactPhone]"]);
	error[2] = validContactEmail(document.freelisting.elements["form[contactEmail]"]);
	for (i = 0; i < error.length; i++) if (error[i] != '') return false;
	return true;}

function validFreeContactName(e) {
	var error = '';
	if (e.value.length < 1 || e.value.length > 99)	error = 'You have reached the maximum limit of 100.';
	if (!e.value) error = 'Please enter a contact name.';
	if (error) document.getElementById('contactNameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('contactNameError').innerHTML = '';
	return error;
}
function validFreeContactPhone(e) {
	var error = '';
	var pattern = /^[0-9()-]*$/;	
	if (!e.value) error = 'Please enter a phone number.';
	else if (e.value.search(pattern) == -1) error = 'Invalid phone number.';
	if (error) document.getElementById('contactPhoneError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('contactPhoneError').innerHTML = '';
	return error;
}

function validateFreelisting1() {
	var error = new Array();
	error[0] = validAbnAcn(document.freelisting.elements["form[busAbn]"]);
	error[1] = validBusinessName(document.freelisting.elements["form[businessName]"]);
	error[2] = validDirectoryHeading(document.freelisting.elements["form[directoryHeading]"]);
	error[3] = validBusinessAddress1(document.freelisting.elements["form[businessAddress1]"]);
	error[4] = validBusinessSuburb(document.freelisting.elements["form[businessSuburb]"]);
	error[5] = validBusinessPostcode(document.freelisting.elements["form[businessPostcode]"]);
	error[6] = validBusinessState(document.freelisting.elements["form[businessState]"]);
	error[7] = validBusinessPhone(document.freelisting.elements["form[businessPhone]"]);
	
	for (i = 0; i < error.length; i++) if (error[i] != '') return false;
	return true;
}
function validAbnAcn(e) {
	var error = '';
/*	
	var pattern = /^[0-9]*$/;
	if (document.freelisting.elements["form[abnacn]"][0].checked == true) {
		if (!e.value) error = 'Please enter an ABN.';
		else if (e.value.search(pattern) == -1 || e.value.length != 11) error = 'Invalid ABN.';
	}
	else if (document.freelisting.elements["form[abnacn]"][1].checked == true) {
		if (!e.value) error = 'Please enter an ACN.';
		else if (e.value.search(pattern) == -1 || e.value.length != 9) error = 'Invalid ACN.';
	}
	else {
		error = 'Please select either an ABN or ACN.';
	}
	if (error) document.getElementById('abnAcnError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('abnAcnError').innerHTML = '';
*/
	return error;
}

function validCustomerId(e) {
	var error = '';
	var pattern = /^[0-9]*$/;
	if (!e.value) error = '';	
	else if (e.value.search(pattern) == -1 || e.value.length != 9) error = 'Invalid Customer ID.';
	if (error) document.getElementById('customerIdError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('customerIdError').innerHTML = '';
	return error;
}

function validBusinessName(e) {
	var error = '';
	if (!e.value) error = 'Please enter a business name.';

	if (error) document.getElementById('businessNameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessNameError').innerHTML = '';
	return error;
}

function validDirectoryHeading(e) {
	var error = '';
	if (!e.value) {
		error = 'Please enter a directory heading.';
		document.getElementById('directoryHeadingError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
		return error;
	}
	else {
		$.ajax({
			type: "GET",
			url: "check-directoryheading.php",
			data: "directoryHeading=" + escape(e.value),
			cache: false,
			success: function (html) {
				if (html) error = 'Directory heading not found, please choose again.';
				if (error) document.getElementById('directoryHeadingError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
				else document.getElementById('directoryHeadingError').innerHTML = '';
			}
		});
		return error;
	}
}

function validBusinessAddress1(e) {
	var error = '';
	if (!e.value) error = 'Please enter a address.';
	if (error) document.getElementById('businessAddressError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessAddressError').innerHTML = '';
	return error;
}

function validBusinessSuburb(e) {
	var error = '';
	if (!e.value) error = 'Please enter a suburb.';
	if (error) document.getElementById('businessSuburbError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessSuburbError').innerHTML = '';
	return error;
}

function validBusinessPostcode(e) {
	var error = '';
	var pattern = /^[0-9]*$/;	
	if (!e.value) error = 'Please enter a postcode.';
	else if (e.value.search(pattern) == -1 || e.value.length != 4) error = 'Invalid postcode.';
	if (error) document.getElementById('businessPostcodeError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessPostcodeError').innerHTML = '';
	return error;
}

function validBusinessState(e) {
	var error = '';
	if (!e.value) error = 'Please enter a state.';
	if (error) document.getElementById('businessStateError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessStateError').innerHTML = '';
	return error;
}

function validBusinessPhone(e) {
	var error = '';
	var pattern = /^[0-9()-]*$/;	
	if (!e.value) error = 'Please enter a phone number.';
	else if (e.value.search(pattern) == -1) error = 'Invalid phone number.';
	if (error) document.getElementById('businessPhoneError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif" width="12" height="12"/>';
	else document.getElementById('businessPhoneError').innerHTML = '';
	return error;
}

function validateRequestCall2() {
	error ='';
	if (!document.requestacall.elements["form[yellowCustomer]"][0].checked && !document.requestacall.elements["form[yellowCustomer]"][1].checked) error = 'Please make a selection.';
	if (error) {
		document.getElementById('yellowCustomerError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
		return false;
	}
	else {
		document.getElementById('yellowCustomerError').innerHTML = '';
		return true;
	}
}

function validateRequestCall1() {
	var error = new Array();
	error[0] = validContactName(document.requestacall.elements["form[contactName]"]);
	error[1] = validContactPhone(document.requestacall.elements["form[contactPhone]"]);
	error[2] = validContactEmail(document.requestacall.elements["form[contactEmail]"]);
	error[3] = validBusinessName(document.requestacall.elements["form[busName]"]);
	error[4] = validBusinessAddress1(document.requestacall.elements["form[busAddress]"]);
	error[5] = validBusinessSuburb(document.requestacall.elements["form[busSuburb]"]);
	error[6] = validBusinessPostcode(document.requestacall.elements["form[busPostcode]"]);
	error[7] = validBusinessState(document.requestacall.elements["form[busState]"]);
		
	for (i = 0; i < error.length; i++) if (error[i] != '') return false;
	return true;
}


function validateEnquiry() {
	var error = new Array();
	error[0] = validContactName(document.enquiry.elements["form[contactName]"]);
	error[1] = validContactPhone(document.enquiry.elements["form[contactPhone]"]);
	error[2] = validContactEmail(document.enquiry.elements["form[contactEmail]"]);
	error[3] = validBusinessName(document.enquiry.elements["form[busName]"]);
	error[4] = validBusinessAddress1(document.enquiry.elements["form[busAddress]"]);
	error[5] = validBusinessSuburb(document.enquiry.elements["form[busSuburb]"]);
	error[6] = validBusinessPostcode(document.enquiry.elements["form[busPostcode]"]);
	error[7] = validBusinessState(document.enquiry.elements["form[busState]"]);
		
	for (i = 0; i < error.length; i++) if (error[i] != '') return false;
	return true;
}

function validContactName(e) {
	var error = '';
	if (e.value.length < 1 || e.value.length > 99)	error = 'You have reached the maximum limit of 100.';
	if (!e.value) error = 'Please enter a contact name.';
	if (error) document.getElementById('contactNameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('contactNameError').innerHTML = '';
	return error;
}
function validSurname(e) {
	var error = '';
	if (e.value.length < 1 || e.value.length > 99)	error = 'You have reached the maximum limit of 100.';
	if (!e.value) error = 'Please enter a surname.';
	if (error) document.getElementById('surnameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('surnameError').innerHTML = '';
	return error;
}
function validContactEmail(e) {
	var error = '';
	if (e.value) {
		$.ajax({
			type: "GET",
			url: "check-email.php",
			data: "email=" + e.value,
			cache: false,
			success: function (html) {
				if (html == 1) var error = 'Please enter valid Email.';
				if (error) document.getElementById('contactEmailError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
				else document.getElementById('contactEmailError').innerHTML = '';
			}
		});
	}
	else document.getElementById('contactEmailError').innerHTML = '';
	return error;
}

function validContactPhone(e) {
	var error = '';
	var pattern = /^[0-9()-]*$/;	
	if (!e.value) error = 'Please enter a phone number.';
	else if (e.value.search(pattern) == -1) error = 'Invalid phone number.';
	if (error) document.getElementById('contactPhoneError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('contactPhoneError').innerHTML = '';
	return error;
}

function validateForm() {
	var password = '';
	var email = '';
	var error = new Array();
	
	error[0] = validUsername(document.register.elements["form[username]"]);
	error[1] = validSalutation(document.register.elements["form[salutation]"]);
	error[2] = validFirstName(document.register.elements["form[firstName]"]);
	error[3] = validLastName(document.register.elements["form[lastName]"]);
	error[4] = validPassword(document.register.elements["form[password]"]);
	error[5] = validConfirmedPassword(document.register.elements["form[confirmPassword]"]);
	error[6] = validEmail(document.register.elements["form[emailAddress]"]);
	error[7] = validConfirmedEmail(document.register.elements["form[confirmEmailAddress]"]);
	error[8] = validSecretQuestion(document.register.elements["form[secretQuestion]"]);
	error[9] = validSecretAnswer(document.register.elements["form[secretAnswer]"]);
	error[10] = validTerms(document.register.elements["form[terms]"]);
	
	for (i = 0; i < error.length; i++) {
		if (error[i] != '' && error[i] != undefined) return false;
		else return true;
	}
}

function validUsername(e) {
	var error = '';
	var pattern = /^[A-Za-z0-9-._]*$/;	
	if (e.value.length < 6 || e.value.length > 20) error = 'Username must be between 6 and 20 characters.';
	else if (e.value.search(pattern) == -1) error = 'Username may include A-Z, a-z, 0-9, period ".", hythen "-" and underscore "_".';
	if (error) {
		document.getElementById('usernameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
		return error;
	}
	else {
		$.ajax({
			type: "GET",
			url: "check-username.php",
			data: "username=" + e.value,
			cache: false,
			success: function (html) {
				if (html) error = 'The username you entered is already in use.';
				if (error) document.getElementById('usernameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
				else document.getElementById('usernameError').innerHTML = '';
				return error;
			}
		});
	}
}

function validSalutation(e) {
	var error = '';
	if (!e.value) error = 'Please select salutation.';
	if (error) document.getElementById('salutationError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('salutationError').innerHTML = '';
	return error;
}

function validFirstName(e) {
	var error = '';
	if (!e.value) error = 'Please enter first name.';
	if (e.value.length < 1 || e.value.length > 99)	error = 'First name must be between 1 and 100 characters.';
	if (error) document.getElementById('firstNameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('firstNameError').innerHTML = '';
	return error;
}

function validLastName(e) {
	var error = '';
	if (!e.value) error = 'Please enter last name.';
	if (e.value.length < 1 || e.value.length > 99)	error = 'You have reached the maximum limit of 100 characters.';
	if (error) document.getElementById('lastNameError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('lastNameError').innerHTML = '';
	return error;
}

function validPassword(e) {
	var error = '';
 	kc = e.keyCode?e.keyCode:e.which;
 	sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
 	if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk)) error = 'Caps lock is on';
	if (e.value.length < 6 || e.value.length > 30)	error = 'Password must be between 6 and 30 characters.';
	$.ajax({
		type: "GET",
		url: "check-password.php",
		data: "password=" + e.value,
		cache: false,
		success: function (html) {
			if (html) error = 'Password must have the a combination of letters and numbers.';
			if (error) document.getElementById('passwordError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
			else document.getElementById('passwordError').innerHTML = '';
		}
	});
	password = e.value;
	if (error) document.getElementById('passwordError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('passwordError').innerHTML = '';
	return error;
}
function validConfirmedPassword(e) {
	var error = '';
	if (e.value != password) error = 'The entered passwords do not match.';
	if (error) document.getElementById('confirmedPasswordError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('confirmedPasswordError').innerHTML = '';
	return error;
}

function validEmail(e) {
	var error = '';
	$.ajax({
		type: "GET",
		url: "check-email.php",
		data: "email=" + e.value,
		cache: false,
		success: function (html) {
			if (html == 1) var error = 'Please enter valid Email.';
			if (html == 2) var error = 'The email you entered is already in use.';
			if (error) document.getElementById('emailError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
			else document.getElementById('emailError').innerHTML = '';
		}
	});
	email = e.value;
	return error;
}

function validConfirmedEmail(e) {	
	var error = '';	
	if (e.value != email) error = 'The entered emails do not match.';
	if (error) document.getElementById('confirmedEmailError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('confirmedEmailError').innerHTML = '';
	return error;
}

function validSecretQuestion(e) {
	var error = '';
	if (!e.value) error = 'Please select a secret question.';
	if (error) document.getElementById('secretQuestionError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('secretQuestionError').innerHTML = '';
	return error;
}

function validSecretAnswer(e) {
	var error = '';
	if (e.value.length < 2 || e.value.length > 40) error = 'Secret answer must be between 2 and 40 characters.';
	if (error) document.getElementById('secretAnswerError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('secretAnswerError').innerHTML = '';
	return error;
}

function validTerms(e) {
	var error = '';
	if (!e.checked) error = 'Please read and tick terms and conditions checkbox.';
	if (error) document.getElementById('termsError').innerHTML = '<img style="cursor: help;" onclick="alert(\'' + error + '\');" title="' + error + '" alt="' + error + '" src="/images/validationIcon.gif"/>';
	else document.getElementById('termsError').innerHTML = '';
	return error;
}
/* function to allow only number entry to edit box*/
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
/*function to check a-z A-Z*/

function isAlphaKey(evt)
{
	 var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && charCode != 32 &&( (charCode < 65 || charCode > 90 ) && (charCode < 97 || charCode > 122) ))
	return false;
	return true;
}




/* Drop Down Menu Hack*/
function foo(px,py,pw,ph,baseElement,fid)
{
		var win = document.getElementById(this.fid);
}


function dropdown_menu_hack(el)
{
	if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
	el.runtimeStyle.behavior="none";

	var ie5 = (document.namespaces==null);
	el.ondblclick = function(e)
	{
		window.event.returnValue=false;
		return false;
	}
	
	if(window.createPopup==null)
	{
		
		var fid = "dropdown_menu_hack_" + Date.parse(new Date());
	
		window.createPopup = function()
		{
			if(window.createPopup.frameWindow==null)
			{
					el.insertAdjacentHTML("AfterEnd","<iframe   id='"+fid+"' name='"+fid+"' src='about:blank'  frameborder='1' scrolling='no'></></iframe>");
					var f = document.frames[fid];
					f.document.open();
					f.document.write("<html><body></body></html>");
					f.document.close();
					f.fid = fid; 
					

					var fwin = document.getElementById(fid);
					fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";
				
					
					f.show = function(px,py,pw,ph,baseElement)
					{							
						py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
						px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
						fwin.style.width = pw + "px";
						fwin.style.height = ph + "px";						
						fwin.style.posLeft =px ;
						fwin.style.posTop = py ;		
						fwin.style.display="block";						
					}

					
					f_hide = function(e)
					{ 
						if(window.event && window.event.srcElement	&& window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
						fwin.style.display="none";
					} 
					f.hide = f_hide;
					document.attachEvent("onclick",f_hide);		
					document.attachEvent("onkeydown",f_hide);		
					
			}
			return f;
		}
	}

	function showMenu()
	{
		
		function selectMenu(obj)
			{				
				var o = document.createElement("option");
				o.value = obj.value;
				o.innerHTML = obj.innerHTML;			
				while(el.options.length>0){el.options[0].removeNode(true);}
				el.appendChild(o);
				el.title =  o.innerHTML; 
				el.contentIndex = obj.selectedIndex  ;
				el.menu.hide(); 				
			}		
		
		
		el.menu.show(0 , el.offsetHeight , 10,  10, el); 
		var mb = el.menu.document.body;
		
		mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;text-aligbn:center;font-family:Verdana;font-size:12px;";
		var t = el.contentHTML;
		t = t.replace(/<select/gi,'<ul');
		t = t.replace(/<option/gi,'<li');
		t = t.replace(/<\/option/gi,'</li');
		t = t.replace(/<\/select/gi,'</ul');
		mb.innerHTML = t;	
	
		
		el.select = mb.all.tags("ul")[0];
		el.select.style.cssText="list-style:none;margin:0;padding:0;";
		mb.options = el.select.getElementsByTagName("li");
		
		for(var i=0;i<mb.options.length;i++)
		{
			mb.options[i].selectedIndex = i;
			mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;cursor:hand;cursor:pointer;white-space:nowrap;"
			mb.options[i].title =mb.options[i].innerHTML;
			mb.options[i].innerHTML ="<nobr>" + mb.options[i].innerHTML + "</nobr>";
			mb.options[i].onmouseover = function()
				{
					if( mb.options.selected ){mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
					mb.options.selected = this;
					this.style.background="#333366";this.style.color="white";
				}
			
			mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
			mb.options[i].onmousedown = function(){selectMenu(this);	}
			mb.options[i].onkeydown = function(){selectMenu(this);	}
				

			if(i == el.contentIndex)
			{
				mb.options[i].style.background="#333366";
				mb.options[i].style.color="white";	
				mb.options.selected = mb.options[i];
			}
		}
	
		
		var mw = Math.max(   ( el.select.offsetWidth + 22 ), el.offsetWidth + 22  );
			 mw = Math.max(  mw, ( mb.scrollWidth+22) );
		var mh =  mb.options.length * 15  + 8 ; 
			 
		var mx = (ie5)?-3:0;
		var my = el.offsetHeight -2;
		var docH =   document.documentElement.offsetHeight ;
		var bottomH = docH  - el.getBoundingClientRect().bottom ; 

		mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100)		);
		
		if(( bottomH < mh) )
		{
			
			mh = Math.max( (bottomH - 12),10);
			if( mh <100 ) 
			{
				my = -100 ;

			}
			mh = Math.max(mh,100);			
		}

		
		self.focus(); 
		
		el.menu.show( mx , my ,  mw, mh , el); 
		sync=null;
		if(mb.options.selected)
		{
			mb.scrollTop = mb.options.selected.offsetTop;
		}
	

		
		
		window.onresize = function(){el.menu.hide()};		
	}

	function switchMenu()
	{
		if(event.keyCode)
		{
			if(event.keyCode==40){ el.contentIndex++ ;}
			else if(event.keyCode==38){ el.contentIndex--; }
		}
		else if(event.wheelDelta )
		{
			if (event.wheelDelta >= 120)
			el.contentIndex++ ;
			else if (event.wheelDelta <= -120)
			el.contentIndex-- ;
		}else{return true;}




		if( el.contentIndex > (el.contentOptions.length-1) ){ el.contentIndex =0;}
		else if (el.contentIndex<0){el.contentIndex = el.contentOptions.length-1 ;}

		var o = document.createElement("option");
			 o.value = el.contentOptions[el.contentIndex].value;
			 o.innerHTML = el.contentOptions[el.contentIndex].text;
			 while(el.options.length>0){el.options[0].removeNode(true);}
			 el.appendChild(o);
			 el.title =  o.innerHTML; 
	}
	
	if(dropdown_menu_hack.menu ==null)
	{
		dropdown_menu_hack.menu =  window.createPopup();
		document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
	}
	el.menu = dropdown_menu_hack.menu ;
	el.contentOptions = new Array();
	el.contentIndex = el.selectedIndex;
	el.contentHTML = el.outerHTML;

	for(var i=0;i<el.options.length;i++)
	{	
		el.contentOptions [el.contentOptions.length] = 
		{
			"value": el.options[i].value,
			"text": el.options[i].innerHTML
		}

		if(!el.options[i].selected){el.options[i].removeNode(true);i--;};
	}

	
	el.onkeydown = switchMenu;
	el.onclick = showMenu;
	el.onmousewheel= switchMenu;

}

