// JavaScript Document
var new_window;

//this function opens a new browser window so the event information can be displayed
function show_popup_window(event_id){
	new_window = window.open("http://www.cornerstone4u.org/youth/calendar/calendar_popup_window.php?id=" + event_id, "event_window", "width=350,height=320,top=300,left=320,scrollbars=yes");
	return false;
}

//this function opens a new browser window so the event information can be displayed
function cornerstone_show_popup_window(event_id){
	new_window = window.open("http://www.cornerstone4u.org/calendar/calendar_popup_window.php?id=" + event_id, "event_window", "width=350,height=320,top=300,left=320,scrollbars=yes");
	return false;
}

function close_window(){
	this.close();
	return false;
}

function admin_left_nav()
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="155" height="415">\n');
    document.write('<param name="movie" value="http://www.cornerstone4u.org/ssl/navigation/cornerstone_admin_left_nav.swf">\n');
    document.write('<param name="quality" value="high">\n');
    document.write('<embed src="http://www.cornerstone4u.org/ssl/navigation/cornerstone_admin_left_nav.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="155" height="415"></embed>\n');
	document.write('</object>\n');

}

//The allTrim() JavaScript function combines both leftTrim() and rightTrim() functions:

function trimAll(sString) 
{
  while (sString.substring(0,1) == ' ')
  {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function regexp_test_phone_number(phone_number){
	var regexp = /[0-9]{10}/;
	return regexp.test(phone_number);
}

//This function statement converts time from the 12 hour time scale to the 24 hour time scale and puts the hours
//and minutes in the necessary format


function convert_twelve_hour_to_twenty_four_hour_time(hour, minute, am_pm){	
    var num_hour = parseInt(hour,10);
    var num_minute = parseInt(minute,10);
   
	var time;
	if (am_pm == 'pm'){
		if (num_hour == 12){
			time = (num_hour *100) + num_minute;
		}else{
			time = ((num_hour + 12) * 100) + num_minute;
		}
	}else{
		if (num_hour == 12){
			time = num_minute;
		}else{
			time = (num_hour * 100) + num_minute;
		}
	}
	return time;
}



  
 /************************************************************************************************************/
 /*     Code to Validate the Dates entered in the drop down boxes                                                                                                          */
 /************************************************************************************************************/
 
 /****************************************************************************************************
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
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){
	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 should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
//		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateDate(string_date){
	if (isDate(string_date)==false){
		return false
	}
    return true
 }
 
  /************************************************************************************************************/
 /*     End Code to Validate the Dates entered in the drop down boxes                                                                                                          */
 /************************************************************************************************************/