﻿function ResizeImage(imgId,percentage) 
{  
		
	var img = document.getElementById(imgId);
	if (img == undefined || img == null) 
	{	
			alert("null pointer");
			return false;
	}	
	var window_height = document.body.clientHeight;
	var window_width  = document.body.clientWidth;
	var image_width = (window_width/100) * percentage;
	var image_height = (img.offsetHeight/img.offsetWidth) * image_width;
	img.width  = image_width;
	img.height = image_height;
}

function OpenSizedKiosk(strUrl,nWidth,nHeight)
{
	window.open(strUrl,'popup','width=' + nWidth + ',height=' +  nHeight + ',' +
	'directories=false,location=false,menubar=false,resizable=false,scrollbars=' + 
	'auto,status=false,toolbar=false');
}
function OpenKiosk(strUrl)
{
	OpenSizedKiosk(strUrl,640,640);
}
function confirmSubmit(strPrompt)
{
	var agree=confirm(strPrompt);
	if (agree)
		return true ;
	else
		return false ;
}
function FormatPhoneNumbers(num)
{
	//TESTLENGTH:"0123456789012345678901234567890123456789012345"
	var	format = "(###) ###-####, (###) ###-####, (###) ###-####";			// Telephone w/ Area Code
	var shortformat = "";

	var validchars = "0123456789";
	var tempstring = "";
	var returnstring = "";
	var extension = "";
	var tempstringpointer = 0;
	var returnstringpointer = 0;
	count = 0;
	// Get the length so we can go through and remove all non-numeric characters
	var length = num.value.length;
	// We are only concerned with the format of the phone number - extensions can be left alone.
	if (length > format.length)
	{
		length = format.length;
	};
	// scroll through what the user has typed
	for (var x=0; x<length; x++)
	{
		if (validchars.indexOf(num.value.charAt(x))!=-1)
		{
			tempstring = tempstring + num.value.charAt(x);
		};
	};
	// We should now have just the #'s - extract the extension if needed
	if (num.value.length > format.length)
	{
		length = format.length;
		extension = num.value.substr(format.length, (num.value.length-format.length));
	};

	// if we have fewer characters than our short format, we'll default to the short version.
	for (x=0; x<shortformat.length;x++)
	{
		if (shortformat.substr(x, 1)=="#")
		{
			count++;
		};
	}
	if (tempstring.length <= count)
	{
		format = shortformat;
	};

	//Loop through the format string and insert the numbers where we find a # sign
	for (x=0; x<format.length;x++)
	{
		if (tempstringpointer <= tempstring.length)
		{
			if (format.substr(x, 1)=="#")
			{
				returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
				tempstringpointer++;
			}else{
				returnstring = returnstring + format.substr(x, 1);
			}
		}

	}

	// We have gone through the entire format, let's add the extension back on.
	returnstring = returnstring + extension;

	//we're done - let's return our value to the field.
	num.value = returnstring;
}
function GetDay(intDay)
{
	var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                     "Thursday", "Friday", "Saturday");
	return DayArray[intDay];
}

function GetMonth(intMonth)
{
	var MonthArray = new Array("January", "February", "March",
                           "April", "May", "June",
                           "July", "August", "September",
                           "October", "November", "December");
	return MonthArray[intMonth];
}

function getDateStrWithDOW()
{
	var TimezoneOffset = -6;
  var localTime = new Date();
  var ms = localTime.getTime() 
             + (localTime.getTimezoneOffset() * 60000)
             + TimezoneOffset * 3600000;  
	var today = new Date(ms);
	var year = today.getYear();
	if(year<1000)
	{ 
		year+=1900;
	}
	var todayStr = GetDay(today.getDay()) + ", ";
	todayStr += GetMonth(today.getMonth()) + " " + today.getDate();
	todayStr += ", " + year;
	return todayStr;
}

function getTime12()
{
	var TimezoneOffset = -6;
  var localTime = new Date();
  var ms = localTime.getTime() 
             + (localTime.getTimezoneOffset() * 60000)
             + TimezoneOffset * 3600000;
  var curDateTime = new Date(ms);
  var curHour = curDateTime.getHours();
  var curMin = curDateTime.getMinutes();
  var curSec = curDateTime.getSeconds();
  var curAMPM = " AM";
  var curTime = "";
  if (curHour >= 12)
  {
    curHour -= 12;
    curAMPM = " PM";
  }
  if (curHour == 0) 
  {
  	curHour = 12;
  }
  curTime = curHour + ":"
    + ((curMin < 10) ? "0" : "") + curMin + ":" 
    + ((curSec < 10) ? "0" : "") + curSec 
    + curAMPM;
  return curTime;
}

function getTime24()
{
	var TimezoneOffset = -6;
  var localTime = new Date();
  var ms = localTime.getTime() 
             + (localTime.getTimezoneOffset() * 60000)
             + TimezoneOffset * 3600000;
  var curDateTime = new Date(ms);
  var curHour = curDateTime.getHours();
  var curMin = curDateTime.getMinutes();
  var curSec = curDateTime.getSeconds();
  var curTime = 
    ((curHour < 10) ? "0" : "") + curHour + ":" 
    + ((curMin < 10) ? "0" : "") + curMin + ":" 
    + ((curSec < 10) ? "0" : "") + curSec;
  return curTime;
}
