/*================================================================================================================================
Company: Quadrant
Application: CMEPlanner web site
Author: Jacob Park
Description: javascript utility, rollover buttons
Dates: 7/22/2003, 8/15/2003
==================================================================================================================================*/

function Rollover(Img, on) {
  var root = 'http://208.133.254.29:5000/images/rollover/';
  if (document.images) {    if (on)
		document.images[Img].src = root + Img + "_on.gif";
		//document.images.left_nav_02.src =   'http://208.133.254.29:5000/images/rollover/left_nav_27.gif'
    else {		document.images[Img].src = root + Img + ".gif";		//var	imgon = new Image();		//imgon.src = 'http://208.133.254.29:5000/images/rollover/left_nav_27_on.gif'
		//document.images.left_nav_02.src = imgon.src;  	}
  }}


function ShowImage(img) {
	window.open('/include/ShowImg.asp?img='+img,'Img','width=1,height=1,scrollbars=1,top=30,left=30');
}

function bookmark_site() {

  var sPlatform = navigator.platform;
  bMac = (sPlatform == "MacPPC")
  if (bMac)
    {
       alert('Mac Users: Please press CTRL+D to bookmark this site.' + '\n' + 'or select Navigator -> Bookmarks ->Add Bookmark.');
       return;
    }

    if (navigator.userAgent.indexOf("MSIE") != -1)
    {
       window.external.AddFavorite('http://www.cmeplanner.com','CMEPlanner.com');
    }
    else
    {
       alert('Netscape Users: Please press CTRL+D to bookmark this site.' + '\n' + 'or select Navigator -> Bookmarks ->Add Bookmark.');
       return;
    }
}


function offramp()  {
	var Msg = "You have selected a link that will take you outside of the CMEPlanner Web site. \nCMEPlanner is not responsible for any content beyond this point."
	alert(Msg);
}



function ValidateLogin(frm){

	if (frm.Email.value == "") {
		alert("Please enter your email address");
		frm.Email.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.Email.value))  {
		frm.Email.select();
		frm.Email.focus();
		return false;
	}

	if (frm.PWD.value == "") {
		alert("Please enter Password");
		frm.PWD.focus();
		return false;
	}
	
	return true;
}


function ValidateShare(frm){

	if (frm.FromEmail.value == "") {
		alert("Please enter your email address");
		frm.FromEmail.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.FromEmail.value))  {
		frm.FromEmail.select();
		frm.FromEmail.focus();
		return false;
	}

	if (frm.ToEmail.value == "") {
		alert("Please enter your colleague's email address");
		frm.ToEmail.focus();
		return false;
	}
	
	if (!CheckEmail(frm.ToEmail.value))  {
		frm.ToEmail.select();
		frm.ToEmail.focus();
		return false;
	}
		                
	return true;
}




function CheckEmail(email) {

		var first = email.indexOf("@")
		var last = email.indexOf(".")
		var email_num = email.length;
		
		if (first != -1) {                // check @ duplicate
			mail_str = email;
			mail_str = mail_str.substr(first+1);
			second = mail_str.indexOf("@");
			if (second != -1)	{	
				alert("Unrecognized e-mail address format. Please check your e-mail and enter a valid e-mail address.");
				
				return false;
			}
		}

		for (var l = 0; l <= (email_num - 1); l++) {
			if (email.indexOf(" ") >= 0 ) {
				alert ("\"Space\" is not valid in e-mail address.");
		        
		        return false;
		    } 
		}

		if ((email.indexOf("/")) != -1)	{	
			alert ("\" / \" is not valid in e-mail address.");
			
			return false;
		}

		if ((email.indexOf(";")) != -1)	{	
			alert ("\" ; \" is not valid in e-mail address.");
			
			return false;
		}

		if ((email.indexOf(",")) != -1)	{	
			alert ("\" , \" is not valid in e-mail address.");
			
			return false;
		}

		if (email.search(/(\S+)@(\S+)\.(\S+)/) == -1) {
				alert("Unrecognized e-mail address format. Please check your e-mail and enter a valid e-mail address.");
			
			return false;
		}
	
		if (email.substring(0, 5) == "http:") {
			alert ("\" http: \" is not valid in e-mail address.");
			
			return false;
		} 

		if (email.lastIndexOf(".") == email_num-1) {
			alert ("\" . \" is not valid at the end of e-mail address.");
			
			return false;
		} 
	
	return true;
} // checkEMail ()


//8-4-2003 MK
function MM_jumpMenu(targ,selObj,restore){
	if (selObj.selectedIndex > 1) {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) 
		selObj.selectedIndex=0;
	}
}


//date validation
//8-18-2003
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 dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	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;
}
