// JavaScript Document
function confirmBox(url,make,model,year,variant){
	var name=confirm("You are going to delete" + "\n" + year + " " + make + " " + model + " " + variant)
	if (name==true){
		//document.write("You pressed the OK button!")
		window.location = url
	}
}

function multiDelete(){
	var name = confirm("this is going to delete selected cars !!!")
	if (name == true){
		//document.forms[0].submit();
		document.forms["carList"].submit();
	}
	else
	return false;
}

function confirmDeleteModel(id){
	var name = confirm("this will delete this model and all cars under this model")
	if (name == true){
		window.location = 'deletemodel.asp?cid=' + id
	}
	else
	return false;
}

function confirmDeleteMake(id){
	var name = confirm("this will delete this make and all cars under this make.")
	if (name == true){
		window.location = 'deletemake.asp?sid=' + id
	}
	else
	return false;
}

function confirmDelete(url){
	var name=confirm("this is going to delete this car!!!")
	if (name==true){
		//document.write("You pressed the OK button!")
		window.location = url
	}
}

function submitForm(){
	document.forms[0].submit();	
}

function checkLoginForm(){
	var doc = document.forms[0]
	var userLogin = doc.UserLogin
	var userPassword = doc.UserPassword
	var Filter = /^[a-zA-Z0-9_\-\@\.]+$/;
	if (!Filter.test(userLogin.value)){
		alert('Sorry, your login contains invalid charactor(s).');
		userLogin.focus();
		userLogin.select();
		return false;
	}
	
	if (!Filter.test(userPassword.value)){
		alert('Sorry, your password contains invalid charactor(s).');
		userPassword.focus();																											
		return false;
	}
}

function checkUserForm(){
	var doc = document.forms['user']
	var Login = doc.Login
	var Password = doc.Password
	var email = doc.Email
	var URL = doc.Website
	var Filter = /^[a-zA-Z0-9_\-\@\.]+$/;
	var emailFormat  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var idFormat = /^[a-zA-Z0-9]+$/;
	var trademeID = doc.trademeID
	var autoTraderID = doc.autoTraderID
	
	if (!Filter.test(Login.value)){
		alert('Sorry, your login name contains invalid charactor(s).');
		Login.focus();
		Login.select();
		return false;
	}

	if (!Filter.test(Password.value)){
		alert('Sorry, the password contains invalid charactor(s).');
		Password.focus();																											
		return false;
	}
	if (!emailFormat.test(email.value)){
		alert('Sorry, your email address is not correct.');
		email.focus();																											
		return false;
	}
	
	if (trademeID.value != ""){
		if(!idFormat.test(trademeID.value)){
			alert('Sorry, the Trademe ID is not in a right format' + "\n" + 'The ID can only contains letters and numbers');
			return false;
		}
	}
	
}

function checkMakeForm(){
	var doc = document.forms['SiteView']
	var makeName = doc.SiteName
	
	if (makeName.value == ""){
		alert("Sorry, but you will need to enter a make name")
		makeName.focus();
		return false;
	}
}

function checkModelForm(){
	var doc = document.forms['formModel']
	var modelName = doc.modelName
	var makeName = doc.makeName
	
	if (modelName.value == ""){
		alert("Sorry, but you will need to enter a model name")
		modelName.focus();
		return false;
	}
	
	if (makeName.value == ""){
		alert("Sorry, but you will need to choose a make for this model")
		return false;
	}
}

function checkCarForm(){
	var doc = document.forms['ArtView']
	var iMake = doc.artSite
	var iModel = doc.artCategory
	var iDealer = doc.artAddedBy
	var iPrice = doc.ArtPrice
	var iMileAge = doc.ArtMileage
	var iYear = doc.artYear
	var iSeats = doc.seats
	var Filter = /^[0-9,\POA]+$/;
	var seatsFilter = /^[0-9]+$/;
	var yearFilter = /^[0-9]+$/;
	var mileAgeFilter = /^[0-9,]+$/;
	var action = doc.submit
	if (action.value == "delete this car"){
		alert("This is going to delete this")
		return false;
	}
	if (iMake.value == ""){
		alert("Sorry, but you will need to choose a make for this car")
		return false;
	}
	if (iModel.value == ""){
		alert("Sorry, but you will need to choose a model for this car")	
		return false;
	}
	if (!Filter.test(iPrice.value)){
		alert("Sorry, the Car Price can only be a number or 'POA'")
		iPrice.select();
		return false;
	}
	if (iSeats.value != ""){
		if (!seatsFilter.test(iSeats.value)){
			alert("Sorry, the car seats can only be a number between 1 - 9")
			iSeats.select();
			return false;
		}
	}
	if (iMileAge.value != ""){
		if (!mileAgeFilter.test(iMileAge.value)){
			alert("Sorry, the Car mileage can only be a number")
			iMileAge.select();
			return false;
		}
	}
	if (iYear.value == ""){
		alert("Sorry, you will need to choose a year for this car")
		return false;
	}
	if (!yearFilter.test(iYear.value)){
		alert("Sorry, you can only enter number car year")
		return false;
	}
	if (iDealer.value == ""){
		alert("Sorry, you will need to choose a dealer for this car")
		return false;
	}
}

function open_win(url,width,height)
{
window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, dependent=yes, scrollbars=yes, resizable=no, copyhistory=no, width="+width+", height="+height+", left=100, right=100")
}

function jumpMenu(targ,selObj,restore){ //v3.0
	
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function silverCircleSearch(url){
	var doc = document.forms[0]
	var cid = doc.artCategory.value
	var dealerID = doc.dealer.value
	var listType = doc.listType.value
	
	parent.location = url + "?cid=" + cid + "&dealers=" + dealerID + "&type=" + listType
}

function goBack(){
	history.go(-1)
}

function userLevel(){
	var doc = document.user
	if (doc.userType.value == "N"){
		doc.userFolder.disabled = true
		doc.userMember.disabled = false
	}
	if (doc.userType.value == "S" || doc.userType.value == "a"){
		doc.userFolder.disabled = false
		doc.userMember.disabled = true
		doc.userFolder.focus()
	}
	if (doc.userType.value == ""){
		doc.userFolder.disabled = false
		doc.userMember.disabled = false
	}
}

function goURL(url,target){
	window.open(url,target)
}

function goTo(URL){
	window.location = URL	
}

function searchFilter(URL){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = URL + "?sid="+makeID+"&cid="+modelID
}

function searchMB(URL){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	list = document.getElementById("listType").value
	minYear = document.getElementById("minYear").value
	maxYear = document.getElementById("maxYear").value
	window.location = URL + "?sid="+makeID+"&cid="+modelID+"&list="+list+"&minYear="+minYear+"&maxYear="+maxYear
}

function searchVW(URL){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	//list = document.getElementById("listType").value
	minYear = document.getElementById("minYear").value
	maxYear = document.getElementById("maxYear").value
	window.location = URL + "?sid="+makeID+"&cid="+modelID+"&minYear="+minYear+"&maxYear="+maxYear
}
function searchSilverCircle(URL){
	modelID = document.getElementById("artCategory").value
	minYear = document.getElementById("minYear").value
	maxYear = document.getElementById("maxYear").value
	ilocation = document.getElementById("dealerLocation").value
	window.location = URL + "?model="+modelID+"&minYear="+minYear+"&maxYear="+maxYear+"&location="+ilocation
}
function goFilter(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "admin.asp?sid="+makeID+"&cid="+modelID
}

function goFilterFrontend(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "default.asp?sid="+makeID+"&cid="+modelID
}

function goFilterThumb(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "allthumb.asp?sid="+makeID+"&cid="+modelID
}

function goMbFilterThumb(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "mbthumb.asp?sid="+makeID+"&cid="+modelID
}

function goFilterGallery(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "allgalleryview.asp?sid="+makeID+"&cid="+modelID
}
function goFilter_a(URL){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = URL+"?sid="+makeID+"&cid="+modelID
}
function goFilter_b(URL,dealers){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = URL+"?sid="+makeID+"&cid="+modelID+"&dealers="+dealers
}

function goMbFilterGallery(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "mbgallery.asp?sid="+makeID+"&cid="+modelID
}
function goMbFilterDefault(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "default.asp?sid="+makeID+"&cid="+modelID
}
function printFilter(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.location = "advantageprint.asp?sid="+makeID+"&cid="+modelID
}

function checkAll(){
	var doc = document.forms['carList']
	checkBoxArr = doc.IDs
	if (doc.selectAll.checked == true){
		for (i = 0; i < checkBoxArr.length; i++) {
			checkBoxArr[i].checked = true;
		}
	}
	else {
		for (i = 0; i < checkBoxArr.length; i++) {
			checkBoxArr[i].checked = false;
		}
	}
}

function goSearch(){
	words = document.getElementById("keywords").value
	window.location = "searchresult.asp?words=" + words
}

function removeImage(imageName,carID,URL){
	var name = confirm("this is going to delete this image !!!")
	if (name == true){
		window.location = "removeoneImage.asp?url=" + URL + "&img=" + imageName	+ "&artID=" + carID
	}
	else
	return false;

}

function moveImageToFirst(imageName,carID){
	window.location = "moveImageToFirst.asp?img=" + imageName + "&artID=" + carID
}

function openPopUp(URL,width,height){
	window.open(URL,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + width + ", height=" + height)
}

function GetImg(ID,img){
	  foto1 = new Image();
	  foto1.src = (img);
	  Controlla(ID,img);
}

function Controlla(ID,img){
	  if((foto1.width!=0)&&(foto1.height!=0)){
		viewFoto(ID,img);
	  }
	  else{
		funzione="Controlla('"+ID+"','"+img+"')";
		intervallo=setTimeout(funzione,20);
	  }
	}

function viewFoto(ID,img){
	  largh=foto1.width+30;
	  altez=foto1.height+30;
	  stringa="width="+largh+",height="+altez;
	  
	  OpenFull(ID,largh,altez);
}
	
function OpenFull(ID,myWidth,myHeight) {
	theURL = "viewImage.asp?image="+ID
	var myLeft = (screen.width-myWidth)/2;
	var myTop = (screen.height-(myHeight+150))/2;
	window.open(theURL,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+myWidth+", height="+myHeight)
}

function closeWindow(){
	window.close();	
}

function transYear(){
	var doc = document.ArtView
	doc.artYear.value = doc.iArtYear.value
}

function transColour(){
	var doc = document.ArtView
	doc.ArtColour.value = doc.iArtColour.value
}

function transTransmission(){
	var doc = document.ArtView
	doc.ArtTransmission.value = doc.iArtTransmission.value
}

function checkEnquiryForm(){
	doc = document.usedCarEnquiry
	var emailFormat  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	email = doc.emailAddress
	name = doc.Name
	phone = doc.ContactNumber
	if (name.value == ""){
		alert('Sorry, you will need to put down your name')
		name.focus();
		return false;
	}
	if (!emailFormat.test(email.value)){
		alert('Sorry, your email address is not correct.');
		email.focus();																											
		return false;
	}
	if (phone.value == ""){
		alert('Sorry, you will need to put down your contact number')
		phone.focus();
		return false;
	}
	
}

function checkPrice(){
	var doc = document.forms["updatePrice"]
	var iPrice = doc.newPrice
	var Filter = /^[0-9,\POA]+$/;
	if (!Filter.test(iPrice.value)){
		alert("Sorry, the Car Price can only be a number or 'POA'")
		iPrice.select();
		return false;
	}
}

function submitPriceForm(){
	var checkStatus
	checkStatus = checkPrice();
	if (checkStatus != false)
	document.forms[0].submit();	
}

function checkMileAge(){
	var doc = document.forms["updateMileAge"]
	var iMileAge =  doc.newMileAge
	var mileAgeFilter = /^[0-9,]+$/;
	if (iMileAge.value != ""){
		if (!mileAgeFilter.test(iMileAge.value)){
			alert("Sorry, the Car mileage can only be a number")
			iMileAge.select();
			return false;
		}
	}
}

function submitMileAgeForm(){
	var checkStatus
	checkStatus = checkMileAge();
	if (checkStatus != false)
	document.forms[0].submit();
}

function cleanBox(id){
	document.getElementById(id).value = ""	
}

function goFilterGalleryFrame(){
	makeID = document.getElementById("artSite").value
	modelID = document.getElementById("artCategory").value
	window.top.location = "allgalleryview.asp?sid="+makeID+"&cid="+modelID
}
