var cal_win;
function CalPop(pLoc, pTitle, pHeight, pWidth)
{
//	cal_win = window.open(pLoc, pTitle, 'toolbar=0,titlebar=0,scrollbars=0,menubar=0,width='+pWidth+',height='+pHeight+',left='+(screen.width/2-(pWidth/2))+',top='+(screen.height/2-(pHeight/2)));	
//	var temp;
//	temp = 'resizable=yes,toolbar=0,titlebar=0,scrollbars=1,menubar=0,width=' + pWidth + ',height=' + pHeight + ',left=' + (screen.width/2-(pWidth/2)) + ',top=' + (screen.height/2-(pHeight/2));
//	alert(pWidth);
	
	var strLocation = pLoc;
	var strTitle = pTitle;
	var intpHeight = pHeight;
	var intWidth = pWidth;
	
//	temp = 'resizable=yes,toolbar=0,titlebar=0,scrollbars=1,menubar=0,width=' + pWidth + ',height=' + pHeight + ',left=' + (screen.width/2-(pWidth/2)) + ',top=' + (screen.height/2-(pHeight/2));
//	alert(screen.height/2-(intpHeight/2));
	cal_win = window.open(strLocation, pTitle, 'left=' + (screen.width/2-(intWidth/2)) + ',top=' + (screen.height/2-(intpHeight/2)) + ',width= ' + intWidth + ', height= ' + intpHeight + ' ,toolbar=1,resizable=0');

	//cal_win = window.open(pLoc, pTitle, 'resizable=yes,toolbar=0,titlebar=0,scrollbars=1,menubar=0,width='+pWidth+',height='+pHeight+',left='+(screen.width/2-(pWidth/2))+',top='+(screen.height/2-(pHeight/2)));	
	//cal_win.moveTo(screen.width/2-85,screen.height/2-113);
}
function CalPopNew(pLoc, pTitle, pHeight, pWidth) {
	var strLocation = pLoc;
	var strTitle = pTitle;
	var intpHeight = pHeight;
	var intWidth = pWidth;
//	temp = 'resizable=yes,toolbar=0,titlebar=0,scrollbars=1,menubar=0,width=' + pWidth + ',height=' + pHeight + ',left=' + (screen.width/2-(pWidth/2)) + ',top=' + (screen.height/2-(pHeight/2));
//	alert(screen.height/2-(intpHeight/2));
	cal_win = window.open(strLocation, pTitle,'toolbar=0,titlebar=0,scrollbars=yes,menubar=0, left=' + (screen.width/2-(intWidth/2)) + ',top=' + (screen.height/2-(intpHeight/2)) + ',width= ' + 600 + ', height= ' + 800 + ' ,toolbar=0' );	
}

function CalPopScrl(pLoc,pTitle,pHeight,pWidth)
{
	//cal_win = window.open(pLoc, pTitle, 'toolbar=0,titlebar=0,scrollbars=yes,menubar=0,width='+pWidth+',height='+pHeight);
	cal_win = window.open(pLoc, pTitle, 'toolbar=0,titlebar=0,scrollbars=yes,menubar=0,width='+pWidth+',height='+pHeight+',left='+(screen.width/2-(pWidth/2))+',top='+(screen.height/2-(pHeight/2)));
	//cal_win.moveTo(screen.width/2-85,screen.height/2-113);
}
function CalPopScrlTbar(pLoc,pTitle,pHeight,pWidth)
{
	//cal_win = window.open(pLoc, pTitle, 'toolbar=0,titlebar=0,scrollbars=yes,menubar=0,width='+pWidth+',height='+pHeight);
	cal_win = window.open(pLoc, pTitle, 'resizable=yes,toolbar=0,titlebar=1,scrollbars=yes,menubar=1,width='+pWidth+',height='+pHeight+',left='+(screen.width/2-(pWidth/2))+',top='+(screen.height/2-(pHeight/2)));
	//cal_win.moveTo(screen.width/2-85,screen.height/2-113);
}
function cnfrm(sDest,sAction){
	if (confirm("Are you sure you wish to " + sAction + "?")) {
		document.location=sDest;
	}
}
function cnfrmspl(sDest,sAction){
	if (confirm(sAction)) {
		document.location=sDest;
	}
}	

function dateAdd( start, interval, number ) {
	
// Create 3 error messages, 1 for each argument. 
var startMsg = "Sorry the start parameter of the dateAdd function\n"
    startMsg += "must be a valid date format.\n\n"
    startMsg += "Please try again." ;
		
var intervalMsg = "Sorry the dateAdd function only accepts\n"
    intervalMsg += "d, h, m OR s intervals.\n\n"
    intervalMsg += "Please try again." ;

var numberMsg = "Sorry the number parameter of the dateAdd function\n"
    numberMsg += "must be numeric.\n\n"
    numberMsg += "Please try again." ;
		
// get the milliseconds for this Date object. 
var buffer = Date.parse( start ) ;
	
// check that the start parameter is a valid Date. 
if ( isNaN (buffer) ) {
    alert( startMsg ) ;
    return null ;
}
	
// check that an interval parameter was not numeric. 
if ( interval.charAt == 'undefined' ) {
    // the user specified an incorrect interval, handle the error. 
    alert( intervalMsg ) ;
    return null ;
}

// check that the number parameter is numeric. 
if ( isNaN ( number ) )	{
    alert( numberMsg ) ;
    return null ;
}

// so far, so good...
//
// what kind of add to do? 
switch (interval.charAt(0))
{
    case 'd': case 'D': 
        number *= 24 ; // days to hours
        // fall through! 
    case 'h': case 'H':
        number *= 60 ; // hours to minutes
        // fall through! 
    case 'm': case 'M':
        number *= 60 ; // minutes to seconds
        // fall through! 
    case 's': case 'S':
        number *= 1000 ; // seconds to milliseconds
        break ;
    default:
    // If we get to here then the interval parameter
    // didn't meet the d,h,m,s criteria.  Handle
    // the error. 		
    alert(intervalMsg) ;
    return null ;
}
return new Date( buffer + number ) ;
}
function isEmpty(s) { return ((s == null) || (s.length == 0)) }
function isDigit (c) { return ((c >= "0") && (c <= "9")) }
function isDecimal (s) {
if (isEmpty(s))
	return false;
var DecimalCount = 0;
for (i = 0; i < s.length; i++) {
	var c = s.charAt(i);
	if (! (isDigit(c) || c=="." ) )
		return false;
	if (c == ".")
		DecimalCount++;
	if (DecimalCount > 1)
		return false;
}
	return true;
}
function isMoney (vField) { 
	var s = vField.value;
	var bRet = true;
	var decimalPointDelimiter = ".";
	if (isEmpty(s))
		bRet = true;
	var DecimalCount = 0;
	var DecimalPlaces = -1;
	for (i = 0; i < s.length; i++) { 
		var c = s.charAt(i); 
		if (!(i==0 & c=="$")) { 
			if (! (isDigit(c) || c=="." ) ) 
				bRet = false;
			if (c == decimalPointDelimiter) 
				DecimalCount++;
			if (DecimalCount > 0)
				DecimalPlaces++;
			if (DecimalCount > 1) 
				bRet = false;
		} 
	} 
	if (DecimalPlaces > 2) bRet = false;
			
	if (!bRet) {
		alert(s + ' is not in acceptable form. \nPlease enter the value as 100.59 or 100');
		vField.focus();
	}
}
function cnfrm2(loc1,loc2){
if (confirm("Click OK to open this Instance or Cancel to open this Series")) {
	document.location = loc1;
} else {
	document.location = loc2;
}
}  

function checkDate (date, prompt) {
  var error = false;
  var dateArray = date.split("/");
  
  var vLaterThanDate = false;
  if( arguments.length >= 3 )
  {
	//the 3rd arg is the min date specification, or true to mean right now
	vLaterThanDate = ( arguments[2] == true ? new Date() : new Date(arguments[3]) );
	
	if( isNaN(vLaterThanDate) )
		vLaterThanDate = false;
  }
      
  if (date != "" && dateArray.length == 3) {
    if (isNaN(dateArray[0]) || isNaN(dateArray[1]) || isNaN(dateArray[2])) {
      error = true;
    }
    else {
        if (dateArray[0] > 12 || dateArray[0] < 1) {
          error = true;
        }
        else {
            if (dateArray[1] > 31 && dateArray[1] < 1) {
              error = true;
            }
            else {
                if (dateArray[2].length != 4) {
                  error = true;
                }
            }
        }
    }
  } else {
    error = true;
  }

  if (error == true) {
    if (prompt) {
      alert ("You must enter a valid date.");
    }
    return false;
  } else {
	if( vLaterThanDate != false )
	{
		//check if the date is ahead of this date
		if( vLaterThanDate > new Date(date))
		{
			alert(arguments.length >= 4 ? arguments[3] : (arguments[2] == true ? 'The date must be in the future' : 'The date must be after ' + vLaterThanDate));
			return false;
		}
	}
    return true;
  }
}

function checkEmail (email) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
    return true;
  } else {  
    return false;
  }
}

 
