


/* compatibility wrapper functions between V3 and V2 */
 		
xmlHttpGet = function(strURL, addToHistory) {
	NC.util.AjaxManager._xmlHttpGet(strURL, 'MainFrame', addToHistory);
}

xmlHttpPostUpdateMain = function(strURL, queryString) {

	NC.util.AjaxManager._xmlHttpPostUpdateMain( strURL, queryString);
}
		
xmlHttpPostUpdatePage = function(strURL, queryString, targetDivId) {
	NC.util.AjaxManager._xmlHttpPostUpdatePage(strURL, queryString, targetDivId);
}

postRequest = function( formName, targetUrl, divId) {
	NC.util.AjaxManager._postRequest( formName, targetUrl, divId);	
}

postDraft = function( url, divId, notLoggedIn) {
	NC.util.AjaxManager._postDraft(url, divId, notLoggedIn);
}

postSearch = function( url, divId, notLoggedIn) {
	NC.util.AjaxManager._postSearch( url, divId, notLoggedIn);
}

postJob = function( url, divId, notLoggedIn) {
	NC.util.AjaxManager._postJob( url, divId, notLoggedIn);
}

showPreviousMainFrameContent = function() {
	NC.util.AjaxManager.showPreviousMainFrameContent();
}

showNextMainFrameContent = function() {
	NC.util.AjaxManager.showNextMainFrameContent();
}

popHistoryPointer = function() {
	NC.util.AjaxManager.popHistoryPointer();
}

hideSearchDivs = function()
{
	var divSearchCompany = document.getElementById( 'SearchJobCompany');
	var divSearchCategory = document.getElementById( 'SearchJobCategory');
	var divSearchDistance = document.getElementById( 'SearchJobDistance');
	if (divSearchCompany != null) {
		divSearchCompany.style.display = 'none';
	}
	if (divSearchCategory != null) {
		divSearchCategory.style.display = 'none';
	}
	if (divSearchDistance != null) {
		divSearchDistance.style.display = 'none';
	}
}

function showSearchDivs()
{
	var divSearchCompany = document.getElementById( 'SearchJobCompany');
	var divSearchCategory = document.getElementById( 'SearchJobCategory');
	var divSearchDistance = document.getElementById( 'SearchJobDistance');
	if (divSearchCompany != null) {
		divSearchCompany.style.display = '';
	}
	if (divSearchCategory != null) {
		divSearchCategory.style.display = '';
	}
	if (divSearchDistance != null) {
		divSearchDistance.style.display = '';
	}
}


function showJsNlSignupForm(signupUrl, event)
{
	hideSearchDivs();
	/* turn off overlays for now
	var transparent = document.getElementById( 'overlay');
	if (transparent != null) {
		transparent.style.visibility = "visible";
	}
	*/
	var divLogin = document.getElementById( 'jslogin');
	var divSignup = document.getElementById( 'jssignup');
	divSignup.style.left=event.clientX + 'px';
	divSignup.style.top=event.clientY + 'px';
	divSignup.style.width = '450px';
//	divSignup.style.left=200;
	divSignup.style.display = 'block';
	divLogin.style.display = 'none';
//	var signupUrl = '../content/jssignup.php';
	var refCodeDiv = document.getElementById( 'refcode');
	if (refCodeDiv != null) {
		var refcode = refCodeDiv.innerHTML;
		signupUrl += '?refcode=' + refcode;
		var refNameDiv = document.getElementById( 'refname');
		if (refNameDiv != null) {
			var refname = refNameDiv.innerHTML;
			if (refname.length > 0) {
				signupUrl += '&refname=' + refname;
				signupUrl = encodeURI(signupUrl);
			}
		}
	}
	NC.util.AjaxManager._xmlHttpGet(signupUrl, 'jssignup', false);
}

function hideJsSignupForm()
{
	/* turn off overlays for now
	var transparent = document.getElementById( 'overlay');
	if (transparent != null) {
		transparent.style.visibility = "hidden";
	}
	*/
	hideDiv('jssignup');
	var divSignup = document.getElementById( 'jssignup');
	divSignup.innerHTML= '';
	showSearchDivs();
	
}

function showJsNlLoginForm( loginUrl, event)
{
	/*
	hideSearchDivs();
	var divlogin = document.getElementById( 'jslogin');
	var divsignup = document.getElementById( 'jssignup');
	divlogin.style.left=event.clientX + 'px';
	divlogin.style.top=event.clientY + 'px';
	divlogin.style.width = '150px';
//	divlogin.style.left=700;
	divlogin.style.display = 'block';
	divsignup.style.display = 'none';
//	var loginUrl = '../content/jslogin.php';
	NC.util.AjaxManager._xmlHttpGet(loginUrl, 'jslogin', false);
	* */
	var parameters = '';
	this.dialog = new NC.widget.ValidatedModalDialog(
		loginUrl, 
		parameters, 
		NC.util.AjaxDialogDisplay.DialogWrapper, 
		'JsLogin',
 		function( updateUrl, updateParms, updateTarget) // submission function
 		{
			var callback =
			{
  				success:function( o) {
  					alert( "Success");
  				},
  				failure:function( o) {
  					alert( "Failure");
  				},
				scope: this    				
			};
			updateUrl += '?' + updateParms;
			var connection = new NC.util.AjaxConnection( 'GET', updateUrl, null);
			connection.executeMethod( callback);
 		}, 
 		'validate_employer_ajax.php4', // not used - still using legacy functions
 		'', // not used
 		function( form, errorDiv) // validation function
 		{
 			alert( "validate")
			return true;	
 		},
 		'LoginError',
 		true
	);	
	// position
	var heightY = 400;
	var widthX = 350;
	var leftX = (NC.util.Dom.getViewportWidth() - widthX)/2 ;
	var topY = 300;
	this.dialog.show( leftX, topY, widthX);		
	
}

function hideLoginForm()
{
	/* turn off overlays for now 
	var transparent = document.getElementById( 'overlay');
	if (transparent != null) {
		transparent.style.visibility = "hidden";
	}
	*/
	hideDiv('jslogin');
	var divSignup = document.getElementById( 'jslogin');
	divSignup.innerHTML= '';
	showSearchDivs();
}

	// post an login request	
	function postJsLoginRequest( divId, top) 
	{
		/* turn off overlays for now
		var transparent = document.getElementById( 'overlay');
		if (transparent != null) {
			transparent.style.visibility = "hidden";
		}
		*/
		var form = document.forms['JsLogin'];
		var postData = "";
		var email = form.Email;
		var password = form.Password;
		var employer = form.Employer;
		postData += "Email=" + email.value + "&";
		postData += "Password=" + password.value;
		var rval;
		if (employer.value == 1 || employer.checked) {
			var empValidateUrl = "./alerts/validate_employer_ajax.php4";
			if (top == false) {
				empValidateUrl = "./validate_employer_ajax.php4";
			}
    		rval = xmlHttpPostUpdatePage(empValidateUrl, postData, divId);
		}
		else {
			var jsValidateUrl = "./alerts/validate_user_ajax.php4";
			if (top == false) {
				jsValidateUrl = "./validate_user_ajax.php4";
			}
    		rval = xmlHttpPostUpdatePage(jsValidateUrl, postData, divId);
    	}
	}

	// post an signup request	
	function postJsSignupRequest( divId) 
	{
		/* turn off overlays for now 
		var transparent = document.getElementById( 'overlay');
		if (transparent != null) {
			transparent.style.visibility = "hidden";
		}
		*/
		var form = document.forms['JsSignup'];
		var postData = "";
		var name = form.NewName;
		var email = form.NewEmail;
		var password = form.Password;
		var password1 = form.Password1;
		var question = form.Question;
		var answer = form.Answer;
		var screenname = form.ScreenName;
		var refcodeControl = form.refcode;
		var cid = form.Cid;
		postData += "NewName=" + name.value + "&";
		postData += "NewEmail=" + email.value + "&";
		postData += "ScreenName=" + screenname.value + "&";
		postData += "Password=" + password.value + "&";
		postData += "Password1=" + password1.value + "&";
		postData += "Question=" + question.value + "&";
		postData += "Answer=" + answer.value  + "&";
		postData += "Cid=" + cid.value  + "&";
		postData += "refcode=" + refcodeControl.value;
//		alert( postData);
    	var rval = xmlHttpPostUpdatePage("./alerts/js_dosignup_ajax.php", postData, divId);
	}
	
	// job application helpers
	
	function applyForJob( jobId)
	{
		popHistoryPointer(); // back one
		showPreviousMainFrameContent();	
		window.open('./ah2.php?jid=' + jobId,'ApplicationWindow') ;
	}

	// post an invitation request	
	function postInvitationRequest() {
		var form = document.forms['JsInviteForm'];
		var postData = "";
		var emailAddress = form.EmailAddress;
		var emailSubject = form.Subject;
		var emailBody = form.Body;
		postData += "EmailAddress=" + emailAddress.value + "&";
		postData += "Subject=" + emailSubject.value + "&";
		postData += "Body=" + emailBody.value;
//		alert( postData);
    	var rval = xmlHttpPostUpdatePage("./do_send_mail_form_actions.php", postData, 'centercontent');
	}
	
	// this is a hack because I could not figure out how to handle two submit buttons within an Ajax framework
	
	// process the preview invitation form	- send the message
	function postSendInvitation( ) {
		var form = document.forms['JsPreviewFormSend'];
		var postData = "";
		var emailAddress = form.EmailAddress;
		var emailSubject = form.Subject;
		var emailBody = form.Body;
		var command = form.Command;
		postData += "EmailAddress=" + emailAddress.value + "&";
		postData += "Subject=" + emailSubject.value + "&";
		postData += "Body=" + emailBody.value + "&";
		postData += "Command=" + command.value;
//		alert( postData);
    	var rval = xmlHttpPostUpdatePage("./do_inv_form_actions.php", postData, 'centercontent');
	}
	
	// process the preview invitation form - back to preview	
	function postBackToPreview( ) {
		var form = document.forms['JsPreviewFormPreview'];
		var postData = "";
		var emailAddress = form.EmailAddress;
		var emailSubject = form.Subject;
		var emailBody = form.Body;
		var command = form.Command;
		postData += "EmailAddress=" + emailAddress.value + "&";
		postData += "Subject=" + emailSubject.value + "&";
		postData += "Body=" + emailBody.value + "&";
		postData += "Command=" + command.value;
//		alert( postData);
    	var rval = xmlHttpPostUpdatePage("./do_inv_form_actions.php", postData, 'centercontent');
	}

	function postUpdateResumeRequest() {
		var form = document.forms['JsResumeUpdateForm'];
		var postData = "";
		var resume = form.Resume;
		postData = "Resume=" + escape(resume.value);
    	var rval = xmlHttpPostUpdateMain("./js_do_changeresume.php4", postData);
	}
	
	



