
// JobListing contruct function
function JobListing() {
	this.jobIDSet = '';
	this.currentJobID = 1;
	this.currentPage = 1;
	this.operationType = '';
	this.discipline = '';
	this.location = '';
	this.priority = '';
	this.employment = '';
	this.employer = '';
	
	// for professional board only
	if ('professional' == boardName) {
		this.title = '';
	}

	// for backend only
	if ('backend' == boardType) {
		this.consultant = '';
	}
	
	this.keyword = '';
	this.overviewPage = '';
};

JobListing.prototype.reset = function() {
	this.deleteCookie(prefix + 'JobIDSet');
	this.deleteCookie(prefix + 'CurrentJobID');
	this.deleteCookie(prefix + 'CurrentPage');
	this.deleteCookie(prefix + 'OperationType');
	this.deleteCookie(prefix + 'Discipline');
	this.deleteCookie(prefix + 'Location');
	this.deleteCookie(prefix + 'Priority');
	this.deleteCookie(prefix + 'Employment');
	
	// for professional board only
	if ('professional' == boardName) {
		this.deleteCookie(prefix + 'Title');
	}
	
	// for backend only
	if ('backend' == boardType) {
		this.deleteCookie(prefix + 'Consultant');
		this.deleteCookie(prefix + 'Employer');
	}
	
	this.deleteCookie(prefix + 'Keyword');
};

JobListing.prototype.setCookie = function(name, value) {
    var cookie_str = name + "=" + escape(value);
    document.cookie = cookie_str;
};


JobListing.prototype.getCookie = function(name) {
    if (!name) return '';
    
    var raw_cookies, tmp, i;
    var cookies = new Array();
    
    raw_cookies = document.cookie.split('; ');
    for (i=0; i < raw_cookies.length; i++) {
        tmp = raw_cookies[i].split('=');
        cookies[tmp[0]] = unescape(tmp[1]);
    }

    if (cookies[name] != null) {
        return cookies[name];
    } else {
        return '';
    }
};

JobListing.prototype.deleteCookie = function(name) {
	var date = new Date(2000, 1, 1);
	document.cookie = name + "=;expires= " + date.toGMTString() +  "; "  +  "; ";
};

// Job Listing ID Set
JobListing.prototype.setCurrentJobID = function(currentJobID) {
    this.setCookie(prefix + 'CurrentJobID', currentJobID);
};

// Job Listing ID Set
JobListing.prototype.setJobIDSet = function(jobIDSet) {
    this.setCookie(prefix + 'JobIDSet', jobIDSet);
};

// set the current page
JobListing.prototype.setCurrentPage = function(currentPage) {
    this.setCookie(prefix + 'CurrentPage', currentPage);
};

// set the operation type
JobListing.prototype.setOperationType = function(operationType) {
    this.setCookie(prefix + 'OperationType', operationType);
};

// set the discipline
JobListing.prototype.setDiscipline = function(discipline) {
    this.setCookie(prefix + 'Discipline', discipline);
};

// set the location
JobListing.prototype.setLocation = function(location) {
    this.setCookie(prefix + 'Location', location);
};

// set priority
JobListing.prototype.setPriority = function(priority) {
	this.setCookie(prefix + 'Priority', priority);
};

// set employment
JobListing.prototype.setEmployment = function(employment) {
	this.setCookie(prefix + 'Employment', employment);
};

//for professional board only
if ('professional' == boardName) {
	// set the title
	JobListing.prototype.setTitle = function(title) {
		this.setCookie(prefix + 'Title', title);
	};
}

//for backend only
if ('backend' == boardType) {
	// set the consultant
	JobListing.prototype.setConsultant = function(consultant) {
	    this.setCookie(prefix + 'Consultant', consultant);
	};

	// set employer
	JobListing.prototype.setEmployer = function(employer) {
		this.setCookie(prefix + 'Employer', employer);
	};
}

// set keyword
JobListing.prototype.setKeyword = function(keyword) {
    this.setCookie(prefix + 'Keyword', keyword);
};

// restore filtered job listing by executing query again
JobListing.prototype.load = function() {
	this.jobIDSet = this.getCookie(prefix + 'JobIDSet');
	this.currentJobID = this.getCookie(prefix + 'CurrentJobID');
	this.currentPage = this.getCookie(prefix + 'CurrentPage');
	this.operationType = this.getCookie(prefix + 'OperationType');
	this.discipline = this.getCookie(prefix + 'Discipline');
	this.location = this.getCookie(prefix + 'Location');
	this.priority = this.getCookie(prefix + 'Priority');
	this.employment = this.getCookie(prefix + 'Employment');
	this.employer = this.getCookie(prefix + 'Employer');
	
	// for professional board only
	if ('professional' == boardName) {
		this.title = this.getCookie(prefix + 'Title');
	}
	
	// for backend only
	if ('backend' == boardType) {	
		this.consultant = this.getCookie(prefix + 'Consultant');
	}
	
	this.keyword = this.getCookie(prefix + 'Keyword');
};

// sleeping...
JobListing.prototype.sleep = function(napTime){
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();
	while(sleeping){
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > napTime) {
			sleeping = false;
		}
	}
};
