// display decision alert box

function decision(message, url){

	if(confirm(message)) location.href = url;

}



// open browser window

function openPopUp(url, windowName, w, h, scrollbar) {



           var winl = (screen.width - w) / 2;

           var wint = (screen.height - h) / 2;

           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;

		   win = window.open(url, windowName, winprops);

           if (parseInt(navigator.appVersion) >= 4) { 

              	win.window.focus(); 

           } 

}



function jumpMenu(target,object,restore){ 

  eval(target+".location='"+object.options[object.selectedIndex].value+"'");

  if (restore) object.selectedIndex=0;

}



function findObj(n, d) {

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function getImage(imageName)

{

		findObj('img').src = imageName;

}



function submitDoc(formName) { 

  var obj;

 

	if (obj=findObj(formName)!=null) 

	{

		findObj(formName).submit(); 

	}

	else 

	{

		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');

	}
    


}

function submitDoc1(formName) { 

  var obj;

 

    if (obj=findObj(formName)!=null) 

    {
        findObj(formName).payment.value = "true";
        findObj(formName).submit(); 

    }

    else 

    {

        alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');

    }
    



}



function validateQuest()
{
     if (document.frmQuest.emergency_contact_person.value== "" )
     { 
         alert ("Please enter Emergency contact person name");
         document.frmQuest.emergency_contact_person.focus();
         return false;
     }	
     if (document.frmQuest.emergency_contact_phone.value== "" )
     { 
         alert ("Please enter Emergency contact phone number");
         document.frmQuest.emergency_contact_phone.focus();
         return false;
     }   
    
   
     if (valButton(document.frmQuest.heart_disease_stroke_raised_cholesterol_or_sudden_death) == null )
     { 
         alert ("Please check Have you ever had or do you currently have?");
         return false;
     } 
     if (valButton(document.frmQuest.regular_exercise) == null )
     { 
         alert ("Please check regular exercise");
         return false;
     } 
     if (valButton(document.frmQuest.prescription_medication) == null )
     { 
         alert ("Please check prescriptionmedication");
         return false;
     } 
     if(valButton(document.frmQuest.hospitalised) == null )
     { 
         alert ("Please check prescription medication");
         return false;
     }
     else if(valButton(document.frmQuest.hospitalised) == "yes")               
     {
         
         if(valButton(document.frmQuest.given_birth) == null )
         { 
             alert ("Please check Have you given birth in the last 8 weeks?");
             return false;
         }  
         
         if(valButton(document.frmQuest.pregnant) == null )
         { 
             alert ("Please check Are you currently pregnant?");
             return false;
         }  
         
         if (document.frmQuest.Doctor_name.value== "" )
         { 
             alert ("Please enter Doctor Name");
             document.frmQuest.Doctor_name.focus();
             return false;
         } 
         if (document.frmQuest.Doctor_phone.value== "" )
         { 
             alert ("Please enter Doctor Phone");
             document.frmQuest.Doctor_phone.focus();
             return false;
         }
         if (document.frmQuest.Date_Cleared.value== "" )
         { 
             alert ("Please enter Date Cleared");
             document.frmQuest.Date_Cleared.focus();
             return false;
         }                          
         
         if(valButton(document.frmQuest.smoke) == null )
         { 
             alert ("Please check Do you smoke?");
             return false;
         }  
         
         if(valButton(document.frmQuest.dieting_or_fasting) == null )
         { 
             alert ("Please check Are you dieting or fasting?");
             return false;
         }                          
                             
         
     }
     
      
	
}

//function to validate radio button
function valButton(btn) {
    
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) 
    {
        if (btn[i].checked) 
        {
            cnt = i; 
            i = -1;
        }
    }
    if (cnt > -1) 
        return btn[cnt].value;
    else 
        return null;
}