// Specify image details
// Path
var path = "images/media/";

// images
var myImage=new Array();

myImage[0] = "slide_images_00.jpg";
myImage[1] = "slide_images_01.jpg";
myImage[2] = "slide_images_02.jpg";
myImage[3] = "slide_images_03.jpg";
myImage[4] = "slide_images_04.jpg";
myImage[5] = "slide_images_05.jpg";

var imgWidth = "479";
var imgHeight = "314";

var speed = 3000;

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

var c=0;
var t;
var timer_is_on=0;
 
function timedCount()
{
	//document.getElementById('txt').value=c;
	blendimage('blenddiv','blendimage','' + path + myImage[c] + '',400)
	c=c+1;
	t=setTimeout("timedCount()", speed);
	if(c == myImage.length){
		c =0;
	}
}

function doSlides()
{
	if (!timer_is_on)
		{
		timer_is_on=1;
		timedCount();
	}
 
}

function preloadImages() {
	
	document.write('<style> .hidden { visibility: hidden; display: none; }</style> <div class="hidden">');
	for(m=0;m<=myImage.length;m++){
		document.write('<img src="' + path + myImage[m] + '" alt="" />');
	}
	document.write('</div>');
	
}

function showSlides(){
	var randomnumber=Math.floor(Math.random()*myImage.length)
	document.write("<div style='background-image: url(" + path + myImage[randomnumber] + "); background-repeat: no-repeat; width: " + imgWidth + "px; height: " + imgHeight + "px;' id='blenddiv'>");
	document.write("<img src='" + path + myImage[randomnumber] + "' style='width: " + imgWidth + "px; height: " + imgHeight + "px; border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; -khtml-opacity: 0; opacity: 0;' id='blendimage' alt='' />");
	document.write("</div>");
}

function showSLO(){
	if(document.getElementById('service_level')){
		if(document.getElementById('service_level').options.selectedIndex == 3){
			document.getElementById('service_level_other').style.visibility = "visible";
		} else {
			document.getElementById('service_level_other').style.visibility = "hidden";
			document.getElementById('service_level_other').value = "";
		}
	}
	
	if(document.getElementById('trip_type')){
		if(document.getElementById('trip_type').options.selectedIndex == 0){
			document.getElementById('trip_type_div').style.visibility = "visible";
		} else {
			document.getElementById('trip_type_div').style.visibility = "hidden";
		}
	}
}

function chTrip(){
	if(document.getElementById('trip_type')){
		if(document.getElementById('trip_type').options.selectedIndex == 0){
			document.getElementById('trip_type_div').style.visibility = "visible";
		} else {
			document.getElementById('trip_type_div').style.visibility = "hidden";
			document.getElementById('mon').checked = false;
			document.getElementById('tue').checked = false;
			document.getElementById('wed').checked = false;
			document.getElementById('thu').checked = false;
			document.getElementById('fri').checked = false;
			document.getElementById('sat').checked = false;
			document.getElementById('sun').checked = false;
	
			document.getElementById('monday').value = "0";
			document.getElementById('tuesday').value = "0";
			document.getElementById('wednesday').value = "0";
			document.getElementById('thursday').value = "0";
			document.getElementById('friday').value = "0";
			document.getElementById('saturday').value = "0";
			document.getElementById('sunday').value = "0";
		}
	}
}

function chSave(){
	if(document.getElementById('remember').checked == true){
		document.getElementById('remember').value = "1";
	} else {
		document.getElementById('remember').value = "0";
	}
}

function chDays(dayn, dayv){
	
	if(document.getElementById(dayn).checked == true){
		document.getElementById(dayv).value = "1";
	} else {
		document.getElementById(dayv).value = "0";
	}
		//alert(dayv + "-" + document.getElementById(dayv).value);
}

// form validation function //
function validate(form) {
  var bill_po = document.getElementById('bill_po').value;
  var bill_name = document.getElementById('bill_name').value;
  var bill_address = document.getElementById('bill_address').value;
  var bill_city = document.getElementById('bill_city').value;
  var bill_zip = document.getElementById('bill_zip').value;
  var bill_phone = document.getElementById('bill_phone').value;
  var bill_cost = document.getElementById('bill_cost').value;
  var pickup_client = document.getElementById('pickup_client').value;
  var pickup_facility = document.getElementById('pickup_facility').value;
  var pickup_phone = document.getElementById('pickup_phone').value;
  var pickup_address = document.getElementById('pickup_address').value;
  var pickup_city = document.getElementById('pickup_city').value;
  var pickup_zip = document.getElementById('pickup_zip').value;
  
  var dest1_doctor = document.getElementById('dest1_doctor').value;
  var dest1_facility = document.getElementById('dest1_facility').value;
  var dest1_phone = document.getElementById('dest1_phone').value;
  var dest1_address = document.getElementById('dest1_address').value;
  var dest1_city = document.getElementById('dest1_city').value;
  var dest1_zip = document.getElementById('dest1_zip').value;
  
  var bill_po_Regex = /^[0-9]*$/;
  var bill_name_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var bill_city_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var bill_zip_Regex = /^[0-9]*$/;
  var bill_phone_Regex = /^[0-9]*$/;
  var bill_cost_Regex = /^(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/;
  var pickup_client_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var pickup_facility_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var pickup_phone_Regex = /^[0-9]*$/;
  var pickup_city_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var pickup_zip_Regex = /^[0-9]*$/;
  
  var dest1_doctor_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var dest1_facility_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var dest1_phone_Regex = /^[0-9]*$/;
  var dest1_city_Regex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var dest1_zip_Regex = /^[0-9]*$/;
  
  if(bill_po == "") { inlineMsg('bill_po','You must enter a Billing PO#.',5); return false; }
  if(!bill_po.match(bill_po_Regex)) { inlineMsg('bill_po','You have entered an invalid PO#,<br>Only numbers are allowed.',5); return false; }
  if(bill_name == "") { inlineMsg('bill_name','You must enter your name.',5); return false; }
  if(!bill_name.match(bill_name_Regex)) { inlineMsg('bill_name','You have entered an invalid name.<br>Invalid characters found.',5); return false; }
  if(bill_address == "") { inlineMsg('bill_address','You must enter your address.',5); return false; }
  if(bill_city == "") { inlineMsg('bill_city','You must enter a city.',5); return false; }
  if(!bill_city.match(bill_city_Regex)) { inlineMsg('bill_city','You have entered an invalid city.<br>Invalid characters found.',5); return false; }
  if(bill_zip == "") { inlineMsg('bill_zip','You must enter your zip code.',5); return false; }
  if(!bill_zip.match(bill_zip_Regex)) { inlineMsg('bill_zip','You have entered an invalid zip code,<br>Only numbers are allowed.',5); return false; }
  if(bill_phone == "") { inlineMsg('bill_phone','You must enter your phone number.',5); return false; }
  if(!bill_phone.match(bill_phone_Regex)) { inlineMsg('bill_phone','You have entered an invalid phone number, Only numbers are allowed.',5); return false; }
  if(!bill_cost.match(bill_cost_Regex)) { inlineMsg('bill_cost','You have entered an invalid cost, Only numbers, commas and periods are allowed.',5); return false; }
  
  if(pickup_client == "") { inlineMsg('pickup_client','You must enter a client name.',5); return false; }
  if(!pickup_client.match(pickup_client_Regex)) { inlineMsg('pickup_client','You have entered an invalid name.<br>Invalid characters found.',5); return false; }
  if(pickup_facility == "") { inlineMsg('pickup_facility','You must enter a facility name.',5); return false; }
  if(!pickup_facility.match(pickup_facility_Regex)) { inlineMsg('pickup_facility','You have entered an invalid facility name.<br>Invalid characters found.',5); return false; }
  if(pickup_phone == "") { inlineMsg('pickup_phone','You must enter a phone number.',5); return false; }
  if(!pickup_phone.match(pickup_phone_Regex)) { inlineMsg('pickup_phone','You have entered an invalid phone number, Only numbers are allowed.',5); return false; }
  if(pickup_address == "") { inlineMsg('pickup_address','You must enter an address.',5); return false; }
  if(pickup_city == "") { inlineMsg('pickup_city','You must enter a city.',5); return false; }
  if(!pickup_city.match(pickup_city_Regex)) { inlineMsg('pickup_city','You have entered an invalid city.<br>Invalid characters found.',5); return false; }
  if(pickup_zip == "") { inlineMsg('pickup_zip','You must enter a zip code.',5); return false; }
  
  if(dest1_doctor == "") { inlineMsg('dest1_doctor','You must enter a doctor name.',5); return false; }
  if(!dest1_doctor.match(dest1_doctor_Regex)) { inlineMsg('dest1_doctor','You have entered an invalid name.<br>Invalid characters found.',5); return false; }
  if(dest1_facility == "") { inlineMsg('dest1_facility','You must enter a facility name.',5); return false; }
  if(!dest1_facility.match(dest1_facility_Regex)) { inlineMsg('dest1_facility','You have entered an invalid facility name.<br>Invalid characters found.',5); return false; }
  if(dest1_phone == "") { inlineMsg('dest1_phone','You must enter a phone number.',5); return false; }
  if(!dest1_phone.match(dest1_phone_Regex)) { inlineMsg('dest1_phone','You have entered an invalid phone number, Only numbers are allowed.',5); return false; }
  if(dest1_address == "") { inlineMsg('dest1_address','You must enter an address.',5); return false; }
  if(dest1_city == "") { inlineMsg('dest1_city','You must enter a city.',5); return false; }
  if(!dest1_city.match(dest1_city_Regex)) { inlineMsg('dest1_city','You have entered an invalid city.<br>Invalid characters found.',5); return false; }
  if(dest1_zip == "") { inlineMsg('dest1_zip','You must enter a zip code.',5); return false; }


  
  //var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  //var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
 /*
  
  if(email == "") {
    inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
    return false;
  }
  if(gender == "") {
    inlineMsg('gender','<strong>Error</strong><br />You must select your gender.',2);
    return false;
  }
  if(message == "") {
    inlineMsg('message','You must enter a message.');
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('message','You have entered an invalid message.');
    return false;
  }
  */
  return true;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 20;
var MSGOFFSET = 3;
var MSGHIDE = 30;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}
