<!---------------Javascript Functions

function popWindow(thisWindow, thisTop, thisLeft, thisWidth, thisHeight)
// Function to open a parsed file name.
{
	window.open(thisWindow, "thisTitle", "toolbar=no,left="+thisLeft+",top="+thisTop+",width="+thisWidth+",height="+thisHeight+",directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
}

function showVehiclePhoto(vehicleInfo)
// Function to pop up a vehicle photo window.
{
	availScreenHeight = screen.availHeight;

	if (availScreenHeight < 1000)
		{		
		window.open("popupwindow.cfm?vehicleID=" + vehicleInfo, "VehiclePhoto", "toolbar=no,left=50,top=0,width=675,height=560,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
		}
	else
		{
		window.open("popupwindow.cfm?vehicleID=" + vehicleInfo, "VehiclePhoto", "toolbar=no,left=50,top=0,width=655,height=560,directories=no,status=no,scrollbars=no,resize=no,menubar=no");	
		}		
}

//-----------------------------------------------------------

function showIndividualVehicleDetails(vehicleInfo)
// Function to pop up a vehicle photo window.
{
	window.open("viewdetailedindividual.cfm?pVehicleID=" + vehicleInfo, "VehicleDetails", "toolbar=no,left=50,top=0,width=600,height=570,directories=no,status=no,scrollbars=no,resize=no,menubar=no");
}

//-----------------------------------------------------------

function showIndividualVehicleDetailsPriceUpdate(vehicleInfo)
// Function to pop up a vehicle photo window.
{
	window.open("Prices/updateIndividualVehiclePrice.cfm?pVehicleID=" + vehicleInfo, "VehicleDetails", "toolbar=no,left=50,top=0,width=600,height=570,directories=no,status=no,scrollbars=no,resize=no,menubar=no");
}

//-----------------------------------------------------------

function editVehicle(vehicleInfo)
// Function to pop up a vehicle photo window.
{
	window.open("editvehicle.cfm?VehicleID=" + vehicleInfo, "VehicleDetails", "toolbar=no,left=50,top=0,width=600,height=570,directories=no,status=no,scrollbars=no,resize=no,menubar=no");
}

//-----------------------------------------------------------

function vehicleDetailEdit(vehicleInfo)
// Function to pop up a vehicle photo window.
{
	window.open("vehicleEditing/vehicleEditing.cfm?VehicleID=" + vehicleInfo, "VehicleDetails", "toolbar=no,left=50,top=0,width=600,height=500,directories=no,status=no,scrollbars=no,resize=no,menubar=no");
}

//-----------------------------------------------------------

function printPage()
// Function to print the current web page.
{
	if (window.print != null)
		{
		window.print();
		}
	else
		{
		alert('Unfortunately, your browser does not support this shortcut.  Please select Print from the File menu.');
		}
}

//-----------------------------------------------------------

function ConfirmCloseSite(Status)
{
	if(confirm("Are you sure you want to "+ Status+ " the user site?"))
		{
			window.location.href="Index.cfm?layout=Open_Close_Main&sublayout=Open_Close_MainAction&OpenStatus=" +Status+""
		}
}
//-----------------------------------------------------------

function check_date(field)
{
	var checkstr = "0123456789";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

   err = 0;
   /* year is wrong if year = 0000 */
   year = openclose.StartYear.value;
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = openclose.StartMonth.value;
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = openclose.StartDay.value;
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "1") || (month == "3") || (month == "5") || (month == "7") || (month == "8") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "4") || (month == "6") || (month == "9") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Sorry, but the date you have selected is invalid.");
   }
}
//-----------------------------------------------------------


function check_date2(field)
{
	var checkstr = "0123456789";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

   err = 0;

   /* year is wrong if year = 0000 */
   year = openclose.EndYear.value;
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = openclose.EndMonth.value;
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = openclose.EndDay.value;
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "1") || (month == "3") || (month == "5") || (month == "7") || (month == "8") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "4") || (month == "6") || (month == "9") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Sorry, but the date you have selected is invalid.");
   }
}
//-----------------------------------------------------------

function check_OpenReportDate(field)
{
	var checkstr = "0123456789";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

   err = 0;

   /* year is wrong if year = 0000 */
   year = salesreport.StartYear.value;
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = salesreport.StartMonth.value;
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = salesreport.StartDay.value;
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Sorry, but the date you have selected is invalid.");
   }
}


//-----------------------------------------------------------

function check_CloseReportDate(field)
{
	var checkstr = "0123456789";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

   err = 0;

   /* year is wrong if year = 0000 */
   year = salesreport.EndYear.value;
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = salesreport.EndMonth.value;
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = salesreport.EndDay.value;
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Sorry, but the date you have selected is invalid.");
   }
}

//-----------------------------------------------------------

function CheckInternalUser(thisCheckBox)
{// Function to manage non-allowance of joint Admin and Super Admin selection,
// and to select 'InternalUser' if 'Admin' or 'SuperAdmin' are selected.
	switch(thisCheckBox.name)
		{
		case "InternalUser":
			{// If Admin or Super are selected, then auto-select 'Internal User'
			if ((document.UserForm.AccessLevel.checked == true) | (document.UserForm.SuperAccessLevel.checked == true))
				document.UserForm.InternalUser.checked = true;
			break;
			}
		
		case "AccessLevel":
			{//Auto-select 'Internal User' if selected and de-select 'Super Admin'
			if (thisCheckBox.checked == true)
				{
				document.UserForm.InternalUser.checked = true;
				document.UserForm.SuperAccessLevel.checked = false;
				}
			break;
			}
		
		case "SuperAccessLevel":
			{//Auto-select 'Internal User' if selected and de-select 'Admin'
			if (thisCheckBox.checked == true)
				{
				document.UserForm.InternalUser.checked = true;
				document.UserForm.AccessLevel.checked = false;
				}
			break;
			}
		}
}

//-----------------------------------------------------------

// Functions created by Fireworks for image roll-over and preloading.
  
function MM_findObj(n, d)
{ //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//-----------------------------------------------------------

function login(){
	window.open('login.cfm', '','status=no,toolbar=no,location=no,resizable=no,scrollbars=no,left=194,top=169,height=180,width=300');
}

function logout(){
	window.open('logout.cfm', '','status=no,toolbar=no,location=no,resizable=no,scrollbars=no,left=220,top=180,height=150,width=300');
}

//-->

//*******************************************	
// Check for a valid email address.
function IsEmailAddr(email)
{  
	if ((email == null) || (email.length == 0))  // Return false if no email address.
		{
		return false;
		}
	else
		{
		var goodEmail = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
		var badEmail = new RegExp(/[\.]+[\.]/);  //ie. two .. in a row.
		
		if (badEmail.test(email))
			return false;
			
		else if (goodEmail.test(email))
			return true;
		}
}
//*******************************************	

