
function $(v) { if (document.getElementById(v)) { return(document.getElementById(v)); } else {return ""}  }
function $S(v) { if (document.getElementById(v)) { return($(v).style); } else { return ""} }

function howManyChecked()
{
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
			if (cnt>1)
			{
				document.editlead.elements[i].checked=false;
			}
		}
		
	}
	if (cnt>1)
	{
		alert('Only check one disposition!');
	}
}


function howManyCheckedCoast()
{
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
			if (cnt>1)
			{
				document.editlead.elements[i].checked=false;
			}
		}
		
	}
	if (cnt>1)
	{
		alert('Only check one disposition!');
	}
	
	if (document.getElementById("1137").checked==true || document.getElementById("6").checked==true)	
	{
		if(document.getElementById("1382").value=='')
		{
			alert('Select Loan type!');	
		}
	}
	
	if (document.getElementById("AltPhone").value==''){	
		alert('Enter Phone Number!');	
	}	
	
	
}


function checkOne()
{
	needToConfirm = false	
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
		}
		
	}
	
	if (document.getElementById("datCallBack").value!=''){
		cnt=cnt+1;			
	}
	
	if (cnt==0)
	{
		alert('Please check a disposition!');
	}
	else
	{
		editlead.submit()
	}
}


function checkOnePause()
{
	needToConfirm = false	
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
		}
		
	}
	
	if (document.getElementById("datCallBack").value!=''){
		cnt=cnt+1;			
	}
	if (cnt==0)
	{
		alert('Please check a disposition!');
	}
	else
	{
		editlead.submit()
		location.href='/shpdialer.asp?nocall=3';
	}
}


function checkOneTransfer()
{
	needToConfirm = false	
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
		}
		
	}
	if (document.getElementById("datCallBack").value!=''){
		cnt=cnt+1;			
	}
	if (cnt==0)
	{
		alert('Please check a disposition!');
	}
	else
	{
		editlead.submit()
		location.href='/shpdialer.asp?nocall=5';
	}
}

  function changeclosesim(idp,idoption) {
   props=window.open('/changeclosesim.asp?idp='+idp+'&idoption='+idoption+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=250, height=200, left = 400, top = 109');
  }

function checkOneEnd()
{
	needToConfirm = false	
	var cnt=0;
	for(i=0; i<document.editlead.elements.length; i++)
	{
		if(document.editlead.elements[i].type=="checkbox")
		{
			if (document.editlead.elements[i].checked==true)
			{
				cnt=cnt+1;			
			}			
		}
		
	}
	if (document.getElementById("datCallBack").value!=''){
		cnt=cnt+1;			
	}
	
	if (cnt==0)
	{
		alert('Please check a disposition!');
	}
	else
	{
		editlead.submit()
		location.href='/shpdialer.asp?nocall=4';
	}
}

function validateForm(){

var okSoFar =true
var errorMessage=""


 if (Right(document.frmUpload.File.value,3)!="csv" && Right(document.frmUpload.File.value,3)!="CSV") {
    okSoFar=false
    errorMessage = "Input File must be CSV!"
    document.frmUpload.File.focus()
  }
if (okSoFar==true) {
    document.frmUpload.submit()
   }
  else 
   alert(errorMessage)
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

  //creates new window; if no w and h sent, then these defaults are used
  function popup(fname,w,h){
  	if (!(w)) w=450; if (!(h)) h=220; 
  	window.open(fname, 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width='+w+', height='+h+', left = 300, top = 109');
  }

  function callsourcedetails(leadid) {
   props=window.open('callsourcedetails.asp?leadid='+leadid+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=500, height=350, left = 400, top = 109');
  }
  
  function userlog(idUser) {
   props=window.open('userlog.asp?idUser='+idUser+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=350, height=350, left = 400, top = 109');
  }
  function sendEmail(LeadID,idlettertype) {
   props=window.open('sendEmail_29.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=350, height=400, left = 400, top = 109');
  }
  function emailApprovedReport() {
   props=window.open('sendApprovedReport.asp', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=350, height=200, left = 200, top = 109');
  }

  function replaceImagefile(idAppraiser,filetypeid) {
   props=window.open('newHLBUFile.asp?idAppraiser='+idAppraiser+'&filetypeid='+filetypeid+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=200, left = 300, top = 109');
  }

  function changeclose(LeadID) {
   props=window.open('/changeclose.asp?LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=250, height=200, left = 400, top = 109');
  }

  function sendEmail_ThinkAd(LeadID,idlettertype,sType) {
   props=window.open('sendEmail_360.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'&sType='+sType+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=600, height=600, left = 400, top = 109');
  }

  function sendEmail_allstate(LeadID,idlettertype) {
   props=window.open('sendEmail_196.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=600, left = 400, top = 109');
  }

  function sendEmail_realty(LeadID,idlettertype) {
   props=window.open('sendEmail_225.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=600, left = 400, top = 109');
  }
    
  function sendEmail_allstateAttach(LeadID,idlettertype) {
   props=window.open('sendEmail_allstateAttach_196.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=600, left = 400, top = 109');
  }

  function newPropertyLead(LeadID,idlettertype) {
   props=window.open('/newPropertyLead.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=500, left = 400, top = 109');
  }  
 function newBuyerLead() {
   props=window.open('/newBuyerLead.asp', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=600, left = 400, top = 109');
  } 
  function newAppraiser() {
   props=window.open('/newAppraiser.asp', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=500, left = 400, top = 109');
  }    
  function blastPropertyLead(LeadID,idlettertype) {
   props=window.open('blastPropertyLead.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=400, left = 400, top = 109');
  }    

  function emailBuyerLeads() {
   props=window.open('/blastBuyerLead.asp', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=400, left = 400, top = 109');
  }    
  
  function sendEmail_98(LeadID,idlettertype) {
   props=window.open('sendEmail_98.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=650, height=700, left = 400, top = 109');
  }

  function openCredit(LeadID,idlettertype,strReportType,number) {
   props=window.open('retreivecredit.asp?strReportType='+strReportType+'&n='+number+'&idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=800, height=1000, left = 400, top = 109');
  }

  function newLeadfile(LeadID,idlettertype) {
   props=window.open('/newLeadFile.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=200, left = 300, top = 109');
  }
  function newlogo(intClientID) {
   props=window.open('newlogo.asp?intClientID='+intClientID+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=150, left = 300, top = 109');
  }
  function leadlog(LeadID,idlettertype) {
   props=window.open('/leadlog.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=350, height=350, left = 400, top = 109');
  }



  function editComment(LeadID,idlettertype,intClientID,idComment) {
   props=window.open('/editcomment.asp?idlettertype='+idlettertype+'&idComment='+idComment+'&intClientID='+intClientID+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=300, left = 300, top = 109');
  }

  function newComment(LeadID,idlettertype,intClientID) {
   props=window.open('newcomment.asp?idlettertype='+idlettertype+'&intClientID='+intClientID+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=300, left = 300, top = 109');
  }


 

  function newQuickComment(LeadID,idlettertype,intClientID) {
   props=window.open('/quickcomment.asp?idlettertype='+idlettertype+'&intClientID='+intClientID+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=300, height=200, left = 300, top = 109');
  }
  
  function managerComment(LeadID,idlettertype,intClientID) {
   props=window.open('managercomments.asp?idlettertype='+idlettertype+'&intClientID='+intClientID+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=500, height=500, left = 300, top = 109');
  }

  function RealtymanagerComment(LeadID,idlettertype,intClientID) {
   props=window.open('RealtymanagerComment.asp?idlettertype='+idlettertype+'&intClientID='+intClientID+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=500, height=500, left = 300, top = 109');
  }
  
  function AppraiserComments(idAppraiser) {
   props=window.open('AppraiserComments.asp?idAppraiser='+idAppraiser+'', 'poppage', 'toolbars=1, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=500, height=500, left = 300, top = 109');
  }  
  
  function addnewfile(idP) {
   props=window.open('newfile.asp?idP='+idP+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=400, height=200, left = 300, top = 109');
  }

  function newLetterType(){
  props=window.open('newLetterType.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=180, left = 300, top = 109');
  }

  function newCategory(){
  props=window.open('newCategory.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=220, left = 300, top = 109');
  }
  
  function newOption(){
  props=window.open('newOption.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=220, left = 300, top = 109');
  }
  
  function newDisposition(){
  props=window.open('newDisposition.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=220, left = 300, top = 109');
  }

  function newNumber(intClientid){
  props=window.open('newnumber.asp?intClientid='+intClientid+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=240, left = 300, top = 109');
  }
  
  function editProcess(idOption){
  props=window.open('editOption.asp?idOption='+idOption+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=240, left = 300, top = 109');
  }
  function newProcess(){
  props=window.open('newOption.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=240, left = 300, top = 109');
  }
  function newBranch(){
  props=window.open('newBranch.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=220, left = 300, top = 109');
  }
  function newHLBUProgram(){
  props=window.open('newHLBURate.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=260, left = 300, top = 109');
  }
  function reassign(LeadID,idlettertype) {
   props=window.open('/reassignlead.asp?idlettertype='+idlettertype+'&LeadID='+LeadID+'', 'poppage', 'toolbars=1, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=350, height=400, left = 400, top = 109');
  }
  function newComm(){
  props=window.open('newComm.asp', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=380, left = 300, top = 109');
  }
  function replaceDoc(idDocument){
  props=window.open('replacedocument.asp?idDocument='+idDocument+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=200, left = 300, top = 109');
  }
  function edtCategory(idCategory){
  props=window.open('editcategory.asp?idCategory='+idCategory+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=220, left = 300, top = 109');
  }


  function newBill(intClientID){
  props=window.open('newBill.asp?intClientID='+intClientID+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=430, left = 300, top = 109');
  }

  function newFaq(idCategory){
  props=window.open('newfaq.asp?idCategory='+idCategory+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=430, left = 300, top = 109');
  }
  function edtfaq(idfaq){
  props=window.open('editfaq.asp?idfaq='+idfaq+'', 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=450, height=430, left = 300, top = 109');
  }

  function faqhelp(idCategory){
  props=window.open('/helpfaq.asp?idCategory='+idCategory+'', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=0, width=480, height=450, left = 300, top = 109');
  }

  function CheckMaxLength(Object, MaxLen)  {
   if(Object.value.length > MaxLen){     
    Object.value = Object.value.substring(0, MaxLen);
   }
  }

function confirmSubmit()
{
var agree=confirm("Are you sure you want to delete this item?");
if (agree)
	return true ;
else
	return false ;
}

// -->



var NS4 = (document.layers);    // Which browser? 
var IE4 = (document.all); 

var win = window;    // window to search. 
var n   = 0; 

function functiondef(str) { 

  var txt, i, found; 

  if (str == "") 
    return false; 

  // Find next occurance of the given string on the page, wrap around to the 
  // start of the page if necessary. 

  if (NS4) { 

    // Look for match starting at the current point. If not found, rewind 
    // back to the first match. 

    if (!win.find(str)) 
      while(win.find(str, false, true)) 
        n++; 
    else 
      n++; 

    // If not found in either direction, give message. 

    if (n == 0) 
      alert("Not found."); 
  } 

  if (IE4) { 
    txt = win.document.body.createTextRange(); 

    // Find the nth match from the top of the page. 

    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { 
      txt.moveStart("character", 1); 
      txt.moveEnd("textedit"); 
    } 

    // If found, mark it and scroll it into view. 

    if (found) { 
      txt.moveStart("character", -1); 
      txt.findText(str); 
      txt.select(); 
      txt.scrollIntoView(); 
      n++; 
    } 

    // Otherwise, start over at the top of the page and find first match. 

    else { 
      if (n > 0) { 
        n = 0; 
        functiondef(str); 
      } 

      // Not found anywhere, give message. 

      else 
        alert("\""+ str +"\" was not found on this page!"); 
    } 
  } 

  return false; 
} 

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

var xmlHttp

function viewer(myurl,str) { 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url=myurl;
	url=url+"?"+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4) { 
		document.getElementById("viewer").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  	// Firefox, Opera 8.0+, Safari
	  	xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
	  	try {
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch (e) {
	    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	return xmlHttp;
}
