var popUp; 
var leftPos;
var topPos;
var needToChange = true;

//******************** sets alert messages after passing specified time
function showtime() {
	now=new Date();
	hour=now.getHours();
	min=now.getMinutes();
	sec=now.getSeconds();
if (hour<=9) {
	document.getElementById('hours').value = "0"+hour;
	add="am";
 }
 if (hour>9){ 
	document.getElementById('hours').value = hour;	
	add="am";
 }
 if (hour==12) {
	document.getElementById('hours').value = hour;
	add="pm";
 }
if (hour>12) {
	document.getElementById('hours').value = "0"+(hour-12)
	add="pm";
 }  
 document.getElementById('minutes').value = (min<=9) ? "0"+min : min;
 document.getElementById('seconds').value = (sec<=9) ? "0"+sec : sec;
 document.getElementById('ampm').value = add;
 setTimeout("showtime()", 1000);
}
function setalert() {
 alrt1=new Date();
 alerth1=alrt1.getHours();
 alertm1=alrt1.getMinutes();
 alertm1 =alertm1+15;
 
 alrt2=new Date();
 alerth2=alrt2.getHours();
 alertm2=alrt2.getMinutes();
 alertm2 =alertm2+30;
 

 if (alertm1>=60) { alertm1=-(60-alertm1); alerth1=alerth1+1;}
 if (alerth1>=24) { alerth1=-(24-alerth1); }
 
 if (alertm2>=60) { alertm2=-(60-alertm2); alerth2=alerth2+1;}
 if (alerth2>=24) { alerth2=-(24-alerth2); }
}
function alarm1() {
if ((hour == alerth1) && (min == alertm1)) {alert('Stay focused');return false;}
 setTimeout("alarm1()", 1000);}
function alarm2() {
if ((hour == alerth2) && (min == alertm2)) {alert('Wrap it up');return false;}
 setTimeout("alarm2()", 1000);}

//********************

function OpenCalendar(idname, postBack)

{
	popUp = window.open('../Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=225,left=200,top=250');
}

function OpenEmail(email, firstName, lastName)

{

if(screen){

	leftPos = screen.width/2-150;

	topPos = screen.height/2-188;

}

	popUp = window.open('../Email.aspx?email=' + email + '&firstName=' + firstName + '&lastName=' + lastName, 
		'popupemail', 
		'width=300,height=350,left='+leftPos+',top='+topPos);
}

function OpenBlankEmail(email, firstName, lastName)

{

if(screen){

	leftPos = screen.width/2-150;

	topPos = screen.height/2-188;

}

	popUp = window.open('Email.aspx?email=' + email + '&firstName=' + firstName + '&lastName=' + lastName, 
		'popupemail', 
		'width=300,height=350,left='+leftPos+',top='+topPos);
}

function OpenInquirySheet(customerID)
{

if(screen)
{

	leftPos = screen.width/2-600;

	topPos = screen.height/2-300;

}

	popUp = window.open('../Staff/Inquiry.aspx?page=4&index=2&customerID=' + customerID + '&showMenu=false', 
		'popupInquirySheet', 
		'scrollbars=1,width=1200,height=600,left='+leftPos+',top='+topPos);
}

function OpenDirections()
{

if(screen)
{

	leftPos = screen.width/2-175;

	topPos = screen.height/2-200;

}

	popUp = window.open('../Directions.aspx', 
		'popupDirections', 
		'scrollbars=0,width=350,height=400,left='+leftPos+',top='+topPos);
}

function OpenDelete(customerID)
{

if(screen){

	leftPos = screen.width/2-150;

	topPos = screen.height/2-188;

}

	popUp = window.open('../Delete.aspx?customerID=' + customerID, 
		'popupdelete', 
		'width=300, height=350,left='+leftPos+',top='+topPos);
}

//glogal variable to handle only one window opened
var popUpHistory=null;

function OpenHistory(customerID)

{
if(screen){
	leftPos = screen.width/2-350;
	topPos = screen.height/2-250;	
}	
	if(!popUpHistory) {
		popUpHistory = window.open('../Staff/History.aspx?customerID=' + customerID, 
		'popupHistory', 
		'scrollbars=1, width=700, height=500,left='+leftPos+',top='+topPos);
	}
	else if(popUpHistory && popUpHistory.closed)
	{
	popUpHistory = window.open('../Staff/History.aspx?customerID=' + customerID, 
		'popupHistory', 
		'scrollbars=1, width=700, height=500,left='+leftPos+',top='+topPos);
	}
}

var popUpPayment = null;

function OpenPayment(invoiceID)

{

if(screen){
	leftPos = screen.width/2-300;
	topPos = screen.height/2-350;	
}	
	if(!popUpPayment) {
		popUpPayment = window.open('../Partner/PartnerPayment.aspx?inv=' + invoiceID,
		'popUpPayment', 
		'scrollbars=1, width=600, height=700,left='+leftPos+',top='+topPos);
	}
	else if(popUpPayment && popUpPayment.closed)
	{
	popUpPayment = window.open('../Partner/PartnerPayment.aspx?inv=' + invoiceID, 
		'popUpPayment', 
		'scrollbars=1, width=600, height=700,left='+leftPos+',top='+topPos);
	}
}

function SetFocus()

{
	if(needToChange)	
	{	
	self.focus();		
	needToChange=false;	
	}
	__doPostBack("","");
}

function OpenCalculator(path)

{
	if(screen)
	{
		leftPos = screen.width/2-112;
		topPos = (screen.height/2-112)-50;
	}
	
	popUp = window.open(path+'/Calculate.aspx', 
		'popupLoanCalculator', 
		'scrollbars=0, width=225, height=250,left='+leftPos+',top='+topPos);	
}

function OpenScheduler(customerID,appointmentID)
{
id = customerID;
if (id!=undefined)
{
if(screen){

	leftPos = screen.width/2-350;

	topPos = screen.height/2-250;

}

	popUp = window.open('../Scheduler.aspx?customerID=' + customerID + '&appointmentID=' + appointmentID,
		'popupscheduler', 
		'scrollbars=1,width=700,height=500,left='+leftPos+',top='+topPos);
}
}

function OpenStaffScheduler(){
if(screen){

	leftPos = screen.width/2-350;

	topPos = screen.height/2-250;
}
	popUp = window.open('../StaffScheduler.aspx','popupstaffscheduler','scrollbars=1,width=700,height=500,left='+leftPos+',top='+topPos);
}


function CloseWindow()
{
	self.close();
}


function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}

function FinishDelete()
{
		__doPostBack('cmdRefresh','');
		
		popUp.close();
}

function Refresh()
{
		__doPostBack('cmdRefresh','');		
}

function Save()
{
		__doPostBack('cmdSave','');
		return false;
		
}


function ClearBox(box)
{
	if ( box.value == box.defaultValue )
	{
		box.value = "";
	}	
}

function SelectAll(aspCheckBoxID, checkVal)
    
{
	//generated control name starts with a colon
	re = new RegExp(':' + aspCheckBoxID + '$') 

	for(i = 0; i < document.forms[0].elements.length; i++) {

		elm = document.forms[0].elements[i]

		if (elm.type == 'checkbox') {

			if (re.test(elm.name)) {

				elm.checked = checkVal

			}
		}
	}
}

function showHideContent(id, show)
{
    var elem = document.getElementById(id);
    if (elem) 
    {
        if (show) 
        {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
            //sets visibility value into the hidden field 
            document.getElementById('floatVisibility').value = "true";
          
        } 
        else
        {
            elem.style.display = 'block';
            elem.style.visibility = 'hidden';
            //sets visibility value into the hidden field 
            document.getElementById('floatVisibility').value = "false";
        }
    }
} 
function getVisibility(id1,id2)
{
var visible = document.getElementById(id1).value;
var elem = document.getElementById(id2);
if(visible=="true")
{
elem.style.display = 'block';
elem.style.visibility = 'visible';
}
else
{
elem.style.display = 'block';
elem.style.visibility = 'hidden';
}
}

function getPosition(id1,id2)
{
	var elem1 = document.getElementById(id1);
	//var elem = document.getElementById('floatPositionY');
	var elem2 = document.getElementById(id2);
	//var elem = document.getElementById('floatLayer');
	elem2.style.pixelTop = elem1.value;
}

function ToggleDisplay(id)

{

  var elem = document.getElementById('d' + id);
  
  if (elem)   	
	{ 	
		if (elem.style.display != 'block') 
		{
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
		} 
		else
		{						
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
			
		}						
	}	
}

function DoNotToggleDisplay(id)
{
  var elem = document.getElementById('d' + id);
	if (elem) 
	{
		if (elem.style.display != 'block') 
		{
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
		} 
		else
		{
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
		}
	}

}

function ChangeStatus()
{
	var elem = document.getElementById("pnlTrackHistory");
	if (elem.style.display!='none')	
	{
		if(needToChange)
		{
		__doPostBack('','');
		confirm('Please Return Record');
		return false;
		}		
	}		
}

//*************************

function DoPostBack() 
{
if(needToChange)
{
__doPostBack('cmdChangeStatus','');

if(document.getElementById("pnlMain")!=null)
{
 return alert('You are about to return the record to the pool.');
}
}
}
//*************************

function Alert(age)

{
var elem = document.getElementById("ddlCustomerGender");
if (elem.value=="male"&&age<=25)
{
alert('MUST BRING IN $200 IN CASH');
}

// isChanged(input_object)
//   Returns true if input object's value has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj){return(getInputValue(obj)!=getInputDefaultValue(obj));}
}

function setPosition(obj)
{
	if(needToChange)		
	{	
	e = window.event;	
	var elem = document.getElementById(obj).style;
	if (e.pageX || e.pageY) {
        leftPos.x = e.pageX;
        topPos = e.pageY;
    } 
    else 
    {
       leftPos = e.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft;
       topPos = e.clientY + document.documentElement.scrollTop - document.documentElement.clientTop;
    }
		topPos -=10;
		leftPos +=10;
		
		elem.top = topPos + 'px';
		elem.left = leftPos + 'px';
	}
}
//function OpenInvoice(billingUnitID, billingDate)
//{

//if(screen){

	//leftPos = screen.width/2-350;

	//topPos = screen.height/2-250;

//}

	//popUp = window.open('../Invoice.aspx?billingUnitID=' + billingUnitID + '&billingDate=' + billingDate, 
		//'popupinvoice', 
		//'scrollbars=1,width=700,height=500,left='+leftPos+',top='+topPos);
//}

function OpenInvoice(billingUnitID, dateFrom, dateTo)
{

if(screen){
	leftPos = screen.width/2-350;
	topPos = screen.height/2-250;
}

	popUp = window.open('../Invoice.aspx?billingUnitID=' + billingUnitID + '&dateFrom=' + dateFrom + '&dateTo=' + dateTo, 
		'popupinvoice', 
		'scrollbars=1,width=700,height=500,left='+leftPos+',top='+topPos);
}


