
function showPic2(newImage, imageID) {
   $('img[id|=placeholder]').attr('src',newImage);
   if(document.getElementById('erf')){	document.getElementById('erf').style.display = '';}
	if(document.getElementById('refBoard')){	document.getElementById('refBoard').style.display = 'none';}
	if(document.getElementById('ref')){	document.getElementById('ref').style.display = '';}
	if(document.getElementById('refBoardd')){	document.getElementById('refBoardd').style.display = 'none';}
   if(document.getElementById('refNumber')){	document.getElementById('refNumber').innerHTML = imageID;}
}
 			function addToRefBoard(){
				$.ajax({
					type: "GET",
				   url: "/jScript/ajaxFunctions.php",
				   
				   // parameters sent through appended to the URL when using GET
				   data: "method=addRefBoard&cat="+document.getElementById('refNumber').innerHTML,
				   
				   // data type returned as
           		dataType: "text",
				   
				   // beforeSend loads an image/text to display when the event is started
				   beforeSend: function(){
				   }, 
            
				   // changes or removes the loading image/text once completed
					complete: function(){ 
				       if(document.getElementById('erf')){	document.getElementById('erf').style.display = 'none';}
				       if(document.getElementById('refBoard')){	document.getElementById('refBoard').style.display = '';}
				       if(document.getElementById('ref')){	document.getElementById('ref').style.display = 'none';}
				       if(document.getElementById('refBoardd')){	document.getElementById('refBoardd').style.display = '';}
					},
					
				   // process completed
					success: function(msg){
				      if(msg.length>2){
				      	alert(msg);
				      }
				   }
	        });
			}

function ccText() {
	for(var i = 0; i < document.forms['payment'].paymentSelection.length; i++ ) {
		if( document.forms['payment'].paymentSelection[i].checked == true )
			var val = document.forms['payment'].paymentSelection[i].value;
		}
   alert("DEMO FINISHED\nThe following actions are now performed\n\n1. The customer pays by "+val+"\n2. System sends the customer an order confirmation email\n3. System sends you an order generation notification");
   return false;
}

function submitenter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13){
   	myfield.form.submit();
   	return false;
   }else{
   	return true;
	}
}

function popUp(URL, wt, ht, tp, lft) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+wt+",height="+ht+",left ="+lft+",top ="+tp+"');");
}
function validateClassified() {
	var message = "";
	if ($("input[name='phone']").val().length < 2){
		message += "Please enter a Contact Phone\n";
	}
	if (!isValidEmail($("input[name='email']").val()) ){
		message += "Please enter a valid Contact Email\n";
	}
	if ($("input[name='classifiedTitle']").val().length < 2){
		message += "Please enter the Classied Title\n";
	}
//	if ($("select[name='classifiedCountry']").val().length < 1){
//		message += "Please select a Country\n";
//	}
//	if ($("input[name='classifiedSuburb']").val().length < 1){
//		message += "Please select a Suburb\n";
//	}
	if ($("select[name='categoriesID']").val().length < 1){
		message += "Please select a Category\n";
	}
	if ($("select[name='subCategoriesID']").val().length < 1){
		message += "Please select a Sub Category\n";
	}
	if ($("textarea[name='description']").val().length < 2){
		message += "Please enter the Classied Description\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		document.getElementById("loading").style.display = '';
		return true;
	}
}
function validateAddImages() {
	var message = "";
	if ($("input[name='imageTitle']").val().length < 2){
		message += "Please enter the Image Title\n";
	}
	if ($("input[name='image1']").val().length < 2){
		message += "Please select an image to Upload\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		document.getElementById("loading").style.display = '';
		return true;
	}
}
function validateAddVideo() {
	var message = "";
	if ($("input[name='videoTitle']").val().length < 2){
		message += "Please enter the Video Title\n";
	}
	if ($("input[name='videoAuthor']").val().length < 2){
		message += "Please enter the Video Author\n";
	}
	if ($("textarea[name='description']").val().length < 2){
		message += "Please enter a Description\n";
	}
	if ($("input[name='file1']").val().length < 2){
		message += "Please select an Video to Upload\n";
	}
	if (!document.forms[0].authorise.checked){
		message += "Please click the Authorisation box\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		document.getElementById("loading").style.display = '';
		return true;
	}
}
function validateAddArticle() {
	var message = "";
	if ($("input[name='articleTitle']").val().length < 2){
		message += "Please enter the Article Title\n";
	}
	if ($("input[name='articleAuthor']").val().length < 2){
		message += "Please enter the Article Author\n";
	}
	if ($("textarea[name='description']").val().length < 2){
		message += "Please enter a Description\n";
	}
	if ($("input[name='file1']").val().length < 2){
		message += "Please select an article to Upload\n";
	}else{
		var data = $("input[name='file1']").val().split(".");
		if(data[1]!= "doc" && data[1]!="docx"  && data[1]!="txt"){
			message += "We accept word documents only\n";
		}
	}
	if (!document.forms[0].authorise.checked){
		message += "Please click the Authorisation box\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		document.getElementById("loading").style.display = '';
		return true;
	}
}
function validateInfo(){
	var message = "";
	if ($("input[name='infoTitle']").val().length < 2){
		message += "Please enter the Information Title\n";
	}
	if ($("select[name='categoriesID']").val().length < 1){
		message += "Please select a Category\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		document.getElementById("loading").style.display = '';
		return true;
	}
	
}
function validateContactForm() {
	var message = "";
	if ($("input[name='name']").val().length < 3 ){
		message += "Please enter your Name \n";
	}
	if ( !isValidEmail($("input[name='email']").val())){
		message += "Please enter a valid Email Address\n";
	}
	if ($("input[name='email']").val() != $("input[name='reemail']").val()){
		message += "Please re-enter your Email Address\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		return true;
	}
}
function validateEmailFriend(){             
	var message = "";
	if ($("input[name='name']").val().length < 3 ){
		message += "Please enter your Name \n";
	}
	if ( !isValidEmail($("input[name='email']").val())){
		message += "Please enter your valid Email\n";
	}
	if ( !isValidEmail($("input[name='friendsEmail']").val())){
		message += "Please enter a valid Friend Email\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		return true;
	}
} 
function displayRow(fieldName){
	var row = document.getElementById(fieldName);
	if (row.style.display == ''){
		row.style.display = 'none';
	}else{
		row.style.display = '';    
	}
}
function askDeleteQuestion() { 
   if(confirm("Are you sure you want to delete this?")){
	   return true;
   }else{
	   return false;
   }
} 
// Sets it to close
function closeRow(fieldName){
	var row = document.getElementById(fieldName);
	row.style.display = 'none';
}
//Sets it to open
function showRow(fieldName){
	var row = document.getElementById(fieldName);
	row.style.display = '';    
}
function checkState(val){
	if (val == "Australia"){
		showRow('ausStates');
		closeRow('otherState');
	}else{
		showRow('otherState');
		closeRow('ausStates');
	}
}
function searchBox() {
	if ($("input[name='searchInput']").val().length < 3 ){
		alert("Please enter search text");
		return false;
	}else{
		return true;
	}
}
function isValidEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return true;
	}else{
		return false;
	}
}
function validateCustomerUpdate() {
	var message = "";
	if ($("input[name='name']").val().length < 2){
		message += "Please enter a valid Name\n";
	}
	if ($("input[name='surname']").val().length < 2){
		message += "Please enter a valid Surname\n";
	}
	if (!isValidEmail($("input[name='email']").val()) ){
		message += "Please enter a valid Email Address\n";
	}
	if ($("input[name='address']").val().length < 2){
		message += "Please enter a valid Address\n";
	}
	if ($("input[name='suburb']").val().length < 2){
		message += "Please enter a valid Suburb\n";
	}
	if ($("input[name='postCode']").val().length < 2){
		message += "Please enter a valid Post Code\n";
	}
	if ($("select[name='state']").val().length < 2 && $("input[name='otherState']").val().length < 2){
		message += "Please enter a valid State\n";
	}
	if ($("select[name='country']").val().length < 2){
		message += "Please enter a valid Country\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		return true;
	}
}
function validateCustomer() {
	var message = "";
	if ($("input[name='name']").val().length < 2){
		message += "Please enter a valid Name\n";
	}
	if ($("input[name='surname']").val().length < 2){
		message += "Please enter a valid Surname\n";
	}
	if (!isValidEmail($("input[name='email']").val()) ){
		message += "Please enter a valid Email Address\n";
	}
	if ($("input[name='repassword2']").val().length < 4){
		message += "Please enter a Password between 4 - 10 chars\n";
	}
	if ($("input[name='postCode']").val().length < 4){
		message += "Please enter a valid Post Code\n";
	}
	if(message.length > 1){
		alert(message);
		return false;
	}else{
		return true;
	}
}
