// declare vars
var currentRow; 
var lastRow; 
var currentRowIndexName; 
var lastRowIndexName; 
var actualCurrentRow; 
var actualLastRow; 
var rowType; 
var contentId; 
var mainFrame;
var memory;
var leftFrameSrc;
var agt=navigator.userAgent.toLowerCase();

function browserIsSafari(){
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)){
		return true;
	}else{
		return false;
	}
}

function browserIsGecko(){
	if (agt.indexOf('gecko') > -1 && agt.indexOf('safari') == -1){
		return true;
	}else{
		return false;
	}
}

function browserIsExplorer(){
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)){
		return true;
	}else{
		return false;
	}
}


// function that selects rows in photo browser

function selectRow(currentRow, lastRow, rowType, contentId, memory){

  if(!lastRow || lastRow == '' || lastRow == currentRow){            // initially selects a row
  
    currentRowIndexName = "row"+currentRow;
    
    actualCurrentRow = document.getElementById(currentRowIndexName); // selects row.
    actualCurrentRow.style.backgroundColor = "#BFBFBF";              // changes background color.
    
    lastRow = currentRow;                                            // sets up which row should be de-selected next time the function is repeated.
    
  }else{                                                             // selects the clicked row and de-selects the old one.
  
    currentRowIndexName = "row"+currentRow;
    lastRowIndexName = "row"+lastRow;
    
    actualCurrentRow = document.getElementById(currentRowIndexName); // selects row.
    actualCurrentRow.style.backgroundColor = "#BFBFBF";              // changes background color.
    
    
    if(!document.getElementById(lastRowIndexName)){
      
      actualLastRow = document.getElementById("extraTd");
    }else{
      actualLastRow = document.getElementById(lastRowIndexName);     // selects row.
    }
    actualLastRow.style.backgroundColor = "#F5F5F5";                 // changes background color.
    
    lastRow = currentRow;                                            // sets up which row should be de-selected next time the function is repeated.
    
  }
  
  // NOTE: due to HIDEOUS error, var name leftFrameSrc actually refers to the RIGHT frame.
  
  if(rowType == "image"){
  
    leftFrameSrc = "browsePhotosMain.php?view="+rowType+"&"+rowType+"="+contentId;
    leftNavSrc = "browsePhotosLeftNav.php?rowSelection="+memory+"&numericRowSelection="+currentRow+"&lastRowSelection="+lastRow+"#goHere";
    topFrameSrc = "browsePhotosTopBar.php?view="+rowType+"&"+rowType+"="+contentId;
    
  } else if(rowType == "album"){
  
    leftFrameSrc = "browsePhotosMain.php?view="+rowType+"&"+rowType+"="+contentId;
    leftNavSrc = "browsePhotosLeftNav.php?rowSelection="+memory+"&numericRowSelection="+currentRow+"&lastRowSelection="+lastRow+"#goHere";
    topFrameSrc = "browsePhotosTopBar.php?view="+rowType+"&"+rowType+"="+contentId;
    
  } else if(rowType == "albumSet"){
  
    leftFrameSrc = "browsePhotosMain.php?view="+rowType+"&"+rowType+"="+memory;
    leftNavSrc = "browsePhotosLeftNav.php?rowSelection="+memory+"&numericRowSelection="+currentRow+"&lastRowSelection="+lastRow+"#goHere";
    topFrameSrc = "browsePhotosTopBar.php?view="+rowType+"&"+rowType+"="+memory;
    
  }
  
  document.forms['rowSelect'].elements['rowSelection'].value = memory;
  document.forms['rowSelect'].elements['numericRowSelection'].value = currentRow;
  document.forms['rowSelect'].elements['lastRowSelection'].value = lastRow;
  
  // document.forms['rowSelect'].submit();                              // sends the old and new selections so they can be written into the html by php and used next time.
  
  window.parent.frames[2].location = leftFrameSrc;                   // tells the display frame to show the selection.
  window.parent.frames[1].location = leftNavSrc;                     // tells the display frame to show the selection.
  window.parent.frames[0].location = topFrameSrc;                    // tells the top frame to show the selection details.
  
}


// function that changes view from the main frame:

var rowSelection;
var numericRowSelection;
var displayWindowView;
var displayType;
var displayId;

function dblClickSelection(rowSelection, numericRowSelection, diplayType, displayId){
  
  displayWindowView = "browsePhotosMain.php?view="+diplayType+"&"+diplayType+"="+displayId;
  displayTopView = "browsePhotosTopBar.php?view="+diplayType+"&"+diplayType+"="+displayId;
  document.forms['setSelection'].elements['rowSelection'].value = rowSelection;
  document.forms['setSelection'].elements['numericRowSelection'].value = numericRowSelection;
  document.forms['setSelection'].submit();
  
  window.parent.frames[2].location = displayWindowView;
  window.parent.frames[0].location = displayTopView;
  
}

// opens or updates the picture information window

var helpObject;

function getSiteHelp(helpObject){

  // alert(photoObject);
  window.open("./siteHelp.php?object="+helpObject,"newWindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=400, height=400");

}

// saves order

function saveCurrentOrder(){

  window.parent.frames[2].location = "./currentOrderBottomBar.php?action=saveOrder";
  window.parent.frames[1].location = "./currentOrderList.php";
  
}

// displays an image at full size in a new window

var iTitle, iName, img_id;

var width = 0;
var height = 0;

function getFullSize(img_id, iTitle, iName, width, height){
  
  // width += 2;
  // height += 2;
  var windowAddress = "/siteApp/run/viewImage.php?img="+iName+"&h="+height+"&w="+width;
  var windowName = "newWindow"+img_id;
  // alert(windowName);
  // window.open(windowAddress, windowName, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=, width=400, height=400");
  // window.open("http://www.w3schools.com","my_new_window","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
  window.open(windowAddress, windowName,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=" + width + ", height=" + height);

}

var section, listAddress;

function changeFinanceView(section){

if(section == "bills"){
  listAddress = "orderBills.php";
}else if(section == "jobInvoices"){
  listAddress = "invoicesList.php?view=invoices";
}else if(section == "jobQuotes"){
  listAddress = "invoicesList.php?view=quotes";
}

  window.parent.frames[0].location = "./invoicesTopBar.php?financeSection="+section;
  window.parent.frames[1].location = "./"+listAddress;
}

var passwordFormShown = "false";

function showPasswordForm(){
	
	// alert("hello");
	var txt = "<form action=\"../oneTouchDisplays/resetPassword.php\" target=\"_parent\" method=\"post\" name=\"retrievePassword\" class=\"noBorder\"> <table id=\"Table_01\" width=\"638\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td class=\"fwareStandardText\"><img src=\"../images/grey_panel_top.gif\" width=\"638\" height=\"10\" alt=\"\"></td></tr><tr> <td class=\"fwareStandardText\" style=\"text-align:center;background-color:#D3D3D9;padding:10px\">This form will reset your password and send the new password to the e-mail address you used to create your account. Your new password will be sent in clear text.</td></tr> <tr> <td width=\"638\" class=\"fwareSmallText\" style=\"background-color:#D3D3D9\"> <div align=\"center\"> <table width=\"400\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" style=\"font-family:arial,helvetica,sans-serif;font-size:12px;color:#666;width:400px\"> <tr> <td style=\"font-family:arial,helvetica,sans-serif;font-size:12px;color:#666;width:150px\">Reset Password For:</td> <td style=\"font-family:arial,helvetica,sans-serif;font-size:10px;color:#666\"><input name=\"resetAcct\" type=\"text\" size=\"24\" maxlength=\"50\" value=\"Enter Your Email Address\" onfocus=\"if(this.value=='Enter Your Email Address'){this.value='';}\" onblur=\"if(this.value==''){this.value='Enter Your Email Address';}\"></td></tr> <tr> <td></td> <td><input type=\"image\" name=\"signUp\" src=\"../images/buttons,submit-greybg.gif\"></td></tr> </table> </div></td></tr> <tr> <td><img src=\"../images/grey_panel_bottom.gif\" width=\"638\" height=\"10\" alt=\"\"></td></tr> </table> </form>";
	// alert(agt);
	if(document.getElementById){ 
		if(browserIsGecko()){
			// alert("getelementbyid exists");
        	// document.getElementById('lostPassword').innerHTML = txt;
        	// alert("is gecko");
        	document.getElementById("iframe").contentDocument.getElementById('lostPassword').innerHTML = txt;
        	passwordFormShown = "true";
        }else{
        	// alert("is not gecko");
        	document.getElementById('lostPassword').innerHTML = txt;
        	passwordFormShown = "true";
        }
	}else{
		alert("no getelementbyid");
	}
	// document.getElementById("lostPassword").innerHTML = "test";
	// return true;
}

function hidePasswordForm(){
	
	// alert("hello");
	var txt = "";
	// alert(agt);
	if(document.getElementById){ 
		if(browserIsGecko()){
			// alert("getelementbyid exists");
        	// document.getElementById('lostPassword').innerHTML = txt;
        	// alert("is gecko");
        	document.getElementById("iframe").contentDocument.getElementById('lostPassword').innerHTML = txt;
        	passwordFormShown = "false";
        }else{
        	// alert("is not gecko");
        	document.getElementById('lostPassword').innerHTML = txt;
        	passwordFormShown = "false";
        }
	}else{
		alert("no getelementbyid");
	}
	// document.getElementById("lostPassword").innerHTML = "test";
	// return true;
}

function togglePasswordForm(){
	if(passwordFormShown == "true"){
		hidePasswordForm();
	}else if(passwordFormShown == "false"){
		showPasswordForm();
	}
}