    var validationmsg = '';
insertJobSourceByObject = function() {
	var js = new ajaxSources();
	var i = new Object();
	i.JobSourceName = document.getElementById('nJobSource').value;
	i.JobSourceType = document.getElementById('nJobSourceTypeid').value;
	i.URL = document.getElementById('nURL').value;
	i.SearchURL = document.getElementById('nSearchURL').value;
	i.Comments = document.getElementById('nComments').value;
	js.InsertJS(i);
	ColdFusion.Grid.refresh('JobSourcesGrid','true');
	resetNewJobSourcePage();
	toggleIndeedAdDisplay('displayOnly', 'formVals');
	}
	
	noteGridChange = function(title,id) {
   var a = new ajaxJobs();
   document.getElementById('txtJobID').value = id;
   
//   var j = a.setJobStruct(id);
}
setJobID = function(){
	var job = new ajaxJobs();
	var qJobID = document.getElementById('hJobID').value; 
	job.SetSessionID(qJobID, 'JobID');	
}
previewJobLetter = function(){
	var job = new ajaxJobs();
	//get ID's to pass to CFC
	var qJobID = document.getElementById('hJobID').value;
	var qLetterID = document.getElementById('hCoverLetterID').value;
	var jobLetter = job.prepare_jobletter_4preview(qJobID,qLetterID);
	//the value returned from the CFC will contain the Text from the Letter after the Percent values have been replaced
	//this value will be inserted into the PreviewLetter cftextarea
	//alert(jobLetter);
	var editorinstance = ColdFusion.objectCache['LetterPreview'];
	var editor = FCKeditorAPI.GetInstance(editorinstance.richtextid);
	//var editor = ColdFusion.RichText.getEditorObject('LetterPreview'); 
	editor.InsertHtml(jobLetter);
	//document.getElementById('btnPreviewLetter').style.display = 'none';
	document.getElementById('FCKThis').style.display  = 'block';
}

updateJobChar =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hJobID').value;
	if (qID > 0) {
		job.UpdateJobsChar(qValue, qField, qID);
	}
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateJobInt =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hJobID').value;
	if (qID > 0) {
		job.UpdateJobsInt(qValue, qField, qID);
	}
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateCompanyChar =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hCompanyID').value;
	job.UpdateCompanyChar(qValue, qField, qID);
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateCompanyInt =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hCompanyID').value;
	job.UpdateCompanyInt(qValue, qField, qID);
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateContactChar =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hContactID').value;
	job.UpdateContactChar(qValue, qField, qID);
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateContactInt =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hContactID').value;
	job.UpdateContactInt(qValue, qField, qID);
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateAdChar =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hAdID').value;
	job.UpdateAdsChar(qValue, qField, qID);
	ColdFusion.Grid.refresh('JobsGrid','true');
}
updateJobSessionValueChar = function(v,s){
	var job = new ajaxJobs();
	var qSessionValue = s;
	var qVal = v;
	job.UpdateJobSessionValueChar(qSessionValue,qVal);
} 
updateJobSessionValueInt = function(v,s){
	var job = new ajaxJobs();
	var qSessionValue = s;
	var qVal = v;
	job.UpdateJobSessionValueInt(qSessionValue,qVal);
}
hideNewCompanyValues = function(){
	document.getElementById('hideMeIfCompanyExists').style.display = 'none';
	document.getElementById('ContactExists').style.display = 'none';
}
successfulJobInsertMsg = function(m){
		alert(m);
		ColdFusion.navigate('SavedJobs.cfm', 'resultdiv');
	}
loginUser = function(u,p){
	var userName = u;
	var passWord = p;
	var up = new ajaxUsers();
	var userFound = up.getUserInformation(u,p);
	if(userFound == 1){
		ColdFusion.Window.hide('Login');
		relocateTo();
	}
	else{document.getElementById('NoUserFound').style.display = "block";}	
}
registerUser = function(u,e){
	var qUserName = u;
	var qEmail = e;
	var up = new ajaxUsers();
	if (u == ''){
		//validation fails
		validationmsg = validationmsg + "A User Name must be provided";
	}
	//if (u.length > 25) {
		//validationmsg = validationmsg + "Your User Name is too long";
	//}
	if (e == ''){
		//validation fails
		validationmsg = validationmsg + "An email address must be provided";
	}
	if (validationmsg == '') {
		document.getElementById('UserRegistration').style.display = 'none';
		document.getElementById('UserCreationStatus').style.display = 'block';
		var userID = up.InsertUser(qUserName,qEmail);
		if (userID > 0) {
			document.getElementById('UserInserted').style.display = 'block';
		}
		else{alert('User Creation Failed.  Please email info@jobsearchlog.com.')
		return false;
		}
		var tpw = up.TPW(qUserName);
		if (tpw.length > 0  && tpw != qUserName){
			document.getElementById('TempPW').style.display = 'block';
		}
		else{alert('Temporary Password Creation Failed.  Please email info@jobsearchlog.com.')
		return false;
		}
		var sid = up.InsertSecurity(userID,qUserName,tpw);
		if (sid > 0) {
			document.getElementById('Security').style.display = 'block';
		}
		else{alert('Security Profile Creation Failed.  Please email info@jobsearchlog.com.')
		return false;
		}
		var regMail = up.UserRegMail(qUserName, qEmail, tpw);
		if (regMail > 0) {
			document.getElementById('MailUser').style.display = 'block';
		}
		else{alert('Registration Mail Delivery Failed.  Please email info@jobsearchlog.com.')
		return false;
		}
		var send2Jumpstart = up.Go2Jumpstart(userID);
		if (send2Jumpstart > 0) {
			document.getElementById('Jumpstart').style.display = 'block';	
			var ads = up.func_AddDemoAd(userID);
			var sources = up.func_CreateDemoJobSource(userID);
			ColdFusion.navigate('jumpstart.cfm','resultdiv');
			//ColdFusion.Window.hide('Register');
			ColdFusion.Window.hide('Login');
		}
		else{alert('Failed to complete Profile Registration.  Please email info@jobsearchlog.com.')
		ColdFusion.Window.hide('Login');
		ColdFusion.navigate('JSLIntro.cfm','resultdiv');
		return false;
		}
		
	}
	else {alert(validationmsg);}
	ColdFusion.Window.hide('Login');
	ColdFusion.navigate('JSLIntro.cfm','resultdiv');
}
dupeUserName = function(u){
	var userName = u.value;
	var up = new ajaxUsers();
	//If the name is a dupe the cfc will return 1
	isDupe = up.Check4Dupe(userName);
	if (isDupe == 1) {
		validationmsg = validationmsg + 'This username is already in use.  Please choose a different username';
		document.getElementById('MatchingUserFound').style.display = 'inline';
	}
	else{
		validationmsg = '';
		document.getElementById('MatchingUserFound').style.display = 'none';}
}
tooLongUserName = function(u){
	var userName = u.value;
	if (userName.length > 25){
		validationmsg = validationmsg + "The provided username is too long.  Please choose a shorter username";
		$('#MatchingUserFound').html(validationmsg).toggle();
	}
}
relocateTo = function() {
	window.location.reload( false );
}
logoutUser = function(){
	var a = new ajaxUsers();
	var iLoggedOut = a.LogOutUser();
	window.location.reload(false);
	
}	

toggleDivDisplay = function(showme, hideme) {
	document.getElementById(showme).style.display = 'block';
	document.getElementById(hideme).style.display = 'none';	
}
passwordMatch = function(){
		var pw = document.getElementById('Password').value;
		var pwa = document.getElementById('RepeatPassword').value;
		
		if(pw == pwa) {
			updateUserPW(pw);
		}
		else {
			alert('No matching username found.  Has this username already veen validated?');
			location.href="index.cfm"
		}
	}
updateUserPW = function(pw){
		up = new ajaxUsers();
		userID = document.getElementById('hUserID').value;
		pwUpdated = up.setNewPassword(userID,pw);
		var userFound = up.putUserInfoIntoStruct(userID);
		location.href ='index.cfm';
	}
clickSaveAsJob = function(a){
	var ad2Save = 'AddJob.cfm?PassedAd=' + a;
	ColdFusion.navigate(ad2Save,'resultdiv');
}
getFCKValue = function() { 
	//alert('fck');
	var job = new ajaxJobs();
	var qSessionValue = 'EmailText';
	var qVal = ColdFusion.getElementValue('LetterPreview', 'JobsForm');
	alert(qVal);
	job.UpdateJobSessionValueChar(qSessionValue,qVal);
	
 }
 	addComment4Job = function() {
		var past = new ajaxJobs();
		past.setCallbackHandler(historycallback);
		past.setErrorHandler(maleErrorHandler);
		past.setHTTPMethod('POST');
		past.setForm('JobsForm');
		comment = past.InsertComment();
		document.getElementById('qComment').value = '';
		//ColdFusion.Grid.refresh('HistoryGrid','true');
		
	}
	  historycallback = function(text)
    {
    	var msg = 'Your comment ';
    	msg = msg +  ' was added \n ';
    	msg = msg + 'to this job. \n ';
		msg = msg + 'It is viewable in the Job History';
       alert(msg);
    }
 	JobLetter2Mail = function() {
		var ltr = new Letter();
		ltr.setCallbackHandler(malecallback);
		ltr.setErrorHandler(maleErrorHandler);
		ltr.setHTTPMethod('POST');
		ltr.setForm('mailletter');
		mail = ltr.JobLetter();
	}
	maleErrorHandler = function(statusCode, statusMsg)
            {
                alert('Status: ' + statusCode + ', ' + statusMsg);
            }
   malecallback = function(text)
    {
    	var msg = 'Your email to ';
    	msg = msg + text + ' has been sent. \n ';
    	msg = msg + 'Look for a copy of the letter in your inbox. '
       alert(msg);
    }
	showHistory4Job = function(j,u){
		var job = new ajaxJobs();
		jStruct = job.StructByLightning(j,u);
		
	}
	showJobHistory = function(r) {
	document.getElementById("hJobTitle").value = r.JOBTITLE;
	//document.getElementById("txtJobTitle").value = document.getElementById("hJobTitle").value;
	document.getElementById("hCompany").value = r.COMPANY;
	document.getElementById("hJobStatus").value = r.JOBSTATUS;
	//var theDiv = r.JOBTITLE + '<br />';
	var theDiv = '<div class="fieldForm" id="fieldForm" > <div class="field50Pct"> ';
	theDiv = theDiv + '<div class="fieldItemLabel"><label for="sCompanyDisp">Company</label></div>';
	theDiv = theDiv + '<div class="fieldItemValue"><span id="sCompanyDisp" name="sCompanyDisp">';
	theDiv = theDiv +  r.COMPANY + '</span></div></div>';
	theDiv = theDiv + '<div class="field50Pct"> ';
	theDiv = theDiv + '<div class="fieldItemLabel"><label for="sContactDisp">Contact</label></div>';
	theDiv = theDiv + '<div class="fieldItemValue"><span id="sContactDisp" name="sContactDisp">';
	theDiv = theDiv +  '<a href="mailto:' + r.CONTACTEMAIL ;
	theDiv = theDiv +  '">' + r.CONTACT + '</a></span></div></div><div class="clear"></div></div>';
	document.getElementById("sJobTitle").innerHTML = theDiv;
}
updateInt4History =function(v,f){
	var job = new ajaxJobs();
	var qValue = v;
	var qField = f;
	var qID = document.getElementById('hJobID').value;
	job.UpdateJobsInt(qValue, qField, qID);
	//ColdFusion.Grid.refresh('HistoryGrid','true');
}
sendJobStatusChangeEvent = function(j,s,u,g){
	//j = jobid to change status for
	//s = change status 2
	//u = userid
	//g = The Grid Name
	var job = new ajaxJobs();
	eventful = job.InsertEvent('Job Status Change',j,0,0,0,0,s,u);
	if (eventful == 0){
		alert('Job Status Event Creation Failed');
	}
	else {
		ColdFusion.Grid.refresh(g,'true');
	}
}
selectLetter2Send = function(l){
	j = document.getElementById('hJobID').value ;
	alert('Job:' + j + '\n Letter:' + l);
}
clearContent = function(e){
	var element2clear = '#' + e;
		$(element2clear).empty()
}
addContent = function(e,c){
	var element2clear = '#' + e;
		$(element2clear).html(c)	
}
upContent = function(e){
	var element2clear = '#' + e;
		$(element2clear).slideUp();	
}
focusOnUserName = function(){
   		$('txtusername').focus()	
}
