/**************************************/
/*
Copyright©2010 Cork Street Ooen Exhibition
by Red Cherry Solutions
*/
/**************************************/

/**************************************/
/* Swap the active CSS */
function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) a.disabled = true;
			if (a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

/**************************************/
/* Popup */
function popup (obj, iW, iH) {
	var winW = iW;
	var winH = iH;
	var winName = '_blank';
	var winL = (screen.width - winW) / 2;
	var winT = ((screen.height - winH) / 2) - 50;
	window.open(obj.href, winName, 'location=no, toolbar=no, status=no, directories=no, scrollbars=yes, menubar=no, resizable=no, left=' + winL + ', top=' + winT +', width=' + winW + ', height=' + winH);
}

/**************************************/
/* Turn off a menu */
function offMenu (obj) {
	document.getElementById(obj + 'Arrows').style.display = 'block';
	document.getElementById(obj).style.display = 'none';
}

/**************************************/
/* Change Menu */
function swapMenu (obj) {
	//check if hidden and show or opposite
	if (document.getElementById(obj).style.display == 'block') {
		document.getElementById(obj).style.display = 'none';
	} else {
		document.getElementById(obj).style.display = 'block';
	}
}

/**************************************/
/* New Entry Form */
function updateFormNewEntry(oForm) {

	if (oForm.category.options[oForm.category.selectedIndex].value == 'Sculpture' || oForm.category.options[oForm.category.selectedIndex].value == 'Mixed Media') {
		document.getElementById('subExtra').style.display = 'block';
	} else {
		document.getElementById('subExtra').style.display = 'none';
	}

	if (oForm.category.options[oForm.category.selectedIndex].value == 'Sculpture' || oForm.category.options[oForm.category.selectedIndex].value == 'Mixed Media') {
		document.getElementById('subUD').style.display = 'inline';
		document.getElementById('subFD').style.display = 'inline';
		document.getElementById('subWeight').style.display = 'block';
	} else {
		document.getElementById('subUD').style.display = 'none';
		document.getElementById('subFD').style.display = 'none';
		document.getElementById('subWeight').style.display = 'none';
	}

	if (oForm.category.options[oForm.category.selectedIndex].value != 'Photography') {
		document.getElementById('subCredit').style.display = 'block';
	} else {
		document.getElementById('subCredit').style.display = 'none';
	}
}

/**************************************/
/* New Entry Form */
function updateFormViewEntry(oForm) {

	if (oForm.category.options[oForm.category.selectedIndex].value == 'Sculpture' || oForm.category.options[oForm.category.selectedIndex].value == 'Mixed Media') {
		document.getElementById('subUD').style.display = 'inline';
		document.getElementById('subFD').style.display = 'inline';
		document.getElementById('subWeight').style.display = 'block';
	} else {
		document.getElementById('subUD').style.display = 'none';
		document.getElementById('subFD').style.display = 'none';
		document.getElementById('subWeight').style.display = 'none';
	}
	
	if (oForm.category.options[oForm.category.selectedIndex].value != 'Photography') {
		document.getElementById('subCredit').style.display = 'block';
	} else {
		document.getElementById('subCredit').style.display = 'none';
	}
}

/**************************************/
/* Entry Validation */
function validateEntry(oForm) {
	var bValid = true;
/*
	//check for security code
	if (oForm.code.value.length < 4) {
		alert('Please enter the security code');
		return false;
	}
*/

	//check normal form
	if (oForm.forename.value == '' ||
/*		oForm.initial.value == '' ||*/
		oForm.surname.value == '') {
		alert('Please enter your forename and surnames.');
		return false;
	}
	if (oForm.houseName.value == '') {
		alert('Please enter a house name or number.');
		return false;
	}
	if (oForm.town.value == '') {
		alert('Please enter your town or city.');
		return false;
	}
	if (oForm.postcode.value == '') {
		alert('Please enter your postal or zip code.');
		return false;
	}
	if (oForm.country.options[oForm.country.selectedIndex].text == 'Please Select') {
		alert('Please select your country.');
		return false;
	}
	if (oForm.county.options[oForm.county.selectedIndex].text == 'Please Select') {
		alert('Please select your county/province.');
		return false;
	}
	if (oForm.telephone.value == '') {
		alert('Please enter your contact telephone number.');
		return false;
	}
	if (oForm.howHear.options[oForm.howHear.selectedIndex].text == 'Please Select') {
		alert('Please tell us how you heard about us.');
		return false;
	}

	//check email
	if (validateEmail(oForm.email) == false) {
		alert('Please enter a valid email address.');
		return false;
	}
	if (oForm.email.value != oForm.emailConfirm.value) {
		alert('Your email address and confirmation do not match.');
		return false;
	}

	//check password
	if (oForm.password.value == '') {
		alert('Please enter a password to login to your account with.');
		return false;
	}
	if (oForm.password.value != oForm.passwordConfirm.value) {
		alert('Your password and confirmation do not match.');
		return false;
	}

	//return correctly
//	if (bValid == false) {
//		alert('Please fill out all fields');
//		return false;
//	}

	return true;
}

/**************************************/
/* Work Validation */
function validateWork(oForm) {
	var bValid = true;

	//check normal form
	if (oForm.file.value == '') {
		alert('Please select an image file to upload.');
		return false;
	}
	if (oForm.title.value == '') {
		alert('Please specify a title for the piece.');
		return false;
	}
	if (isNaN(oForm.dimensionsH.value) || isNaN(oForm.dimensionsW.value)) {
		alert('Please specify the dimensions.');
		return false;
	}
	if (isNaN(oForm.dateCompletedDD.value) || isNaN(oForm.dateCompletedMM.value) || (isNaN(oForm.dateCompletedYYYY.value))) {
		alert('Please provide the date that the work was completed.');
		return false;
	}
	if (isNaN(oForm.price.value)) {
		alert('Please enter a numeric price as a whole number for the piece.  Example: enter £200.00 as 200');
		return false;
	}
	if (oForm.dimensionsH.value == '' ||
		oForm.dimensionsW.value == '') {
		alert('Please specify the piece dimensions.');
		return false;
	}
	if (oForm.dateCompletedDD.value == '' ||
		oForm.dateCompletedMM.value == '' ||
		oForm.dateCompletedYYYY.value == '') {
		alert('Please specify the date the piece was completed.');
		return false;
	} else {
		/*valid timescale*/
	    var d1 = new Date(oForm.dateCompletedYYYY.value, oForm.dateCompletedMM.value, oForm.dateCompletedDD.value);
	    var d2 = new Date(2009, 12, 31);

	    var milli_d1 = d1.getTime();
	    var milli_d2 = d2.getTime();

		if ((milli_d1 - milli_d2) < 0) {
			alert('The piece can only be submitted if it was completed after 31/12/2009.');
			return false;
		}
	}

	if (oForm.price.value == '') {
		alert('Please specify the price of the piece.');
		return false;
	}
	if (oForm.categoryMedium.options[oForm.categoryMedium.selectedIndex].text == 'Please Select') {
		alert('Please select the medium of the piece.');
		return false;
	}

	//check date piece created
	if (isDate(oForm.dateCompletedDD.value, oForm.dateCompletedMM.value, oForm.dateCompletedYYYY.value) == false) {
		alert('Please enter a valid completion date: DD/MM/YYYY');
		return false;
	}

	//check piece year
	if (oForm.dateCompletedYYYY.value < 2009) {
		alert('The piece must have been created after 31/12/2008');
		return false;
	}

	return true;
}

/**************************************/
/* validate the email field */
function validateEmail(field) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) { return false; }
		else { return true; }
	}
}

/* date validation */
function isDate(dd,mm,yyyy) {
   var d = new Date(mm + "/" + dd + "/" + yyyy);
   return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}









































//<!-- hide from old browsers...
var info
var initVal = "please select"

function createArray() {
info = new Array(
initVal + "*Please Select",
"United Kingdom*Please Select|Angus|Antrim|Argyll and Bute|Armagh|Avon|Ayrshire|Bedfordshire|Berkshire|Blaenau Gwent|Birmingham|Borders|Bridgend|Bristol|Buckinghamshire|Caerphilly|Cambridgeshire|Cardiff|Carmarthenshire|Central|Ceredigion|Channel Islands|Cheshire|Clwyd|Conwy|Cornwall|County Durham|Cumbria|Denbighshire|Derbyshire|Devon|Dorset|Dumfries and Galloway|Down|Dyfed|East Sussex|East Yorkshire|Edinburgh|Essex|Fermanagh|Fife|Flintshire|Galway|Glasgow|Gloucestershire|Grampian|Greater Manchester|Gwent|Gwynedd|Hampshire|Herefordshire|Hertfordshire|Highland|Isle of Anglesey|Isle of Man|Isle of Wight|Kent|Lanarkshire|Lancashire|Leicestershire|Lincolnshire|London|Londonderry|Lothian|Merseyside|Merthyr Tydfil|Middlesex|Mid Glamorgan|Monmouthshire|Neath Port Talbot|Newport|Norfolk|North Yorkshire|Northamptonshire|Northumberland|Nottinghamshire|Orkney|Oxfordshire|Pembrokeshire|Powys|Rhondda Cynon Taf|Shetland|Shropshire|Somerset|South Glamorgan|South Yorkshire|Staffordshire|Strathclyde|Suffolk|Surrey|Swansea|Tayside|Torfaen|Tyne and Wear|Tyrone|Vale of Glamorgan|Warwickshire|West Midlands|West Sussex|West Yorkshire|Western Isles|West Glamorgan|Wiltshire|Worcestershire|Wrexham",
"United States*Please Select|Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming",
"Ireland*Please Select|Carlow|Cavan|Clare|Cork|Donegal|Dublin|Galway|Kerry|Kildare|Kilkenny|Laois|Leitrim|Limerick|Longford|Louth|Mayo|Meath|Monaghan|Offaly|Roscommon|Sligo|Tipperary|Waterford|Westmeath|Wexford|Wicklow",
"Australasia*Please Select|Fiji|New South Wales|New Zealand|Northern Territory|Papua New Guinea|Queensland|South Australia|Tasmania|Victoria|Western Australia",
"Canada*Please Select|Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland|NorthWest Territories|Nova Scotia|Ontario|Prince Edward Island|Quebec|SasKatchewan|Yukon",
"Africa*Please Select|Algeria|Angola|Benin|Botswana|Burkina Faso|Burundi|Cameroon|Cape Verdi Islands|Central African Republic|Chad|Comoros|Congo|Djibouti Republic|Egypt|Equatorial Guinea|Ethiopia|Gabon|Gambia|Ghana|Guinea|Guinea-Bissau|Ivory Coast|Kenya|Lesotho|Liberia|Libya|Madagascar|Mali|Mauritania|Mauritius|Morocco|Mozambique|Namibia|Niger|Nigeria|Reunion|Rwanda|Senegal|Seychelles|Sierra Leone|South Africa|Sudan|Swaziland|Tanzania|Tunisia|Uganda|Zaire|Zambia|Zimbabwe",
"Asia*Please Select|Afghanistan|Azerbaijan|Bangladesh|Bhutan|Brunei|Burma|Cambodia|China|Hong Kong|India|Indonesia|Japan|Kazakhstan|Laos|Macau|Malaysia|Maldive Islands|Mongolia|Nepal|North Korea|Pakistan|Philippines|Singapore|South Korea|Sri Lanka|Taiwan|Thailand|Vietnam",
"Europe*Please Select|Albania|Andorra|Austria|Belarus|Belgium|Bosnia and Herzegovina|Bulgaria|Croatia|Cyprus|Czech Republic|Denmark|Estonia|Faroe Islands|Finland|France|Germany|Gibraltar|Greece|Hungary|Iceland|Italy|Latvia|Lithuania|Luxembourg|Macedonia|Malta|Netherlands|Norway|Poland|Portugal|Romania|Russian Federation|Serbia|Slovakia|Slovenia|Spain|Sweden|Switzerland|Turkey|Ukraine|Yugoslavia",
"The Caribbean*Please Select|Anguilla|Antigua|Aruba|The Bahamas|Barbados|Barbuda|Bermuda|Bonaire|The British Virgin Islands|The Cayman Islands|Cuba|Curacao|Dominica|The Dominican Republic|Grenada|Guadeloupe|Haiti|Jamaica|Martinique|Montserrat|Puerto Rico|Saba|St. Barthelemy|St. Kitts and Nevis|St. Lucia|St. Martin|St. Vincent and the Grenadines|Tobago|Trinidad|Turks and Caicos|The U.S. Virgin Islands",
"Mexico*Please Select|Acapulco|Aguascalientes|Cabo San Lucas|Cancun|Celaya|Chihuahua|Ciudad Del Carmen|Ciudad Juarez|Ciudad Obregon|Coatzacoalcos|Cozumel|Culiacan|Culiacan Sinaloa|Guadalajara|Guaymas|Hermosillo|Huatulco|Ixtapa-Zihuatanejo|La Paz|Lazaro Cardenas|Leon Guanajuato|Loreto|Los Mochis|Manzanillo|Manzanillo Colima|Matamoros|Mazatlan|Mazatlan-Sin|Merida|Mexicali|Mexico City|Minatitlan|Monterrey|Morelia-Michoacan|Nuevo Laredo|Oaxaca|Playa Del Carmen|Puebla|Puerto Escondido|Puerto Vallarta|Queretaro|Ramos Arizpe-Coah|Salina Cruz|Saltillo-Coahuila|San Jose Del Cabo|San Juan Del Rio|San Luis Potosi|Silao-Guanajuato|Tamaulipas|Tapachula|Tepic|Tijuana|Toluca-Edo|Torreon|Torreon Coahuila|Torres Satelite|Tuxtla Gutierrez|Veracruz|Villahermosa|Zacatecas",
"Central America*Please Select|Belize|Costa Rica|El Salvador|Guatemala|Honduras|Nicaragua|Panama",
"South America*Please Select|Argentina|Brazil|Chile|Columbia|Paraguay|Peru|Uruguay|Venezuela|Costa Rica|Cuba|Dominica|Ecuador|Haiti|Honduras|Mexico|",
"Middle East*Please Select|Bahrain|Iran|Iraq|Israel|Jordan|Kuwait|Lebanon|Oman|Qatar|Saudi Arabia|Syria|United Arab Emirates",
"South Atlantic*Please Select|St Helena|Tristan da Cunha|Gough Island|Inaccessible Island|Bouvetoya|South Georgia|Marion Island|Crozet Islands|Kerguelen|Amsterdam and St Paul|Heard Island"
);
}

createArray();

function updateMenus(what){
    var ctry = what.value;
    var tmp, arr, found
    found = false
    for (c=0; c<info.length; c++){
        tmp = info[c]
        if (tmp.split('*')[0] == ctry){
            arr = tmp.split('*')[1].split('|')
            found = true
            break
        }
    }
    if (found){
        document.getElementById("frm_town").options.length = arr.length;
        for ( var i = 0; i < arr.length; i++ ) {
            document.getElementById("frm_town").options[i].text  = arr[i];
            document.getElementById("frm_town").options[i].value = arr[i];
        }
        document.getElementById("frm_town").selectedIndex=0;
    }
	setState();
}
// end of hiding -->

