function un_load(id1, id2)
{
	document.all[id1].style.display = "block";
	document.getElementById(id2).style.opacity = .5;
	document.getElementById(id2).style.filter = 'alpha(opacity=50)';
}
function pre_load(id1, id2)
{
	document.all[id1].style.display = "none";
	document.getElementById(id2).style.opacity = 1;
	document.getElementById(id2).style.filter = 'alpha(opacity=100)';
}
function cnt(id)
{
	var y=document.getElementById(id).value;
	var r = 0;
	a=y.replace(/\s/g,' ');
	a=a.split(' ');
	for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
	if((60-r) >0)
		document.getElementById('c').innerHTML = (60-r)+' Words Left';
	else
		document.getElementById('c').innerHTML = (r-60)+' Words Too Many';
	document.getElementById('h_c').value = (60-r);
	if((60-r) == 0)
		document.getElementById(id).blur();
}
function getMulti(id)
{
	var array = new Array();
	for (var i = 0; i < document.getElementById(id).length; i++)
	{
		if (document.getElementById(id).options[i].selected)
			array.push(document.getElementById(id).options[i].text);
	}
	return array;
}
function IsEmail(email)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})/;
   var address = email
   if(reg.test(address) == false)
      return false;
   return true;
}
function IsNumeric(sText)
{
	var ValidChars = "0123456789 ";//only numbers are accepted e.g. ! 3.01, -3, 30a etc
	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;
}
function blocking(nr, state)
{
	if(state == 'INT')
	{
		document.getElementById(nr).style.display = 'block';
		document.getElementById('country').disabled = false;
	}
	else if(state != 'INT')
	{
		document.getElementById(nr).style.display = 'none';
		document.getElementById('int_state').value = '';
		document.getElementById('country').value = 'Australia';
		document.getElementById('country').disabled = true;
	}
}
function chkChar(str, extra)
{
	var iChars = "$^*=[]\\;{}|\""+extra;
	var valid = true;
	for (var i = 0; i < str.length; i++)
	{
		if (iChars.indexOf(str.charAt(i)) != -1)
			valid = false;
	}
	return valid;
}
function validateForm1()//login.php
{
	var errors = '';
	if(document.login.username.value == '')
		errors += 'Please enter your Username.\n';
	if(document.login.password.value == '')
		errors += 'Please enter your Password.\n';
	if(errors != '')
	{
		alert(errors);
		return false;
	}
	else
		document.login.js.value = 'y';
}
function validateForm2()//sixty_words.php
{
	var errors = '';
	var words = document.getElementById('h_c').value;
	if(!chkChar(document.sixty_form.blurb.value, ''))
		errors += '60 Words Description cannot contain these charactors:\n$^*=[]\\;{}|\"';
	else if(words <0)
		errors += 'You cannot have more than 60 words in your 60 Words Description';
	if(errors != '')
	{	
		alert(errors+' '+words);
		return false;
	}
}
function validateForm3()//special_offer.php
{
	var errors = '';
	if(document.so_form.headline.value == '')
		errors += 'Please enter the Headline for your Special offer.\n';
	else if(!chkChar(document.so_form.headline.value, ''))
		errors += 'Special Offer Headline cannot contain these charactors:\n$^*=[]\\;{}|\"\n';
	if(document.so_form.desc.value == '')
		errors += 'Please enter the Description for your Special offer.\n';
	if(!chkChar(document.so_form.desc.value, ''))
		errors += 'Special Offer Description cannot contain these charactors:\n$^*=[]\\;{}|\"\n';
	if(!chkChar(document.so_form.calltoaction.value, ''))
		errors += 'Special Offer Call to Action cannot contain these charactors:\n$^*=[]\\;{}|\"\n';
	if(!chkChar(document.so_form.terms.value, ''))
		errors += 'Special Offer Terms and Conditions cannot contain these charactors:\n$^*=[]\\;{}|\"\n';
	if(errors != '')
	{
		alert(errors);
		return false;
	}
}
function validateForm4()//my_account.php - perosnl details
{
	var errors = '';
	var firstname = document.pd_form.firstname.value;
	var lastname = document.pd_form.lastname.value;
	var role = document.pd_form.role.value;
	var mobile = document.pd_form.mobile.value;
	var email = document.pd_form.email.value;
	var com_email = document.pd_form.com_email.value;
	var phone = document.pd_form.phone.value;
	var fax = document.pd_form.fax.value;
	
	if(firstname == '')
		errors += 'Please enter your First Name.\n';
	else if(IsNumeric(firstname))
		errors += 'Your First Name cannot be numeric entry.\n';
	else if(!chkChar(firstname, ''))
		errors += 'Your First Name cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(lastname == '')
		errors += 'Please enter your Last Name.\n';
	else if(IsNumeric(lastname))
		errors += 'Your Last Name cannot be numeric entry.\n';
	else if(!chkChar(lastname, ''))
		errors += 'Your Last Name cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(role != '')
	{
		if(!chkChar(role, ''))
			errors += 'Your Business Position cannot contain these characters:\n$^*=[]\\;{}|\"\n';
		else if(IsNumeric(role))
			errors += 'Your Business Position cannot be numeric entry.\n';
	}
	if(mobile != '')
	{
		if(mobile.length < 8)
			errors += 'Your Mobile phone number must be at least 8 digits number e.g. 04 1111 1111.\n';	
		else if(!IsNumeric(mobile))
				errors += 'Your Mobile phone number must be at least 8 digits number e.g. 04 1111 1111.\n';
	}
	if(email == '')
		errors += 'Please enter your Email.\n';
	else if(email != '')
	{
		if(!IsEmail(email))
			errors += 'Please enter a Valid Email.\n';
		else if(com_email == '')
			errors += 'Please Confirm your Email.\n';
		else if(com_email != email)
			errors += 'Please Confirm your Email.\n';
	}
	if(phone != '')
	{
		if(phone.length < 8)
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(phone))
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(fax != '')
	{
		if(fax.length < 8)
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(fax))
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(errors != '')
	{
		alert(errors);
		return false;
	}
}
function validateForm5()//my_account.php - login details
{
	var errors = '';
	var h_username = document.ld_form.h_username.value;
	var username = document.ld_form.username.value;
	var org_pwd = document.ld_form.org_pwd.value;
	var cur_pwd = document.ld_form.cur_pwd.value;
	var new_pwd = document.ld_form.new_pwd.value;
	var con_pwd = document.ld_form.con_pwd.value;
	
	if(username == '')
		errors += 'Please enter an Username.\n';
	else if(!chkChar(username, ''))
		errors += 'Your Username cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(cur_pwd != '' || new_pwd != '' || con_pwd != '')
	{
		if(cur_pwd == '')
			errors += 'Please enter your Current Password.\n';
		else if(cur_pwd != org_pwd)
			errors += 'Please enter the Valid Current Password.\n';
		if(new_pwd == '')
			errors += 'Please enter the New Password.\n';
		else if(new_pwd != '')
		{
			if(new_pwd.length <6)
				errors += 'New Password must be minimum of 6 characters.\n';
			else if(!chkChar(new_pwd, ''))
				errors += 'New Password cannot contain these characters:\n$^*=[]\\;{}|\"\n';
			else if(new_pwd == cur_pwd)
				errors += 'New Password cannot be the same as the Current Password.\n';
			else
			{
				if(new_pwd != '' && con_pwd == '')
					errors += 'Please Confirm your New Password.\n';
				else if(con_pwd != new_pwd)
					errors += 'Please enter the New Password to confirm it.\n';	
			}
		}
	}
	else
		errors += 'Please enter new Login Details.\n';
	
	if(errors != '')
	{
		alert(errors);
		return false;
	}
}
function validateForm6()//my_blisting.php
{
	var errors = '';
	var company = document.listing.company.value;
	var addr1 = document.listing.addr1.value;
	var addr2 = document.listing.addr2.value;
	var state = document.listing.state.value;
	var int_state = document.listing.int_state.value;
	var postcode = document.listing.postcode.value;
	var country = document.listing.country.value;
	var email = document.listing.email.value;
	var com_email = document.listing.com_email.value;
	var phone = document.listing.phone.value;
	var fax = document.listing.fax.value;
	var desc = document.listing.desc.value;
	var url = document.listing.url.value;
	var words = document.getElementById('h_c').value;
	//alert(category+'\n'+city+'\n'+suburb+'\n'+company+'\n'+addr1+'\n'+addr2+'\n'+state+'\n'+int_state+'\n'+postcode+'\n'+country+'\n'+email+'\n'+phone+'\n'+fax+'\n'+desc+'\n'+url);
	if(company == '')
		errors += 'Please enter your Company name.\n';
	else if(!chkChar(company, ''))
		errors += 'Your Company name cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(addr1 == '')
		errors += 'Please enter your Address 1.\n';
	else if(!chkChar(addr1, ''))
		errors += 'Your Address 1 cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(addr1 == '' && addr2 != '')
		errors += 'Please use the Address 1 field first.\n';
	else if(!chkChar(addr2, ''))
		errors += 'Your Address 2 cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(state == 'INT')
	{
		if(int_state == '')
			errors += 'Your State is required to complete the form.\n';
		else if(!chkChar(int_state, ''))
			errors += 'Your State can not contain these characters:\n$^*=[]\\;{}|\"\n';
			
		if(country == 'Australia')
			errors += 'Please select a country other then Australia or select an Australian State.\n';
	}
	if(state != 'INT')
	{
		if(postcode == '')
			errors += 'Your Postcode is required to complete the form.\n';
		else
		{
			if(!IsNumeric(postcode))
				errors += 'Your Postcode/Zip Code must be a 4 digits number e.g. 3101.\n';
			else if(postcode.length < 4)
				errors += 'Your Postcode/Zip Code must be a 4 digits number e.g. 3101.\n';
			else if(postcode.length > 4)
				errors += 'Your Postcode/Zip Code cannot be more than 4 digits e.g. 3101.\n';
		}
	}
	if(postcode != '')
	{
		if(!chkChar(postcode, ''))
			errors += 'Your Postcode/Zip Code can not contain these characters:\n$^*=[]\\;{}|\"\n';
	}
	if(email == '')
		errors += 'Please enter your Email address.\n';	
	else
	{
		if(!IsEmail(email))
		errors += 'Please enter a Valid Email.\n';
		else if(com_email == '')
			errors += 'Please Confirm your Email.\n';
		else if(com_email != email)
			errors += 'Please Confirm your Email.\n';
	}
	if(phone == '')
		errors += 'Please enter your Phone number.\n';
	else if(phone != '')
	{
		if(phone.length < 8)
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(phone))
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(fax != '')
	{
		if(fax.length < 8)
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(fax))
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(desc != '')
	{
		if(!chkChar(desc, ''))
			errors += 'Your 60 Words Description cannot contain these charactors:\n$^*=[]\\;{}|\"';	
		else if(words <0)
			errors += 'You cannot have more than 60 words in your 60 Words Description';
	}
	if(errors != '')
	{
		alert(errors);
		return false;
	}
}
function validateForm7()//my_support.php
{
	var errors = '';
	var company = document.support.company.value;
	var firstname = document.support.firstname.value;
	var lastname = document.support.lastname.value;
	var phone = document.support.phone.value;
	var mobile = document.support.mobile.value;
	var email = document.support.email.value;
	var fax = document.support.fax.value;
	var category = document.support.category.value;
	var comments = document.support.comments.value;
	//alert(firstname+'\n'+lastname+'\n'+phone+'\n'+mobile+'\n'+email+'\n'+fax+'\n'+category+'\n'+comments);
	if(firstname == '')
		errors += 'Please enter your First Name.\n';
	else if(IsNumeric(firstname))
		errors += 'Your First Name cannot be numeric entry.\n';
	else if(!chkChar(firstname, ''))
		errors += 'Your First Name cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(lastname == '')
		errors += 'Please enter your Last Name.\n';
	else if(IsNumeric(lastname))
		errors += 'Your Last Name cannot be numeric entry.\n';
	else if(!chkChar(lastname, ''))
		errors += 'Your Last Name cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(phone == '')
		errors += 'Please enter your Phone Number.\n';
	else if(phone != '')
	{
		if(phone.length < 8)
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(phone))
			errors += 'Your Phone number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(mobile != '')
	{
		if(mobile.length < 8)
			errors += 'Your Mobile phone number must be at least 8 digits number e.g. 04 1111 1111.\n';	
		else if(!IsNumeric(mobile))
				errors += 'Your Mobile phone number must be at least 8 digits number e.g. 04 1111 1111.\n';
	}
	if(email == '')
		errors += 'Please enter your Email.\n';
	else if(email != '')
	{
		if(!IsEmail(email))
			errors += 'Please enter a Valid Email.\n';
	}
	
	if(fax != '')
	{
		if(fax.length < 8)
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';	
		else if(!IsNumeric(fax))
			errors += 'Your Fax number must be at least 8 digits number e.g. 03 9123 4567.\n';
	}
	if(category == '')
		errors += 'Please select the Category.\n';
	if(comments == '')
		errors += 'Please enter your comments.\n';
	else if(!chkChar(comments, ''))
		errors += 'Your Comments cannot contain these characters:\n$^*=[]\\;{}|\"\n';
	if(errors != '')
	{
		pre_load('load', 'tbl');
		alert(errors);
		return false;
	}
}

function checkEmail()
{
	
	if(document.lost_pwd.email.value == "")
	{
		alert("You must specify an Email address");
		return false;
	}
	else if(!IsEmail(document.lost_pwd.email.value))
	{
		alert("Please enter a Valid Email address");
		return false;
	}
	return true;
}
function chkMove()
{
	var errors = '';
	var cate = document.getElementById('category').value;
	var city = document.getElementById('city').value;
	var suburb = document.getElementById('suburb').value;
	var o_1 = document.getElementById('o_1').value;
	var o_2 = document.getElementById('o_2').value;
	var o_3 = document.getElementById('o_3').value;
	
	if(cate == '0' && o_1 == '')
		errors += 'Please specify the Category or select on from the list.\n';
	else if(!chkChar(o_1, '-/&_'))
		errors += 'Category cannot contain these characters.\n$^*=[]\\;{}|\-/&_"\n';
	if(city == '0' && o_2 == '')
		errors += 'Please specify the City or select on from the list.\n';
	else if(!chkChar(o_2, '-/&_'))
		errors += 'City cannot contain these characters.\n$^*=[]\\;{}|\-/&_"\n';
	if(suburb == '0' && o_3 == '')
		errors += 'Please specify the Suburb or select on from the list.\n';
	else if(!chkChar(o_3, '-/&_'))
		errors += 'Suburb cannot contain these characters.\n$^*=[]\\;{}|\-/&_"\n';
	if(errors != '')
	{
		alert(errors);
		return false;
	}
	else
		return confirmation('Are you sure you want to move you listing?');
}
