

function addUser(theForm){

	if (theForm.UserID.value == "" ) {		
		theForm.UserID.focus();	
	    alert("Please enter UserID!");  
    	return false;		
	} else if (theForm.Password.value == "" ){			
		theForm.Password.focus();	
    	alert("Please enter Password");
	    return false;
	} else if (theForm.FullName.value == "" ){			
		theForm.FullName.focus();	
    	alert("Please enter Full Name");
	    return false;
	} 
 
	return true;
}

function addEventType(theForm){

	if (theForm.TypeDescription.value == "" ) {		
		theForm.TypeDescription.focus();	
	    alert("You must enter Event Type Description!");  
    	return false;		
	} else if (theForm.EventColor.value == "" ){			
    	alert("Please Select valid color");
	    return false;
	} 
	return true;
}
function addCalendar(theForm){

	if (theForm.CalendarName.value == "" ) {		
		theForm.CalendarName.focus();	
	    alert("You must enter Calendar Name!");  
    	return false;			
	} 
	return true;
}



function addEventValidator(theForm){

	if (theForm.Subject.value == "" ) {		
		theForm.Subject.focus();	
	    alert("You must enter Subject for event");  
    	return false;		
	} else if (theForm.startD.value == "" ){			
    	alert("Please Select Start Date");
	    return false;
	} else if (theForm.endD.value == "") {			
    	alert("Please Select End Date");
	    return false;
	}	
	
	/*make sure waranty start date is greater than waranty end date */
	var eventStartDt = new Date(theForm.startD.value);
	var eventEndDt = new Date(theForm.endD.value);
	var days = jsDateDiff(eventStartDt,eventEndDt,"d",true);
	if (days < 0 ){
		alert("Event Start Date must be greater then Event End Date!");
		return false;
	}

	if ( theForm.EventType.options[0].selected){
		alert("Please select Event Type!");
		return false;
	}

	return true;
}
 
 function SetColor(item){
	var targObj;
	if (document.all){
		targObj=document.all("color"); 
	} else if (document.getElementById) {
		targObj=document.getElementById("color");
	}
	var selType;
	for (i=0; i < item.length ;i++) {
    	if (item.options[i].selected) {
  			selType = item.options[i].value;						
		}
    }	
	for(i=0; i < EventColor.length;i++){
		if ( EventColor[i].Type == selType)
				targObj.style.background='#'+EventColor[i].Color;			
	}
}

 
function L(item,color){
	item.style.cursor='hand';
	if (color == "")
		item.style.background='#B0C4DE';
	else
		item.style.background=color;
	//gold color =#FFCC00
}

function D(item,color){
	item.style.background=color;
}

function jsDateDiff( startD, endD, interval, rounding ) {

    var iOut = 0; var bufferA = Date.parse( startD );
	var bufferB = Date.parse(endD);var number = bufferB-bufferA ;

    switch (interval.charAt(0)) {
        case 'd': case 'D':
            iOut = parseInt(number / 86400000) ;
			if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
	        return null;
    }
    return iOut ;
}
