var retdate = "";
var retval = "";


function emailwindow(windowWidth,windowHeight,Email) {

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;

	winName = "EmailWindow";
	title = "Send Email To Customer"
	windowURL = "/customer/emailwindowframeset.html?Email=" + Email;


	retval=window.showModalDialog(windowURL, window, "dialogWidth:"+windowWidth+"px;dialogHeight:"+windowHeight+"px;edge:raised;center:yes;help:no;resizable:no;status:no;");
}


function SendNewsletterButton()
{

	return confirm('Are you sure you want to send the newsletter?');

}

function NewsletterSubscribersList()
{
	var windowURL = "/newsletter/subscribers.aspx";
	var windowOptions = "resizable=no;toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=yes,width=350,height=550" ;
	retval = window.open(windowURL,'NewsletterSubscribersList',windowOptions);
}

function SuppliesSamples()
{
	var windowURL = "/supplies/suppliesSamples.aspx";
	var windowOptions = "resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=yes,width=500,height=350" ;
	retval = window.open(windowURL,'SuppliesSamples',windowOptions);
}

function specialsBrandsEditWindow(selObj)
{
	if (selObj.options[selObj.selectedIndex].value == -1)
	{
		var winName = "SpecialsBrandsWindows";
	
		self.name = "main";
	
		var windowURL = "supplies/brandsframeset.html";
		retNoteID=showModalDialog(windowURL,window,"dialogHeight: 400px; dialogWidth: 250px; edge: raised; center: Yes; help: No; resizable: No; scroll: No; status: No;");
	
		__doPostBack('_ctl2$RefreshButton','');
	}
}

function specialsCategoriesEditWindow(selObj)
{
	if (selObj.options[selObj.selectedIndex].value == -1)
	{
		var winName = "SpecialsCategoriesWindows";
	
		self.name = "main";
	
		var windowURL = "supplies/categoriesframeset.html";
		retNoteID=showModalDialog(windowURL,window,"dialogHeight: 400px; dialogWidth: 250px; edge: raised; center: Yes; help: No; resizable: No; scroll: No; status: No;");
	
		__doPostBack('_ctl2$RefreshButton','');
	}
}

function specialsNotesWindow(windowWidth, windowHeight, noteID, specialID)
{
//	alert('noteID: ' + noteID + '\nspecialID: ' + specialID);

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;
	var winName = "SpecialsNotesWindows";

	self.name = "main";
	
	var windowURL = "supplies/notesframeset.html?NoteID="+noteID+"&SpecialID="+specialID;
	retNoteID=showModalDialog(windowURL,window,"dialogHeight: 425px; dialogWidth: 560px; edge: raised; center: Yes; help: No; resizable: No; scroll: No; status: No;");

//	var windowOptions = "resizable=yes;toolbar=no,location=yes,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=yes,width=" + windowWidth + ",height=" + windowHeight ;


//	retNoteID = window.open(windowURL,winName,windowOptions);

	if (retNoteID != '' && retNoteID != null)
	{
		noteID.value=retNoteID;
	}
	
//	alert(noteID.value);
//	return true;
}

function previewNewsletter(NewsletterID)
{
	var windowURL = "/newsletter/preview.aspx?ID="+NewsletterID;
	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=yes,width=500,height=600" ;
	retval = window.open(windowURL,'previewNewsletter',windowOptions);
}

function newsletterSendWarning()
{
	var windowWidth = 300
	var windowHeight = 150

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;

	var winName = "NewsletterSendWarning";
	var windowURL = "/newsletter/newslettersendwarning.aspx"
	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();

}

function previewSpecial(SpecialID)
{
	var windowURL = "/specials/preview.aspx?ID="+SpecialID
	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=yes,width=500,height=600" ;
	retval = window.open(windowURL,'previewSpecial',windowOptions);
}


function LaunchCalendar(input)
{
	var windowURL = "/customer/calendarframeset.html?Date="+input.value;
	retdate=showModalDialog(windowURL,window,"dialogHeight: 205px; dialogWidth: 237px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");

	if (retdate != '' && retdate != null)
	{
		input.value=retdate;
	}
}

function LaunchSupplyProcess(MachineID)
{

	var windowURL = "/customer/supplyprocess.aspx?MachineID="+MachineID;
	retval=showModalDialog(windowURL,window,"dialogHeight: 283px; dialogWidth: 450px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");

	if (retval != 'cancel')
	{
		parent.machineidsbody.__doPostBack('RefreshButton','')
	}
	else
	{
		return false;
	}
}

function LaunchSupplyProcessVerify(MachineID)
{

	var windowURL = "/customer/supplyprocessverify.aspx?MachineID="+MachineID;
	retval=showModalDialog(windowURL,window,"dialogHeight: 277px; dialogWidth: 450px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");

	if (retval != 'cancel')
	{
		parent.machineidsbody.__doPostBack('RefreshButton','')
	}
	else
	{
		return false;
	}
}

function LaunchSupplyUnProcess(MachineID)
{

	var windowURL = "/customer/supplyunprocess.aspx?MachineID="+MachineID;
	retval=showModalDialog(windowURL,window,"dialogHeight: 237px; dialogWidth: 410px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");

	if (retval != 'cancel')
	{
		parent.machineidsbody.__doPostBack('RefreshButton','')
	}
	else
	{
		return false;
	}
}

function DigitsDashesSlashesDotsOnly(fld,length,e)
{
var strCheck = '0123456789-\\/.';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 7) return true;  // 
if (whichCode == 8) return true;  // 
if (whichCode == 9) return true;  // 
if (whichCode == 10) return true;  // 
if (whichCode == 11) return true;  // 
if (whichCode == 12) return true;  // 
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1)  // Not a valid key
	{
		return false;
	}
	else
	{
		if (fld.value.length == length) return false; else return true;
	}
}

function DigitsOnly(fld,length,e)
{
var strCheck = '0123456789.';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 7) return true;  // 
if (whichCode == 8) return true;  // 
if (whichCode == 9) return true;  // 
if (whichCode == 10) return true;  // 
if (whichCode == 11) return true;  // 
if (whichCode == 12) return true;  // 
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1)  // Not a valid key
	{
		return false;
	}
	else
	{
		if (fld.value.length == length)
		{
			return false;
		}
		else
		{
//			fld.value = fld.value + '$';
			return true;
		}
	}
}
function FormatCurrencyField(fld)
{
	if ((fld.value.indexOf('$') == -1) && ((fld.value.length > 0) && (!fld.value.indexOf('0') == 0)))
	{
		if (fld.value.indexOf('.') == -1)
		{
			fld.value = fld.value + ".00";
		}
		if (fld.value.indexOf('.') == fld.value.length - 2)
		{
			fld.value = fld.value + "0";
		}
		fld.value = '$' + fld.value;
	}
}

function RemoveDollarOnFocus(fld)
{
	if (fld.value.indexOf('$') > -1)
	{
		fld.value = fld.value.replace("$","");
	}
}

function DigitsAndLettersOnly(fld,length,e)
{
	var strCheck = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 7) return true;  // 
	if (whichCode == 8) return true;  // 
	if (whichCode == 9) return true;  // 
	if (whichCode == 10) return true;  // 
	if (whichCode == 11) return true;  // 
	if (whichCode == 12) return true;  // 
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1)  // Not a valid key
		{
			return false;
		}
		else
		{
			if (fld.value.length == length) return false; else return true;
		}
}

function DigitsAndDashesOnly(fld,length,e)
{
var strCheck = '0123456789-';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 7) return true;  // 
if (whichCode == 8) return true;  // 
if (whichCode == 9) return true;  // 
if (whichCode == 10) return true;  // 
if (whichCode == 11) return true;  // 
if (whichCode == 12) return true;  // 
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1)  // Not a valid key
	{
		return false;
	}
	else
	{
		if (fld.value.length == length) return false; else return true;
	}
}

function DigitsAndCommasOnly(fld,length,e)
{
var strCheck = '0123456789,';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 7) return true;  // 
if (whichCode == 8) return true;  // 
if (whichCode == 9) return true;  // 
if (whichCode == 10) return true;  // 
if (whichCode == 11) return true;  // 
if (whichCode == 12) return true;  // 
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1)  // Not a valid key
	{
		return false;
	}
	else
	{
		if (fld.value.length == length) return false; else return true;
	}
}


function machineidswindow(windowWidth,windowHeight,UserID) {

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;

	winName = "machineIDs";
	title = "Machine IDs"
	windowURL = "/customer/machineidsframeset.html?UserID=" + UserID;

	retval=window.showModalDialog(windowURL, window, "dialogWidth:"+windowWidth+"px;dialogHeight:"+windowHeight+"px;edge:raised;center:yes;help:no;resizable:no;status:no;");

//	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
//	retval = window.open(windowURL,winName,windowOptions);

}

function meterlookupwindow() {

	var w = 620;
	var h = 440;

	var windowOptions = "resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=auto,width=" + w + ",height=" + h;

	retval = window.open('/products/meterseriallookup/default.aspx','meterseriallookupwindow',windowOptions);

}

function meterhistory(windowWidth,windowHeight,MachineID) {

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;

	winName = "History";
	windowURL = "/customer/meterhistory.aspx?MachineID=" + MachineID;
	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();
}

function supplyhistory(windowWidth,windowHeight,MachineID) {

	var w = (screen.width)/2-windowWidth/2;
	var h = (screen.height)/2-windowHeight/2;

	winName = "History";
	windowURL = "/customer/supplyhistory.aspx?MachineID=" + MachineID;
	var windowOptions = "resizable=yes;toolbar=no,location=no,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();
}

function helpinfo(windowWidth,windowHeight,helppage) {

	winName = "Help";
	windowURL = "/customer/helpinfo.aspx?" + helppage;
	var windowOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,top=25,left=25,scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();
}

function userinfo(windowWidth,windowHeight,userpage) {
	
	var w = (screen.width-windowWidth)/2;
	var h = (screen.height-windowHeight)/2-200;

	winName = "Popup";
	windowURL = "/forum/userinfo.aspx?" + userpage;
	var windowOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,top=" + h + ",left=" + w + ",scrollbars=no,width=" + windowWidth + ",height=" + windowHeight ;
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();
}

function reminder() {
	
	var w = (screen.width-250)/2;
	var h = (screen.width-150)/2-200;

	winName = "Reminder";
	windowURL = "/forum/passwordreminder.aspx";
	var windowOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0,scrollbars=no,width=350,height=200";
	var mywindow = window.open(windowURL,winName,windowOptions);
	mywindow.focus();
	mywindow.moveTo(w, h);
}

function TryBrowser()
{
	if(String(navigator.appName) == "Netscape" && parseFloat(String(navigator.appVersion)) >= 4 && parseFloat(String(navigator.appVersion)) < 5)
	{
			return confirm('Correct?');
	}
	return true;
}

function stringFormat(fld,e)
{
var strCheck = '0123456789';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 7) return true;  // 
if (whichCode == 8) return true;  // 
if (whichCode == 9) return true;  // 
if (whichCode == 10) return true;  // 
if (whichCode == 11) return true;  // 
if (whichCode == 12) return true;  // 
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1)  // Not a valid key
	{
		return false;
	}
	else
	{
		return true;
	}
}

function MeterSubmitButton(input)
{
	if (input.value.length == 0)
	{
		return false;
	}
		else
	{
		return true;
	}
}

function MachineIDSubmitButton(input1, input2)
{
	if (input1.value.length == 0)
	{
		return false;
	}
		else
	{
		if (input2.SelectedIndex > 1)
		{
			return true;
		}
			else
		{
			return false;
		}
	}
}

function ConfirmMeter(input, oldinput, Username, e)
{
	if (input.value.length == 0) return false;
	if (input == null) return false;
	if (parseInt(oldinput) > parseInt(input.value))
	{
		alert('New meter reading cannot be smaller then previous reading.');
		return false;
	}
	return confirm(Username + '\n\nPlease make sure meter reading [' + input.value + '] is correct.\n\nPress \'OK\' to confirm, \'Cancel\' to go back and correct if necessary.'); 
}

function ConfirmSupply(input)
{
//	alert(input.value);

	if (input.value.length == 0)
	{
		alert("You need to enter your current meter reading for this machine!");
		return false;
	}
	if (input == null) return false;
}

function DropDownMenu(targ,selObj,restore)
{ 
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
     if (restore) selObj.selectedIndex=0;
}

function AddMoreMachinesCheck(AddMoreMachinesTextBox)
{
	if (AddMoreMachinesTextBox.value.length == 0)
	{
		alert('Please enter machine ID first!\nMust be 5 to 9 characters long.        ');
		return false;
	}
	else if (AddMoreMachinesTextBox.value.length < 5 || AddMoreMachinesTextBox.value.length > 9)
	{
		alert('Machine ID must be 5 to 9 characters long.        ');
		return false;
	}
	else
	{
		alert('Machine you are about to add will not be visible in your list until Image IV Systems approves it.');
		return true;
	}
}

function launch()
{
}
