function trimFileName (input) {
	if (navigator.appVersion.indexOf("Win") != -1) 
		output = input.split('\\');
	else 
		output = input.split('/');
	return output[output.length-1];
}

function updateFileName(p, value) {
	var name = trimFileName(value);
	Element.childElements(p)[2].value = name;
}

function setRegion(name, id) {
	$('region_id').value = id;
	$('region_name').value = name;
	Shadowbox.close();
}

function validate(form) {
	var mailRegex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/gi;
	if (!form['post[email]'].value.match(mailRegex)) {
		alert('The entered email address does not appear to be valid.');
		form['post[email]'].focus();
		return false;
	}

	if (form['post[email]'].value != form['post[email_confirm]'].value) {
		alert('Email fields do not match.');
		form['post[email_confirm]'].focus();
		return false;
	}
	
	if (!form['post[agreement]'].checked) {
		alert('You must agree to the Terms of use before you can submit this classified.');
		form['post[agreement]'].focus();
		return false;
	}
	
	if (extraValidate) return extraValidate(form);
}

function addPhoto() {
	var box = $('photoRow');
	var newBox = box.cloneNode(true);
		newBox.id = '';
		Element.childElements(newBox)[2].value = 'No Image Selected';
		Element.childElements(newBox).last().show();
	box.parentNode.appendChild(newBox);
}

Shadowbox.init({path:'/js/shadowbox/',overlayColor:'#FFFFFF',players: ["img","iframe"], animate:false});

function openRegionPicker () {
    Shadowbox.open({
        player:     'iframe',
        title:      'Select A Region',
        content:    '/create/regionpicker/',
        height:     300,
        width:      280
    });
}
