/*function open_win(url, width, height) {
	
	window.open(url,'Diamond Limo Service','width='+width+',height='+height+',toolbar=no,location=no,scrollbars=no,copyhistory=no,resizable=yes');
	
}
*/

function openNewWindow(url, name, features) {
newWindow = window.open(url, name, features);
}

function close_win() {
	window.close();	
}
   
function getPageName() {
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
}
   
function openWin(url,w,h,scroll,resize) {

	var newwindow = "";	
	var leftPos = (screen.width) ? (screen.width-w)/2 : 0;
	var topPos = (screen.height) ? (screen.height-h)/2 : 0;
	
	if (newwindow.location && !newwindow.closed) { 
		newwindow.location.href = url; 
		newwindow.focus(); 
	} 
	else 
	{
		newwindow=window.open(url,'newwin','height=' + h + ',width=' + w + ',top=' + topPos + ',left=' + leftPos +
							  ',resizable=' + resize + ',scrollbars=' + scroll);
	}
}

/* validate email address */
function isValidEmail(str) {
   
   if ( (str.indexOf(".") > 2) && (str.indexOf("@")>0) && (str.indexOf(" ") == -1) ) {
        
   }
   else {
        return false;
   }
   
   return true;
}


/*Reservation page*/

/*show a thumbnail of the car selected*/
function showcar(carListObj) {
	
	var car = carListObj.options[carListObj.selectedIndex].value;
	
	if (car == '') {
	}
	else {
		hideVisible(carListObj);
		
		var carObj = document.getElementById(car);
		
		show(carObj);
	}
	
}

/*shows the description of limos on the quote form on the first page*/
function showLimoDesc(carListObj) {
    var car = carListObj.options[carListObj.selectedIndex].value;
    
    var desc = car.replace(/_/g," ");
    
    var lbl = document.getElementById("lblLimoDesc");
    
    lbl.innerHTML = desc;
    
}

/*hides the visible thumbnail if any */
function hideVisible(carListObj) {
	
	var listLength = carListObj.options.length - 1;
	var i, elem;
	
	for (i = 1; i<=listLength; i++) {
	    elem = document.getElementById(carListObj.options[i].value);
		hide(elem);
	}
}

function hide(elem) {
    elem.className = "hide";
}

function show(elem) {
    elem.className = "show";
}

/*Reset form
formType could be 'reserv' or 'quote'
*/
function resetForm(frmObj,formType) {
    
    var answer = confirm("This will clear all fields in this form. Are you sure?");
    
    if (answer){
        
        if (formType == "reserv") {
            hideVisible(document.getElementById("DropDownListLimoReq"));
        }
        
        frmObj.reset();
    }
    
 
}

/*to validate Reservation form on reservation.aspx*/
function validateResrv(frmObj) {
	
	if (frmObj.txtName.value.length == 0) {
		alert("You must specify the contact name");
		frmObj.txtName.focus();
		return false;
	}
	//either email or phone 1 must be specified
	else if (frmObj.txtEmail.value.length == 0 && frmObj.txtPhone1.value.length == 0) {
		alert("You must specify at least one of email address or phone number");
		frmObj.txtEmail.focus();
		return false;
	}
	else if (frmObj.txtPickupDate.value.length == 0) {
		alert("You must choose a pick-up date");
		frmObj.txtPickupDate.focus();
		return false;
	}
	else if (frmObj.txtPickupStreetNo.value.length == 0) {
		alert("You must specify a street number of the location where to pick you up from");
		frmObj.txtPickupStreetNo.focus();
		return false;
	}
	else if (frmObj.txtPickupStreetName.value.length == 0) {
		alert("You must specify a street name of the location where to pick you up from");
		frmObj.txtPickupStreetName.focus();
		return false;
	}
	else if (frmObj.txtPickupCity.value.length == 0) {
		alert("You must specify a city of the location where to pick you up from");
		frmObj.txtPickupCity.focus();
		return false;
	}
	else if (frmObj.txtDropoffStreetNo.value.length == 0) {
		alert("You must specify a street number of the location where to drop you off");
		frmObj.txtDropoffStreetNo.focus();
		return false;
	}
	else if (frmObj.txtDropoffStreetNo.value.length == 0) {
		alert("You must specify a street name of the location where to drop you off");
		frmObj.txtDropoffStreetNo.focus();
		return false;
	}
	else if (frmObj.txtDropoffCity.value.length == 0) {
		alert("You must specify a city of the location where to drop you off");
		frmObj.txtDropoffCity.focus();
		return false;
	}
	else if (frmObj.DropDownListLimoReq.options[frmObj.DropDownListLimoReq.selectedIndex].value == "-1") {
		alert("You must choose a car from the list of limos");
		frmObj.DropDownListLimoReq.focus();
		return false;
	}
	
	if (!isValidEmail(frmObj.txtEmail.value)) {
        alert("You must specify a valid email address.");
        frmObj.txtEmail.focus();
        return false;
    }
	
	return true;
	
}

function validateQuoteForm(frmObj) {
    
    if (frmObj.txtName.value.length == 0) {
        alert("You must specify your name");
        frmObj.txtName.focus();
        return false;
    }
    else if (frmObj.txtEmail.value.length == 0) {
	    alert("You must specify the email address.");
	    frmObj.txtEmail.focus();
	    return false;
	}
	else if (frmObj.DropDownList_Service.options[frmObj.DropDownList_Service.selectedIndex].value == "-1") {
	    alert("You must choose a service from the list.");
	    frmObj.DropDownList_Service.focus();
	    return false;
	}	
	else if (frmObj.DropDownListLimoReq.options[frmObj.DropDownListLimoReq.selectedIndex].value == "-1") {
	    alert("You must choose a vehicle from the list.");
	    frmObj.DropDownListLimoReq.focus();
	    return false;
	}
	else if(frmObj.DropdownList_startLocation.options[frmObj.DropdownList_startLocation.selectedIndex].value == "Select") {
	    alert("You must specify the location you would like to travel from.");
	    frmObj.DropdownList_startLocation.focus();
	    return false;
    }
    else if(frmObj.DropdownList_endLocation.options[frmObj.DropdownList_endLocation.selectedIndex].value == "Select") {
	    alert("You must specify the location you would like to travel to.");
	    frmObj.DropdownList_endLocation.focus();
	    return false;
    }
	else if(frmObj.txtDate.value.length == 0) {
	    alert("You must specify the date you require our services.");
	    frmObj.txtDate.focus();
	    return false;
    }
    else if (frmObj.txtPhone.value.length == 0) {
        alert("You must specify your contact phone number.");
        frmObj.txtPhone.focus();
        return false;
    }
	
    
    /* validate email */
    if (!isValidEmail(frmObj.txtEmail.value)) {
        alert("You must specify a valid email address.");
        frmObj.txtEmail.focus();
        return false;
    }
    
    return true;
}
