﻿function validateMiniSignupForm() {
	if ((document.getElementById('MiniSignupFirstName').value == '') || (document.getElementById('MiniSignupFirstName').value == 'first name')) {
		window.alert('Please enter your first name');
		return false;
	}
	if ((document.getElementById('MiniSignupLastName').value == '') || (document.getElementById('MiniSignupLastName').value == 'last name')) {
		window.alert('Please enter your last name');
		return false;
	}
	if ((document.getElementById('MiniSignupEmail').value == '') || (document.getElementById('MiniSignupEmail').value == 'email')) {
		window.alert('Please enter your email address');
		return false;
	}
}

function validateSignupForm() {
	if (document.getElementById('SignupFirstName').value == '') {
		window.alert('Please enter your first name');
		return false;
	}
	if (document.getElementById('SignupLastName').value == '') {
		window.alert('Please enter your last name');
		return false;
	}
	if (document.getElementById('Address1').value == '') {
		window.alert('Please enter your address');
		return false;
	}
	if (document.getElementById('City').value == '') {
		window.alert('Please enter your city');
		return false;
	}
	if (document.getElementById('Postcode').value == '') {
		window.alert('Please enter your postcode');
		return false;
	}
	if (document.getElementById('SignupEmail1').value == '') {
		window.alert('Please enter your email address');
		return false;
	}
	if (document.getElementById('SignupEmail1').value != document.getElementById('SignupEmail2').value) {
		window.alert('Please enter the same email address into both boxes');
		return false;
	}
	if (document.getElementById('SignupPassword1').value == '') {
		window.alert('Please enter a password');
		return false;
	}
	if (document.getElementById('SignupPassword1').value != document.getElementById('SignupPassword2').value) {
		window.alert('Please enter the same password into both boxes');
		return false;
	}
	sPassword1 = document.getElementById('SignupPassword1').value;
	if (sPassword1.length < 6) {
		window.alert('Your password should be 6 - 10 characters long');
		return false;
	}
}

function validateChangePasswordForm() {
	if (document.getElementById('CurrentPassword').value == '') {
		window.alert('Please enter your current password');
		return false;
	}
	if (document.getElementById('NewPassword1').value == '') {
		window.alert('Please enter a new password');
		return false;
	}
	if (document.getElementById('NewPassword1').value != document.getElementById('NewPassword2').value) {
		window.alert('Please enter the same password into both new password boxes');
		return false;
	}
	sNewPassword1 = document.getElementById('NewPassword1').value;
	if (sNewPassword1.length < 6) {
		window.alert('Your password should be 6 - 10 characters long');
		return false;
	}
}

function validateChangeEmailForm() {
	if (document.getElementById('NewEmail1').value == '') {
		window.alert('Please enter a new email address');
		return false;
	}
	if (document.getElementById('NewEmail1').value != document.getElementById('NewEmail2').value) {
		window.alert('Please enter the same email into both new email boxes');
		return false;
	}
	if (document.getElementById('Password').value == '') {
		window.alert('Please enter your current password');
		return false;
	}	
}

function validateClassifiedForm() {
	if (document.getElementById('ProductName').value == '') {
		window.alert('Please enter a product name');
		return false;
	}
	if (document.getElementById('ShortDesc').value == '') {
		window.alert('Please enter a short description');
		return false;
	}
	if (document.getElementById('LongDesc').value == '') {
		window.alert('Please enter a long description');
		return false;
	}
	if (isNaN(document.getElementById('PriceMin').value) || document.getElementById('PriceMin').value == '') {
		window.alert('Please enter a valid price');
		return false;
	}
	if (isNaN(document.getElementById('PriceMax').value) || document.getElementById('PriceMax').value == '') {
		window.alert('Please enter a valid maximum price');
		return false;
	}
	if (document.getElementById('ContactName').value == '') {
		window.alert('Please enter a contact name');
		return false;
	}
}

function validateCompEntryForm() {
	if (document.getElementById('FirstName').value == '') {
		window.alert('Please enter your first name');
		return false;
	}
	if (document.getElementById('LastName').value == '') {
		window.alert('Please enter your last name');
		return false;
	}
	if (document.getElementById('Email').value == '') {
		window.alert('Please enter your email address');
		return false;
	}
	if (document.getElementById('Address1').value == '') {
		window.alert('Please enter your address');
		return false;
	}
	if (document.getElementById('City').value == '') {
		window.alert('Please enter your city');
		return false;
	}
	if (document.getElementById('Postcode').value == '') {
		window.alert('Please enter your city');
		return false;
	}
	if (document.getElementById('CompAcceptTerms').checked == false) {
		window.alert('You must accept the competition\'s Terms and conditions');
		return false;
	}
}

function chooseProductForAd(iProductID, sProductName) {
	// Populate the product name and id onto the opener
	window.opener.document.getElementById('ProductID').value = iProductID;
	window.opener.document.getElementById('ProductName').value = sProductName;
	// Show the div and hide the text box
	window.opener.document.getElementById('ProductName').style.display = 'none';
	window.opener.document.getElementById('ChosenProductName').style.display = 'block';
	// Chuck the product name into the div
	if (window.opener.document.getElementById('ChosenProductName').innerHTML != undefined) {
		window.opener.document.getElementById('ChosenProductName').innerHTML = sProductName;
	} else {
	window.opener.document.getElementById('ChosenProductName').textContent = sProductName;
	}
	window.close();
}

function openProductPickerWindow(iProductCategoryId) {
	// Blank out the product name text box and div
	document.getElementById('ProductName').value = '';
	if (document.getElementById('ChosenProductName').innerHTML != undefined) {
		document.getElementById('ChosenProductName').innerHTML = '';
		document.getElementById('ProductName').value = '';
	} else {
		document.getElementById('ChosenProductName').textContent = '';
	}
	// Reset the hidden field
	document.getElementById('ProductID').value = 0;
	// Show the text box and hide the div
	document.getElementById('ProductName').style.display = 'block';
	document.getElementById('ChosenProductName').style.display = 'none';
	// Open a popup window
	window.open('new_product_popup.asp?pc=' + iProductCategoryId, 'productwindow', 'width=400,height=400');
}

// Voting stars functions
function showOnStars(iItemId, iStarId) {
	for (iCount = 1; iCount <= iStarId; iCount++) {
		sSelectedStarDivId = 'Voting_' + iItemId + '_' + iCount;
		//document.getElementById(sSelectedStarDivId).setAttribute("class", "VotingStarOn");
		document.getElementById(sSelectedStarDivId).className = "VotingStarOn";
	}
}
function showOffStars(iItemId, iStarId) {
	for (iCount = 1; iCount <= iStarId; iCount++) {
		sSelectedStarDivId = 'Voting_' + iItemId + '_' + iCount;
		//document.getElementById(sSelectedStarDivId).setAttribute("class", "VotingStarOff");
		document.getElementById(sSelectedStarDivId).className = "VotingStarOff";
	}
}
function rateItem(iItemId, iRating, iNumberOfStars, sPostURL) {
	var sPostURL = sPostURL + '?i=' + iItemId + '&r=' + iRating
	if (window.XMLHttpRequest) {
		// mozilla/firefox etc
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open('GET', sPostURL, false);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) {
		// internet explorer
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.open('GET', sPostURL, false);
			xmlhttp.send();
		}
	}
	iNewAverageRating = xmlhttp.responseText;
	if (iNewAverageRating > 0) {
		// do stuff here to hide the container
		sVotingContainerName = 'VotingStarsContainer_' + iItemId;
		document.getElementById(sVotingContainerName).style.display = 'none';
		// refresh the little rating stars
		for (iCount = 1; iCount <= iNumberOfStars; iCount++) {
			sSelectedRatingStarDivId = 'Rating_' + iItemId + '_' + iCount;
			if (iCount <= iNewAverageRating) {
				//document.getElementById(sSelectedRatingStarDivId).setAttribute("class", "RatingStarOn");
				document.getElementById(sSelectedRatingStarDivId).className = "RatingStarOn";
			} else {
			//document.getElementById(sSelectedRatingStarDivId).setAttribute("class", "RatingStarOff");
			document.getElementById(sSelectedRatingStarDivId).className = "RatingStarOff";
			}
		}
		// Increment the rating counter
		sRatingCounterId = 'Ratings_total_' + iItemId;
		iRatingCounterTotal = document.getElementById(sRatingCounterId).firstChild.nodeValue;
		iRatingCounterTotal = parseInt(iRatingCounterTotal) + 1;
		document.getElementById(sRatingCounterId).firstChild.nodeValue = iRatingCounterTotal;
	}
}

function checkComposeForm(sNickname) {
	if (sNickname == '') {
		window.alert('Please enter a nickname');
		return false;
	} else {
		// check the entered nickname exists in the context of this website
		iCustomerID = checkNickname(sNickname);
		if (iCustomerID == 0) {
			window.alert('The nickname you entered can\'t be found');
			return false;
		}
	}
	if (document.getElementById('Subject').value == '') {
		window.alert('Please enter a subject');
		return false;
	}
}

function checkNickname(sNickname){
	// Stuff to work out date (needed to make sure browser doesn't cache callbacks)
	var today = new Date();
	var iMinutes = today.getMinutes();
	var iSeconds = today.getSeconds();
	var iMilliseconds = today.getMilliseconds();
	sPostURL = '/generic/ajax/check_nickname.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&n=' + sNickname;
	if (window.XMLHttpRequest) {
		// mozilla/firefox etc
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open('GET', sPostURL, false);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) {
		// internet explorer
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.open('GET', sPostURL, false);
			xmlhttp.send();
		}
	}
	iCustomerID = xmlhttp.responseText;
	return iCustomerID;
}

function getMiniAlbum(sPlane, iAlbumId) {
	// Stuff to work out date (needed to make sure browser doesn't cache callbacks)
	var today = new Date();
	var iMinutes = today.getMinutes();
	var iSeconds = today.getSeconds();
	var iMilliseconds = today.getMilliseconds();
	sPostURL = '/generic/ajax/get_mini_album.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&p=' + sPlane + '&a=' + iAlbumId;
	if (window.XMLHttpRequest) {
		// mozilla/firefox etc
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open('GET', sPostURL, false);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) {
		// internet explorer
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.open('GET', sPostURL, false);
			xmlhttp.send();
		}
	}
	sAlbumHtml = xmlhttp.responseText;
	return sAlbumHtml;
}

function reSortAlbum() {
	window.alert('hello');
}

function getNicknameMatches(sSearch, sResultsElementName) {
	if (sSearch.length >= 3) {
		// Stuff to work out date (needed to make sure IE doesn't mess me about by caching the callbacks)
		var today = new Date();
		var iMinutes = today.getMinutes();
		var iSeconds = today.getSeconds();
		var iMilliseconds = today.getMilliseconds();
		// Make the URL
		var postURL = '/generic/ajax/compose_msg_customer_list.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&s=' + sSearch + '&e=' + sResultsElementName
		if (window.XMLHttpRequest) {
			// mozilla/firefox etc
			xmlhttp = new XMLHttpRequest();
			xmlhttp.open('GET', postURL, false);
			xmlhttp.send(null);
		}
		else if (window.ActiveXObject) {
			// internet explorer
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			if (xmlhttp) {
				xmlhttp.open('GET', postURL, false);
				xmlhttp.send();
			}
		}
		sSearchResults = xmlhttp.responseText;
		document.getElementById(sResultsElementName).style.display = 'block';
		document.getElementById(sResultsElementName).innerHTML = sSearchResults;
	} else {
	document.getElementById(sResultsElementName).style.display = 'none';
	document.getElementById(sResultsElementName).innerHTML = '';
	}
}

function selectNicknameMatch(sNickname, sResultsElementName) {
	document.getElementById('Nickname').value = sNickname;
	document.getElementById(sResultsElementName).style.display = 'none';
	document.getElementById(sResultsElementName).innerHTML = '';
}

function checkForImageInForm(sImageName) {
	if (sImageName == '') {
		window.alert('Please choose an image');
		return false;
	}
}

function checkNicknameForm() {
	sOldNickname = document.getElementById('OldNickname').value;
	sNewNickname = document.getElementById('NewNickname').value;
	if (sNewNickname == '') {
		window.alert('Please enter a nickname');
		return false;
	}
	if (sOldNickname == sNewNickname) {
		window.alert('You have not changed your nickname');
		return false;
	}
	var iCustomerId = checkNickname(sNewNickname)
	if (iCustomerId > 0) {
		window.alert('The nickname you have chosen is already in use');
		return false;
	}
}

function getPostingAsQuote(iPostingId) {
	var editor1 = document.getElementById('CE_Posting_ID');


	// Stuff to work out date (needed to make sure IE doesn't mess me about by caching the callbacks)
	var today = new Date();
	var iMinutes = today.getMinutes();
	var iSeconds = today.getSeconds();
	var iMilliseconds = today.getMilliseconds();
	// Make the URL
	var postURL = '/generic/ajax/get_posting_as_quote.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&p=' + iPostingId
	if (window.XMLHttpRequest) {
		// mozilla/firefox etc
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open('GET', postURL, false);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) {
		// internet explorer
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.open('GET', postURL, false);
			xmlhttp.send();
		}
	}
	sPosting = xmlhttp.responseText;
	editor1.PasteHTML(sPosting + '<p>&nbsp;</p>');
	editor1.FocusDocument();
}

function openNewWindow(sUrl) {
	window.open(sUrl, 'window', 'width=980,height=600,status=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes');
}

// Functions for CuteEditor custom dialogs

function getMemberAlbum(button){
	//use CuteEditor_GetEditor(elementinsidetheEditor) to get the cute editor instance
	var editor=CuteEditor_GetEditor(button);
	//show the dialog page , and pass the editor as newwin.dialogArguments
	//(handler,url,args,feature)
	var newwin=editor.ShowDialog(null,'/CuteEditor_files/Dialogs/InsertFromAlbum_Custom.asp',editor,'dialogWidth:650px;dialogHeight:375px');
}

function getMemberAlbum_Article(button) {
	//use CuteEditor_GetEditor(elementinsidetheEditor) to get the cute editor instance
	var editor = CuteEditor_GetEditor(button);
	//show the dialog page , and pass the editor as newwin.dialogArguments
	//(handler,url,args,feature)
	var newwin = editor.ShowDialog(null, '/CuteEditor_files/Dialogs/InsertFromAlbum_Article_Custom.asp', editor, 'dialogWidth:650px;dialogHeight:350px');
}





function reportAbuse(iWebsiteId, iThreadId, iPostingId, iCustomerId) {
    // Stuff to work out date (needed to make sure IE doesn't mess me about by caching the callbacks)
    var today = new Date();
    var iMinutes = today.getMinutes();
    var iSeconds = today.getSeconds();
    var iMilliseconds = today.getMilliseconds();
    // Make the URL
    var postURL = '/generic/ajax/report_abuse.asp?now=' + iMinutes + iSeconds + iMilliseconds + '&p=' + iPostingId + '&c=' + iCustomerId + '&th=' + iThreadId + '&w=' + iWebsiteId
    if (window.XMLHttpRequest) {
        // mozilla/firefox etc
        xmlhttp = new XMLHttpRequest();
        xmlhttp.open('GET', postURL, false);
        xmlhttp.send(null);
    }
    else if (window.ActiveXObject) {
        // internet explorer
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        if (xmlhttp) {
            xmlhttp.open('GET', postURL, false);
            xmlhttp.send();
        }
    }
    sReported = xmlhttp.responseText;
    if (sReported == 'True') {
        document.getElementById('Report' + iPostingId).innerHTML = '<strong>Reported</strong>';
    }
    else {
        window.alert('Reporting Failed');
    }
}
