function LoadIframe(which)
{	if(document.all)
		{	var currentlocation = which.contentWindow.location.href;
			var currentheight = which.contentWindow.document.body.scrollHeight;	
			var currentwidth = which.contentWindow.document.body.scrollWidth }
	else
		{	var currentlocation = which.contentDocument.location.href;
			var currentheight = which.contentDocument.body.scrollHeight;
			var currentwidth = which.contentDocument.body.scrollWidth;	}
	
		if (currentheight> 20)
		SLIDETO(which,currentheight)
		if (which.getAttribute('LoadIframeWidth')!= null)
		{   
		    which.style.width=currentwidth + 'px'
		}
		
}
//################################################################################################################
function LoadIframeByID(IFrameID)
{	var myiframe = document.getElementById(IFrameID);
    LoadIframe(myiframe);
}
//################################################################################################################
function LoadIframeALL()
{   var ifram=document.getElementsByTagName("iframe");
    for(var i=0;i<ifram.length;i++)
        {LoadIframe(ifram[i])}
}

//################################################################################################################
function SLIDETO(frame,size)
{	frame.height = size;	
}
//################################################################################################################
function ShowHide(which)
{   var item = document.getElementById(which)
    if(item)
       if(item.style.display == '')
            item.style.display = 'none'
       else
            item.style.display = ''        
}
//################################################################################################################
function ExpandCollapse(Obj,Img)
{   ShowHide(Obj);
    var item = document.getElementById(Img)
    if(item)
        if(item.src.indexOf("icn_plus")>0)
            item.src = item.src.replace("icn_plus", "icn_minus");
        else
            item.src = item.src.replace("icn_minus", "icn_plus");  
              
}
ExpandCollapse('PhotosTR','IMGPhotosTR')
//################################################################################################################
var SaveInputDataCounter = 1
function SaveInputData(which)
{   which.className="InputCurrentlySaving"  
    
    var myform=document.createElement("form");
    var TextArea = document.createElement("textarea");
    TextArea.name = "InputData"
    TextArea.style.display = "none";
    myform.appendChild(TextArea);
    document.body.appendChild(myform);
    myform.method = "post"
    myform.target = "SaveInputData_" + SaveInputDataCounter
    
    var iframdiv = document.createElement("DIV");
    iframdiv.innerHTML = "<IFRAME NAME=SaveInputData_" + SaveInputDataCounter + " width=1 height=1></IFRAME>"
    iframdiv.style.visibility = 'hidden';
    document.body.appendChild(iframdiv);
    SaveInputDataCounter++
         
    
    var val = which.value
    if(which.type =='checkbox')
        if(which.checked)
            val = 1;
        else
            val = 0;
    TextArea.value = val;
    myform.action = "DB_SaveInput.asp?Val=" + which.name
    myform.submit();       
}
//################################################################################################################
function DeleteInputData(tbl,Ident,Value)
{   if(ConfirmDelete())
        {
            var ifram = document.createElement("IFRAME");
            ifram.style.width=1;
            ifram.style.height=1;
            ifram.style.visibility = 'hidden';
            ifram.src="DB_DeleteRow.asp?TBL=" + tbl + "&Ident=" + Ident +  "&Value=" + escape(Value);
            document.body.appendChild(ifram);   
        }   
}    
//################################################################################################################
function SavedInputData(InputID)
{   var input = document.getElementById(InputID)
    var inputstatus = document.getElementById("SaveInputStatus_" + InputID)
    if(inputstatus)
        inputstatus.innerText = "Saved"
         
    else
        input.className="InputSaved" 
    
} 
//################################################################################################################
function ConfirmDelete()
{   var r=confirm("Are you sure that you want to delete this?");
    if(r!=true)
    return false
    else
    return true
}
//################################################################################################################
function Pop(SRC,TITLE,HH,WW)
{   if(document.body.offsetHeight <= HH )
        parent.OpenWindow(SRC,TITLE,HH,WW)
    else
        parent.OpenWindow(SRC,TITLE,HH,WW)    
}
//################################################################################################################
function checkdate(input)
{   var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false
    if (!validformat.test(input.value))
    returnval=false
    else{ //Detailed check for valid date ranges
    var monthfield=input.value.split("/")[0]
    var dayfield=input.value.split("/")[1]
    var yearfield=input.value.split("/")[2]
    var dayobj = new Date(yearfield, monthfield-1, dayfield)
    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
    returnval=false
    else
    returnval=true
    }
    return returnval
}
//################################################################################################################

function CheckTimeParts(Input)
{ var obj= document.getElementById(Input);
  var D = document.getElementById(Input + 'D1');
  var t1 = document.getElementById(Input + 'DT1');
  var t2 = document.getElementById(Input + 'DT2');
  var t3 = document.getElementById(Input + 'DT3');
  var err = document.getElementById(Input + 'DTmessage');
  err.innerHTML = '';
  var Dtext = '';
  var Ttext = '';
  if(D)
  {
    if(checkdate(D))
    { Dtext = D.value;}
    else
    {err.innerHTML = "<font color=red size=-2>Invalid Date (ex. 01/01/1900)</font>" }
  }
  if(t1)
  {  if(t1.value !='' || t2.value !=''  || t3.value !='')
        if(t1.value !='' && t2.value !=''  && t3.value !='') 
          { Ttext = t1.value  + ':' + t2.value + ' ' + t3.value }
          else
          {  err.innerHTML = "<font color=red size=-2>Invalid Time</font>"  }
  }
  if(Dtext !='' && Ttext !='') Dtext = Dtext + ' ';
  obj.value = Dtext + Ttext;
}
//################################################################################################################
function checkForm(obj,formname)
{   var theform=obj
	var frmLength = theform.length;	
	for (i=0; i<frmLength;i++)
		{  if(theform[i].getAttribute ("REQ") =="1")
		   {//alert(theform[i].getAttribute("QUESTION") + ' - ' +theform[i].getAttribute("ITYPE") + ' = ' + theform[i].value)
		    var currentQuestion = document.getElementById('TD'+theform[i].name);
		    currentQuestion.className ='FormQuestion'
			switch (theform[i].getAttribute("ITYPE"))
				{
				case "1": case "2":  //TEXT
					if(theform[i].value =='')
						{
							alert('A required question was not answered!');
							theform[i].focus();
							currentQuestion.className ='FormQuestionError'
							return false;
						}
				break;
				case "3": //checkbox
						if(CheckCheckBox(theform[i].name,1) == false)
						{
							alert('A required question was not answered!\n\nAt least one choice must be selected!')
							currentQuestion.className ='FormQuestionError'
							return false;
						}
				break;
				case "4": //radio
						if(CheckCheckBox(theform[i].name,1) == false)
						{
							alert('A required question was not answered!\n\n One choice must be selected!')
							currentQuestion.className ='FormQuestionError'
							window.location.hash="ANCHOR" + theform[i].name; 							
							return false;
						}
				break;
				case "5": //select
						if(theform[i].value =='')
						{
							alert('A required question was not answered!\n\n One choice must be selected!')
							currentQuestion.className ='FormQuestionError'
							return false;
						}
				break;
				default : alert('hitting default');
				}

		   }
	    }
	  document.getElementById("MyFormSubmitTR").style.display="none";
	  document.getElementById("MyFormSubmitTXTTR").style.display="";
	     	
}
//################################################################################################################
function CheckCheckBox(object,count)
{	var checkbox_choices = 0;
	var checklength = document.getElementsByName(object).length
	
	for (counter = 0; counter < checklength; counter++)
	{	if(document.getElementsByName(object).item(counter).checked == true)
			checkbox_choices = checkbox_choices + 1
	}
	if(checkbox_choices>=count)
		return true
	else
		return false
}
//################################################################################################################
function CloseInfoWindow()
{
    InfoWindow.hide(); 
}
