var uploadWin = null;
function addNewCompanyDetails(){
	
	document.companyDetailsFrm.ID.value = "";
	document.companyDetailsFrm.ACTION.value = "";
	document.companyDetailsFrm.submit();
	
}

function uploadImage(){
	
	if( uploadWin != null && uploadWin.open && uploadWin.closed == false ){
		
		uploadWin.focus();
		return;
	}
	else{
		var url = 'ImageUpload.jsp?ID='+document.companyDetailsFrm.ID.value;
		var popW = 495;
		var popH = 120;

		if(document.all) {
		/* the following is only available after onLoad */
			w = document.body.clientWidth;
			h = document.body.clientHeight;
			LeftPosition =(w)?(w-popW)/2:100;
			TopPosition  =(h)?(h-popH)/2:100;

		}

		var settings='width='+popW+',height='+popH+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		uploadWin = window.open(url,'UserPasswordChange', settings) ;	
		//showModalDialog(url,null,"edge:sunken;help:no;center:yes;scroll:yes;resizable:no;status:no;unadorned:no;dialogWidth:350px;dialogHeight:140px;");
	}
	
	
}

function deleteCompanyDetails(){
	
	if( confirm(" Do you want to delete this record ?") == true){
		document.companyDetailsFrm.ACTION.value = "DELETE";
		document.companyDetailsFrm.submit();
	}
	
}

function saveCompanyDetails(){	
	
	if( validateCompanyData() == true ){ 
		
		document.companyDetailsFrm.ACTION.value = "SAVE";
		document.companyDetailsFrm.submit();
	}
}

function reviewThis( regId ){

	document.RegistrationRequestReport.CID.value = regId ;
	document.RegistrationRequestReport.action="RegRequestedCompanyDetails.jsp";
	document.RegistrationRequestReport.submit();
}

function closeCompanyWindow(){
	
	var frm = document.companyDetailsFrm;
	if ( frm == null ){
		frm = document.RegistrationRequestReport;
	}
	
	frm.action="Index.jsp";	
	
	if( frm.SEATCHSTRING.value != '' || frm.CATEGORY.value != '' ){
		
		frm.action="SearchMemberList.jsp";
	}
	
	frm.submit();
}

function validateCompanyData(){
	
	var validData 	= true;	
	var frm 	= document.companyDetailsFrm;
	var msg		= "";	
	var tempVal	= "";
	var focusObj	= null;	
	var ValueEmpty	= null;	
	
	//company name
	tempVal = trim( frm.Company_Name.value );
	if( tempVal == '' ){
		
		validData 	= false;
		msg += '\n\t*  Company Name.';	
		focusObj 	=  frm.Company_Name;
	}

	//SIC
	tempVal = trim( frm.SIC.value );
	if( validateNumericOnly( frm.SIC.value ) == false ){
	
		frm.SIC.value = "";
		validData = false;
		msg += '\n\t*  SIC number.';
		if( focusObj == null ){
			
			focusObj =  frm.SIC;
		}
	
	}
	
	//Dues
	tempVal = trim( frm.Dues.value );
	if( validateCurrency( frm.Dues.value ) == false ){
		
		frm.Dues.value = "";
		validData = false;
		msg += '\n\t*  valid Amount for Dues.';
		if( focusObj == null ){		
			
			focusObj =  frm.Dues;
		}
		
	}
	
	//Portal
	tempVal = trim( frm.Portal_Links.value );
	if( validateCurrency( frm.Portal_Links.value ) == false ){
		
		frm.Portal_Links.value = "";
		validData = false;
		msg += '\n\t*  valid Amount for Portal Links.';
		if( focusObj == null ){		
			
			focusObj =  frm.Portal_Links;
		}
		
	}
	
	//Number of Employees 
	tempVal = trim( frm.Number_of_ees.value );
	if( validateNumericOnly( frm.Number_of_ees.value ) == false ){
		
		frm.Number_of_ees.value = "";
		validData = false;
		msg += '\n\t*  valid Employees Number.';
		if( focusObj == null ){		
			
			focusObj =  frm.Number_of_ees;
		}
		
	}
	
	//Start Date
	tempVal = trim( frm.StartDate.value );
	if( checkDate( frm.StartDate.value ) == false ){
		
		frm.StartDate.value = "";
		validData = false;
		msg += '\n\t* StartDate is invalid. Please enter in mm/dd/yyyy format.';
		if( focusObj == null ){		
		
			focusObj =  frm.StartDate;
		}
	}
	
	//Expire Date
	tempVal = trim( frm.ExpireDate.value );
	if( checkDate( frm.ExpireDate.value ) == false ){
		
		frm.ExpireDate.value = "";
		validData = false;
		msg += '\n\t* ExpireDate is invalid. Please enter in mm/dd/yyyy format.';
		if( focusObj == null ){		
		
			focusObj =  frm.ExpireDate;
		}
	}
	
	//Commants
	tempVal = trim( frm.Comments.value );
	if( frm.Comments.value.length > 255 ){		
		
		validData = false;
		msg += "\n\t* Comments can't exceed more than 255 characters.";
		if( focusObj == null ){		
		
			focusObj =  frm.Comments;
		}
	}
	
	
	if( validData == false ){
		
		alert( "Please enter values  for the following fields: \n" + msg );
		if( ValueEmpty != null ){
			
			ValueEmpty.value="";
		}

		if( focusObj != null ){
			
			focusObj.focus();
		}
	}
	return validData;
}
