// DATE FUNCTIONALITY
function showFutureDate(){

	checkCookieTime();

	var mydate=new Date(parseInt(getCookie("t")));

	// alert(mydate);
	var year=mydate.getYear();

	if (year < 1000){
		year+=1900;
	}

	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();

	if (daym<10){
		daym="0"+daym;
	}

	var days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	document.write("<span class='breadcrumbs'>"+days[day]+" "+months[month]+" "+daym+", "+year+"</span>");
}

// TIMER SETTINGS AND FUNCTIONS

/***** settings *****/
// number of named fields
var numFields=4;

// days 00
var tday=0;
// hours 00
var thour=0;
// minutes 00
var tmin=5;
// seconds 00
var tsec=00;
// error message
var errmsg="Sorry, this offer is no longer available.";
// reset timer?
var resetTimer=false;

// uncomment this line to reset the cookie for testing
// deleteCookie("t");

/***** timer variables *****/

var up,down;
var min1,sec1;
var minutesRemaining,secondsRemaining,hoursRemaining,expiretime;
var diff;

daysForTimer=tday*24*60*60*1000;
hoursForTimer=thour*60*60*1000;
minutesForTimer=tmin*60*1000;
secondsForTimer=tsec*1000;

timerLength=daysForTimer + hoursForTimer + minutesForTimer + secondsForTimer;

/***** functions *****/

function checkCookieTime(){
	if (IsCookieNotPresent()) {
		SetCookieTimeout();
	}

	if(IsCookiePresent()) {
		cookietime=getCookie("t");
		timenow=new Date();
		tn=timenow.getTime();
		diff=cookietime-tn;

		if(diff<=0) {
			hoursRemaining=0;
			minutesRemaining=0;
			secondsRemaining=0;
		}
		else {
			hoursRemaining=Math.floor(diff/1000/60/60);
			diff=diff-(hoursRemaining*1000*60*60);
			minutesRemaining=Math.floor(diff/1000/60);
			diff=diff-(minutesRemaining*1000*60);
			secondsRemaining=Math.floor(diff/1000);
		}
	}}

function IsCookieNotPresent() {
	return (getCookie("t")=="" || getCookie("t")==null)
}

function IsCookiePresent() {
	return !IsCookieNotPresent();
}

function SetCookieTimeout() {
	now=new Date();
	expiretime=now.getTime()+timerLength;
	et=new Date();
	cookieexpire=et.getTime()+365*60*60*1000;
	ce=new Date(cookieexpire);
	setCookie("t", expiretime,ce);
}

function Display(min, sec){
	var disp;

	// disp = "" + hour + " " + DisplayName(hour, "hour") + " ";
	disp = min + " " + DisplayName(min, "minute")  + " ";
	disp+= sec + " " + DisplayName(sec, "second");

	return(disp);
}

function DisplayName(timeValue, timeString) {
	return DoNotAddS(timeValue) ? timeString : timeString + "s";
}

function DoNotAddS(timeValue) {
	return (timeValue==0) || (timeValue==1);
}

function CountDown(){
	checkCookieTime();

	// displayValue=Display(hoursRemaining, minutesRemaining, secondsRemaining)+" remaining.";
	displayValue=Display(minutesRemaining, secondsRemaining)+" remaining.";

	//for(t=1;t<numFields+1;t++) {
	//	document.getElementById('display'+t).innerHTML=displayValue;
	//}

	document.getElementById("display1").innerHTML=displayValue;
	// document.getElementById("display2").innerHTML=displayValue;
	
	
	if((minutesRemaining==0)&&(secondsRemaining==0)&&(hoursRemaining==0)) {
		if(errmsg) {
			flag=2;
			alert(errmsg);
		}

		if(resetTimer==true){
			SetCookieTimeout();
			down=setTimeout("CountDown()",1000);
		 }
	}
	else{
		down=setTimeout("CountDown()",1000);
	}
}

// MISC FUNCTIONS

function popUpWindow(URLStr, width, height,windowName){
	x = (screen.width - width)/2;
	y = (screen.height - height)/2;
	var settings='toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+x+', top='+y+',screenX='+x+',screenY='+y;
	window.open(URLStr, windowName, settings);
}
function remote(url){
	window.opener.location=url
	window.close();
}
function bookit(){
	if (document.all && parseInt(navigator.appVersion) >= 4) {
	  var url=document.location.toString();
	  var title=document.title;
	  window.external.AddFavorite(url,title);
	} else {
	  if(navigator.appName == "Netscape"){
	  	alert("You must press ^D (CTRL-D) to bookmark this page");
	  }
	}
}
function winPrint(){
	if (window.print){
		window.print();
	}
	else{
		alert("Your Web Browser DOES NOT support this print method. Close this window and select File>Print from your Menus.");
	}
}

// COOKIE FUNCTIONS

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

// VALIDATION
// note!  these functions have been modified to add a function to check 2 email fields against one another

function FDK_StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function FDK_AddToValidateArray(FormName,FormElement,Validation,SetFocus)
{
    var TheRoot=eval("document."+FormName);
 
    if (!TheRoot.ValidateForm) 
    {
        TheRoot.ValidateForm = true;
        eval(FormName+"NameArray = new Array()")
        eval(FormName+"ValidationArray = new Array()")
        eval(FormName+"FocusArray = new Array()")
    }
    var ArrayIndex = eval(FormName+"NameArray.length");
    eval(FormName+"NameArray[ArrayIndex] = FormElement");
    eval(FormName+"ValidationArray[ArrayIndex] = Validation");
    eval(FormName+"FocusArray[ArrayIndex] = SetFocus");
 
}

function FDK_ValidateNonBlank(FormElement,ErrorMsg)
{
  var msg = ErrorMsg;
  var val = FormElement.value;  

  if (!(FDK_StripChars(" \n\t\r",val).length == 0))
  {
     msg="";
  }

  return msg;
}

function FDK_AddNonBlankValidation(FormName,FormElementName,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateNonBlank("+FormElementName+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

function FDK_ValidateEmail(FormElement,Required,ErrorMsg)
{
   var msg = "";
   var val = FormElement.value;
   var msgInvalid = ErrorMsg;

   var theLen = FDK_StripChars(" ",val).length
   if (theLen == 0)	     {
     if (!Required) return "";
     else return msgInvalid;
   }

   if (val.indexOf("@",0) < 0 || val.indexOf(".")<0) 
   {
      msg = msgInvalid;
   }
   return msg;
}

function FDK_AddEmailValidation(FormName,FormElementName,Required,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateEmail("+FormElementName+","+Required+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

var flag=0;
function FDK_Validate(FormName, stopOnFailure, AutoSubmit, ErrorHeader)
{
 var theFormName = FormName;
 var theElementName = "";
 if (theFormName.indexOf(".")>=0)  
 {
   theElementName = theFormName.substring(theFormName.indexOf(".")+1)
   theFormName = theFormName.substring(0,theFormName.indexOf("."))
 }
 var ValidationCheck = eval("document."+theFormName+".ValidateForm")
 if (ValidationCheck)  
 {
  var theNameArray = eval(theFormName+"NameArray")
  var theValidationArray = eval(theFormName+"ValidationArray")
  var theFocusArray = eval(theFormName+"FocusArray")
  var ErrorMsg = "";
  var FocusSet = false;
  var i;
  var msg;
 
        // Go through the Validate Array that may or may not exist
        // and call the Validate function for all elements that have one.
  if (String(theNameArray)!="undefined")
  {
   for (i = 0; i < theNameArray.length; i ++)
   {
    msg="";
    if (theNameArray[i].name == theElementName || theElementName == "")
    {
      msg = eval(theValidationArray[i]);
    }
    if (msg != "")
    {
     ErrorMsg += "\n"+msg;                   
     if (stopOnFailure == "1") 
     {
       if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
      alert(ErrorHeader+ErrorMsg);
      document.MM_returnValue = false; 
      break;
     }
     else  
     {
      if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
     }
    }
   }
  }
  if (ErrorMsg!="" && stopOnFailure != "1") 
  {
	if(flag==1){
  	ErrorMsg+="The email fields do not match";
  }
  if(flag==2){
	ErrorMsg=errmsg;
  }
   alert(ErrorHeader+ErrorMsg);
  }
  document.MM_returnValue = (ErrorMsg==""); 
  if (document.MM_returnValue && AutoSubmit)  
  {
   eval("document."+FormName+".submit()")
  }
 }
}
function checkEmail(){
	if(document.send.pemail.value!=document.send.cemail.value){flag=1;}
}
// if(document.location.href.indexOf("index.php")!=-1){
	//alert(getCookie('aid'));
//}
