var selArray = new Array();

	function openHistory(guid)
	{
		w = window.open('/infoex.net/contacts/history.aspx?entityId=' + guid , 'history_win')
	}
	
function autoFillMarketingRoute(valtofill)
	{
	   for (var i = 1; i <  top.fraRightFrame.document.Form1.primaryEntityEdit_drpMarketingRoute_drpDownId.options.length; i++) 
			{ if(top.fraRightFrame.document.Form1.primaryEntityEdit_drpMarketingRoute_drpDownId.options[i].text == valtofill)
                         top.fraRightFrame.document.Form1.primaryEntityEdit_drpMarketingRoute_drpDownId.selectedIndex = i;
            }
	}
//add zipfield, countyfield, statefield, cityfield
function autoFill(zipfield, countyfield, statefield,marketingfield, cityfield)
{
	var county=document.getElementById(countyfield).value;
	var city=document.getElementById(cityfield).value;
	var state=document.getElementById(statefield).value;
	var zip=document.getElementById(zipfield).value;
	var myFrame=document.getElementById("hdnFrame");
	var cont=false;
	if ((state !='') && (city !=''))
	{
		cont=true;
	}
	if ((county !='') && (city !=''))
	{
		cont=true;
	}
	if ((county !='') && (state !=''))
	{
		cont=true;
	}
	if (zip!='')
	{
		cont=true;
	}
	//if they are all filled in don't auto-fill
	if ((zip!='') && (city!='') && (state!='') && (county!=''))
	{
		cont=false;
	}
	if (cont) {
		var myquerystring="county=" + county + "&city=" + city + "&state=" + state + "&zip=" + zip + "&zipfield=" + zipfield + "&countyfield=" + countyfield + "&statefield=" + statefield + "&cityfield=" + cityfield
		myFrame.src="/infoex.net/autoFill.aspx?" + myquerystring
	}
	//txtCounty
	//txtCity
	//txtState
	//txtZip
	//get the values from these fields
	//set the hdnFrame.src="" with the query string
	//the hidden frame will reload the data.
}


function isEmail(str) {

  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function toUpper(controltext, type)
{
//type=0 - all caps
//type=1 - first letter
	var myBox = document.getElementById(controltext);
	var myText = new String(myBox.value);
	while (myText.charAt(0)==' ')
	{
		myText=myText.substring(1,myText.length);
	}
	
	if (myText.length > 0)
	{
		var newText=new String("");
		var setNext = false;
		if (type==1) {
			for (var i=0; i < myText.length; i++)
			{
				if ((i==0) || (setNext))
				{
					var tmpLetter=myText.charAt(i);
					tmpLetter=tmpLetter.toUpperCase();
					newText=newText + tmpLetter;
					setNext=false;
				}
				else
				{
					if (myText.charAt(i)==' ')
					{
						setNext=true;
					}
					else
					{
						setNext=false;
					}
					newText = newText + myText.charAt(i);
				}
			}
		}
		else {
			//do the whole word
			newText = myText.toUpperCase();
		}
		myBox.value=newText;
	}
	
}
function getInfo(entityId, formButton, dropDownList, hiddenId)
{
	var myDrop=document.getElementById(dropDownList);
	var selectedindex=myDrop.selectedIndex;
	
	window.open("/InfoEx.Net/contacts/contact.aspx?drpdownid="+ dropDownList + "&selectedindex="+ selectedindex + "&entityId=" + entityId + "&formButton=" + formButton + "&hiddenId=" + hiddenId + "", "_blank","location=0,menubar=0,scrollbars=1,resizable=yes,height=525,width=800,top=0,left=0");
	
	//window.open("/InfoEx.Net/GlobalPopup/EditEntity.aspx?selectedindex="+ selectedindex + "&entityId=" + entityId + "&formButton=" + formButton + "&hiddenId=" + hiddenId + "", "editEntity","location=0,menubar=0,scrollbars=1,resizable=yes,height=390,width=600");
}


function openCalendar(currentDate, frmElement)
{
	window.open("/InfoEx.Net/GlobalPopup/DatePicker.aspx?currentDate="+currentDate+"&formElement="+frmElement+"", "wysiwyg", "location=0,menubar=0,resizable=no,height=270,width=480");
}


function findText(finder_textbox, finder_selectbox)
{ 


 finder_selectbox = document.getElementById(finder_selectbox);
 var searchStr = finder_textbox.value;
 var newText='';
	for (var i=0; i < searchStr.length; i++)
	{
		if (searchStr.charAt(i)=='\\')
		{
		}
		else
		{
			newText = newText + searchStr.charAt(i);
		}
	}
searchStr=newText;
 
 var myExp = new RegExp(("" + searchStr), "i");
 var foundResult = false;
 var i=0;
 
 while ((foundResult = false) || (i < finder_selectbox.length))
 {
 
  if( myExp.test(finder_selectbox.options[i].text.substring(0, searchStr.length)))
  {
   finder_selectbox.options[i].selected = true;
   foundResult = true;
   i = finder_selectbox.length + 1; //4000;   //make this the length of the list + 1
  }
  i++;
  
 }
}

function confirm_delete()
{
  if (confirm("Are you sure you want to delete this item?")==true)
    return true;
  else
    return false;
}

function confirm_email()
{
  if (confirm("There are no services assigned to this inspection. Proceed?")==true)
    return true;
  else
    return false;
}

function confirm_change_marketingroute(msg)
{
  if (confirm(msg)==true)
    return true;
  else
    return false;
}
//Window Functions

function openModal(url, windowName, properties)
{
	window.showModalDialog(url, windowName, properties);	
}

function openWindow(url, windowName, properties)
{
	window.open(url, windowName, properties);
}


function checkAll(frmName,chkName)
{
	var allChecks = document.getElementsByTagName("input");
	var arrLen = 0;
	for (var j=0; j < allChecks.length; j++)
		{
			if ((allChecks(j).type == "checkbox") && (allChecks(j).name==chkName)) {
				allChecks(j).checked = eval("document."+frmName+".chkAll.checked");
			}
		}
}



function editAddress(franId)
	{
		var listDels = getCheckBoxes('addressCheck','edit');
		if (listDels == "")
		{
			//nothing to edit
		}
		else
		{
			//loop through selArray, and open a new window
			for (i=0; i < selArray.length; i++)
			{
//				window.open("addressPick.asp?franId="+franId+"&addressId="+selArray[i], "EditAddress"+i, "location=0,menubar=0,scrollbars=1,resizable=yes,height=200,width=585");
			}
		}
	}

	function deleteAddress()
	{
		var listDels = getCheckBoxes('addressCheck', 'delete');
		if (listDels == "")
		{
			//nothing to delete
		}
		else
		{
			//loop through selArray
			document.addressForm.submit();
		}
	}

	

		
		function getCheckBoxes(inName, action)
		{
			selArray = new Array();
			var returnVals = "";
			var alertVals="";
			var allChecks = document.getElementsByTagName("input");
			var arrLen = 0;
			for (var j=0; j < allChecks.length; j++)
			{
				if ((allChecks(j).type == "checkbox") && (allChecks(j).name==inName)) {
					//alert(allChecks(j).id);
					if (allChecks(j).checked) {
						returnVals = returnVals + "," + allChecks(j).value
						alertVals = alertVals + "\n" + allChecks(j).id
						selArray[arrLen] = allChecks(j).value;
						arrLen++;
						
					}
				}
			}
			if (action=="delete")
			{
				if (alertVals != "") 
				{
					if (! confirm("Confirm Deletion of: \n" + alertVals))
					{
						returnVals="";
					}
				}
			}

			return returnVals;				
		}

	function disableMenu(formId, menuId, allVals)
	{
		var myMenutable = document.getElementById('div'+menuId);
		myMenutable.innerHTML="";
	}

	
	function showDoc(formId, menuId, allVals)
	{
//	var myHideT;
//	var myhideM;	
		for (var j=0; j < allVals.length; j++)
			{
//				alert(allVals[j]);
				var myhideT=document.getElementById(allVals[j] + 'Table');
				myhideT.className="hide";
				var myhideM=document.getElementById('font'+ allVals[j] + 'Menu');
				myhideM.className="white";
			}

		var myFormtable = document.getElementById(formId);
		myFormtable.className="shown";
		var myMenutable = document.getElementById('font'+menuId);
		myMenutable.className="yellow";
	}
	
	
	function showManageForm(tableId)
	{
		var myhideT = document.getElementById('franDisplay');
		myhideT.className="hide";
		myhideT = document.getElementById('franEdit');
		myhideT.className="hide";

		var myFormtable = document.getElementById(tableId);
		myFormtable.className="shown";

	}

	function expandImages(tableId)
	{
		var myFormtable = document.getElementById(tableId);
		if (myFormtable.className == "shown")
		{
			myFormtable.className="hide";
		}
		else {
			myFormtable.className="shown";		
		}
	}