// JavaScript Document

// Image Swap Preload
function MM_preloadImages() { //v3.0
  var d=document; if(d.Images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Image Swap
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Pulldown Nav
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Browser Detect
if(document.layers){

   document.write("<link rel='STYLESHEET' type='TEXT/CSS' href='http://www.advancekids.com/css/netscape.css'>");

}

else if(document.all){

    document.write("<link rel='STYLESHEET' type='TEXT/CSS' href='http://www.advancekids.com/css/ie.css'>");

}


else if(document.getElementById){

    document.write("<link rel='STYLESHEET' type='TEXT/CSS' href='http://www.advancekids.com/css/ie.css'>");

}

else{

    document.write("<link rel='STYLESHEET' type='TEXT/CSS' href='http://www.advancekids.com/css/ie.css'>");

}

// Calendar
function doClock() {
    var t = new Date(), a = doClock.arguments, str = "", i, a1, lang = "1";
    var month = new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
    var tday = new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
    for (i = 0; i < a.length; i++) {
        a1 = a[i].charAt(1);
        switch (a[i].charAt(0)) {
          case "M":
            if ((Number(a1) == 3) && ((t.getMonth() + 1) < 10)) {
                str += "0";
            }
            str += (Number(a1) > 1) ? t.getMonth() + 1 : month[t.getMonth() * 2 + Number(a1)];
            break;
          case "D":
            if ((Number(a1) == 1) && (t.getDate() < 10)) {
                str += "0";
            }
            str += t.getDate();
            break;
          case "Y":
            str += (a1 == "0") ? t.getFullYear() : t.getFullYear().toString().substring(2);
            break;
          case "W":
            str += tday[t.getDay() * 2 + Number(a1)];
            break;
          default:
            str += unescape(a[i]);
        }
    }
    return str;
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,fldName){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format for the "+fldName+" field should be : mm/dd/yyyy")
		return false
	}
	if (month<1 || month>12){
		alert("Please enter a valid month in the "+fldName+" field")
		return false
	}
	if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day  in the "+fldName+" field")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear +" in the "+fldName+" field")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date in the "+fldName+" field")
		return false
	}
return true
}

function ckDate() {
	if (document.form1.Display.value=='2') {
		if (isDate(document.form1.DisplayStart.value,'DISPLAY START DATE')==false) {
			return false;				
		}
		else if (isDate(document.form1.DisplayStop.value,'DISPLAY STOP DATE')==false) {
		return false;				
		}
		else {
		return true;
		}
	}
	
}

// PopUp Windows for Functionality
newWindow = null

function openSession(appid, start, end, cid, userid, weekcount, scheddate, listdate, selected, ro)	{	
	newWindow = window.open('scheduler/dsp_form.cfm?&appid='+appid+'&start='+start+'&end='+end+'&cid='+cid+'&userid='+userid+'&weekcount='+weekcount+'&scheddate='+scheddate+'&listdate='+listdate+'&selected='+selected+'&ro='+ro, "newWin", "toolbar=no,location=no,scrollbars=no,width=325,height=525")
}

function intuserselect(groupid,route,s2)		{
	newWindow = window.open("users/dsp_intuserselect.cfm?groupid="+groupid+"&route="+route+"&s2="+s2, "newWin", "toolbar=no,location=no,scrollbars=yes,width=240,height=200")
}

function extuserselect(groupid,route)		{
	newWindow = window.open("users/dsp_extuserselect.cfm?groupid="+groupid+"&route="+route, "newWin", "toolbar=no,location=no,scrollbars=yes,width=246,height=200")
}

function caseAssign(cid)		{
	newWindow = window.open("caseinfo/dsp_form_assign.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=183,height=220")
}

function caseDiagnosis(cid)		{
	newWindow = window.open("caseinfo/dsp_form_diagnosis.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=auto,width=350,height=230")
}

function caseHealth(cid)		{
	newWindow = window.open("caseinfo/dsp_form_health.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=auto,width=196,height=262")
}

function caseSchool(cid)		{
	newWindow = window.open("caseinfo/dsp_form_school.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=auto,width=330,height=220")
}

function caseDoc(cid)		{
	newWindow = window.open("caseinfo/dsp_form_doc.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=auto,width=358,height=216")
}

function caseRefAgency(cid)		{
	newWindow = window.open("caseinfo/dsp_form_refagency.cfm?cid="+cid, "newWin","toolbar=no,location=no,scrollbars=auto,width=380,height=270")
}

function caseSA(said,cid)		{
	newWindow = window.open("caseinfo/dsp_form_sa.cfm?said="+said+'&cid='+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=340,height=450")
}

function newContent(parentid, crumblist)		{
	newWindow = window.open("architecture/dsp_new_content.cfm?parentid="+parentid+'&crumblist='+crumblist, "newWin", "toolbar=no,location=no,scrollbars=no,width=300,height=300")
}

function caseFamily(cid)		{
	newWindow = window.open("caseinfo/dsp_form_family.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=575,height=375")
}

function caseClient(cid)		{
	newWindow = window.open("caseinfo/dsp_form_client.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=300,height=375")
}

function caseCase(cid)		{
	newWindow = window.open("caseinfo/dsp_form_case.cfm?cid="+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=430,height=250")
}

function caseNotes(cid,userid,groupid)		{
	newWindow = window.open("scheduler/dsp_form_notes.cfm?userid="+userid+'&groupid='+groupid+'&cid='+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=183,height=160")
}

function caseStart(cid,userid,groupid)		{
	newWindow = window.open("scheduler/dsp_form_startdate.cfm?userid="+userid+'&groupid='+groupid+'&cid='+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=183,height=160")
}

function caseWeeklyhrs(cid,userid,groupid)		{
	newWindow = window.open("scheduler/dsp_form_weeklyhrs.cfm?userid="+userid+'&groupid='+groupid+'&cid='+cid, "newWin", "toolbar=no,location=no,scrollbars=no,width=183,height=160")
}