function Contact_Widget (contacts, owner, serial, saved, valid_contact, winked, jobs) {
	this.contacts = contacts;
	this.owner = owner;
	this.serial = serial;
	this.saved = saved;
	this.valid = valid_contact;
	this.winked = winked;
	this.jobs = jobs;
}

Contact_Widget.prototype.new_account = function (root) {
	_get(root).innerHTML = this.wrap_html();
	_get('contacts_wrap').innerHTML = this.new_account_html();
}

Contact_Widget.prototype.show_all = function (root) {
	_get(root).innerHTML = this.wrap_html();
	_get('contacts_wrap').innerHTML = this.full_list_html();
}

Contact_Widget.prototype.job_account_contacts = function (root) {
	_get(root).innerHTML = this.wrap_html();
	_get('contacts_wrap').innerHTML = this.job_account_html();
}

Contact_Widget.prototype.show_jobs = function (root) {
	_get('contact_navigation').innerHTML = this.navigation('jobs');
	_get('contacts_detail').innerHTML = this.jobs_list_html();
}

Contact_Widget.prototype.show_winks = function (root) {
	_get('contact_navigation').innerHTML = this.navigation('winks');
	_get('contacts_detail').innerHTML = this.winks_list_html();
}

Contact_Widget.prototype.show_valid = function (root) {
	_get('contact_navigation').innerHTML = this.navigation('valid');
	_get('contacts_detail').innerHTML = this.valid_list_html();
}

Contact_Widget.prototype.guest_contact = function (root) {
	_get(root).innerHTML = this.guest_html();
}

Contact_Widget.prototype.guest_jobs_contact = function (root) {
	_get(root).innerHTML = this.guest_html();
}

Contact_Widget.prototype.contact_message = function (root) {
	_get('contacts_wrap').innerHTML = this.input_message_html();
	_get('contacts_wrap').style.display = "block";
	_get('button_wrap').innerHTML = this.input_message_button();
}

Contact_Widget.prototype.post_job = function (root) {
	_get('contacts_wrap').innerHTML = this.input_job_html();
	_get('contacts_wrap').style.display = "block";
	_get('button_wrap').innerHTML = this.input_job_button();
}

Contact_Widget.prototype.wrap_html = function () {

	var html = "";
	
	html += "<div style=\"height: 100%; color: #CCC\">";
	html += "<b>Contact Board</b>";
	html += "<div style=\"border-bottom: 1px solid #666; margin-right: 5px;\">";
	html += "<div id=\"contacts_wrap\" class=\"contact_content\" style=\"border-bottom: 1px solid #333; color: #CCC\"></div>";
	html += "</div>";
	html += "</div>";
	return html;
}

Contact_Widget.prototype.guest_html = function (jobs) {

	var html = "<div style=\"background-color: #777; border-top: 1px solid #888; border-left: 1px solid #888; border-bottom: 1px solid #444; border-right: 1px solid #333; padding: 4px; height: 100%; color: #CCC\">";
	html += "<b>Contact Board</b> | " + "<span style=\"font-size: 10px\">";
	
	if(this.valid && !this.jobs) {
		html += "post a <a class=\"white\" onClick=\"contact_message(" + this.serial + ")\">Message</a>";
	}
	
	if(this.jobs) {
		html += "post a <a class=\"white\" onClick=\"guest_post_job(" + this.serial + ")\">Job</a>"; 
	}
	
	if(!this.valid && !this.jobs) {
		if(!this.winked) {
			html += "give a <a class=\"white\" onClick=\"wink_contact(" + this.serial + ",'wink')\">Wink</a>";
		}
	}
	
	html += "</span>";
	
	html += "<div style=\"border-bottom: 1px solid #888; border-right: 1px solid #888; border-left: 1px solid #333; border-top: 1px solid #333;\">";
	html += "<div id=\"contacts_wrap\" style=\"color: #CCC; display: none;\">";
	
	html += "<div style=\"font-size: 10px\">";
	html += "<textarea style=\"width: 96%; height: 80%\" class=\"clean\"></textarea><br /></div>";
	
	html += "</div>";
	html += "</div>";
	html += "<div id=\"button_wrap\">";
	
	if(!this.saved) {
		html += "<span style=\"font-size: 10px\">[+] <a class=\"white\" onClick=\"save_contact(" + this.serial + ")\">Save Contact</a></span>";
	}
	html += "</div>";
	html += "</div>";
	
	return html;
}

Contact_Widget.prototype.input_job_button = function () {
	var html = "<input style=\"margin: 3px\" type=\"submit\" class=\"button\" value=\"post\" onClick=\"input_job_post('" + this.serial + "')\"/>";
	return html;
}

Contact_Widget.prototype.input_job_html = function () {
	var html = "<select id=\"job_post_select\" style=\"width: 100%\">";
	for(var x=0; x<this.jobs.length;x++) {
		html += "<option value=\"" + this.jobs[x].job_id + "\">" + this.jobs[x].job_name + "</option>";
	}
	html += "</select><br />";
	return html;
}

Contact_Widget.prototype.input_message_button = function () {
	var html = "<input style=\"margin: 3px\" type=\"submit\" class=\"button\" value=\"post\" onClick=\"input_contact_message('" + this.serial + "')\"/>";
	return html;
}

Contact_Widget.prototype.input_message_html = function () {
	var html = "<textarea id=\"message_text\" class=\"clean\" style=\"width: 100%; height: 160px;\"></textarea><br />";
	return html;
}

Contact_Widget.prototype.new_account_html = function () {
	var html = "<div style=\"height: 40px;\" valign=\"middle\"><div style=\"background-color: #222; text-align: center\">You do not have any contacts.</div></div><hr style=\"border: 1px dotted #333\"/>";
	return html;
}

Contact_Widget.prototype.navigation = function (type) {

	switch (type) {
		case "jobs": 
			var html = "<div onClick=\"show_all_contacts()\" class=\"tab\">History</div>";
			html += "<div onClick=\"show_jobs_contacts()\" class=\"active_tab\">Jobs</div>";
			html += "<div onClick=\"show_winks_contacts()\" class=\"tab\">Winks</div>";
			html += "<div onClick=\"show_valid_contacts()\" class=\"tab\">Contacts</div>";
			break;
		case "winks": 
			var html = "<div onClick=\"show_all_contacts()\" class=\"tab\">History</div>";
			html += "<div onClick=\"show_jobs_contacts()\" class=\"tab\">Jobs</div>";
			html += "<div onClick=\"show_winks_contacts()\" class=\"active_tab\">Winks</div>";
			html += "<div onClick=\"show_valid_contacts()\" class=\"tab\">Contacts</div>";
			break;
		case "valid": 
			var html = "<div onClick=\"show_all_contacts()\" class=\"tab\">History</div>";
			html += "<div onClick=\"show_jobs_contacts()\" class=\"tab\">Jobs</div>";
			html += "<div onClick=\"show_winks_contacts()\" class=\"tab\">Winks</div>";
			html += "<div onClick=\"show_valid_contacts()\" class=\"active_tab\">Contacts</div>";
			break;
		default: 
			var html = "<div onClick=\"show_all_contacts()\" class=\"active_tab\">History</div>";
			html += "<div onClick=\"show_jobs_contacts()\" class=\"tab\">Jobs</div>";
			html += "<div onClick=\"show_winks_contacts()\" class=\"tab\">Winks</div>";
			html += "<div onClick=\"show_valid_contacts()\" class=\"tab\">Contacts</div>";
	}
	
	return html ;
}


Contact_Widget.prototype.job_account_html = function () {
	var contacts_found = false;
	var html = "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\"><tr><td valign=\"top\">";
	html += "<div id=\"contact_navigation\" style=\"width: 90px; border-right: 0px solid #333\">";
	html += "<div class=\"active_tab\">Contacts</div>";
	html += "</div>";
	html += "</td><td width=\"100%\">";
	
	html += "<div id=\"contacts_detail\" style=\"height: 100%\">";
	html += "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\" style=\"padding: 3px; background-color: #333; border-top: 1px solid #666\">";
	for(var x=0;x<this.contacts.length;x++) {
		contacts_found = true;
		var serial = this.contacts[x].serial;
		var type = this.contacts[x].sender_type;
		var available = this.contacts[x].sender_avail;
		var valid = this.contacts[x].valid;
		var bg_color = '#666';
		var color = '#222';
		
		html += "<tr><td style=\"background-color: #222; color: #EEE; border-bottom: 1px solid #333\"><span class=\"" + link_class(type) + "\">&nbsp;--&nbsp;</span></td>";
		html += "<td style=\"padding-left: 4px; background-color: " + bg_color + "; color:" + color + "; border-bottom: 1px solid #333\" width=\"100%\"><a class=\"" + link_class(type) + "\" href='../index.php?u_id=" + topcode(serial) + "&t=" + topcode(type)  + "&av=" + topcode(available) + "'>" + this.contacts[x].sender + "</a>";
		html += " | <span style=\"font-size: 10px\">" + raw_date(this.contacts[x].date) + "</span><br />";
		html += "</td></tr>";
	}
	
	if(!contacts_found) {
		html += "You do not have any contacts.";
	}
	
	html += "</td></tr>";
	html += "</table></div>";
	html += "</td></tr></table>";
	return html;
}

Contact_Widget.prototype.full_list_html = function () {
	var html = "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\"><tr><td valign=\"top\" style=\"background-color: #444\">";
	html += "<div id=\"contact_navigation\" style=\"width: 90px; border-right: 0px solid #333; background-color: #555\">";
	html += this.navigation();
	html += "</div>";
	html += "</td><td width=\"100%\">";
	
	html += "<div id=\"contacts_detail\" style=\"height: 100%\"><table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\" style=\"padding: 3px; background-color: #333; border-top: 1px solid #666\"><tr>";
	for(var x=0;x<this.contacts.length;x++) {
		if(this.contacts[x].sender && this.contacts[x].sender != 'undefined' ) {
			var serial = this.contacts[x].serial;
			var type = this.contacts[x].sender_type;
			var available = this.contacts[x].sender_avail;
			var valid = this.contacts[x].valid;
			var bg_color = '#555';
			var color = '#222';
			if(valid >= 1) {
				bg_color = '#444';
				color = '#EEE';
			}
			html += "<td align=\"center\" style=\"background-color: #222; color: #EEE; border-top: 1px solid #444; border-bottom: 1px solid #333\"><span class=\"" + link_class(type) + "\">&nbsp;--&nbsp;</span></td>";
			html += "<td style=\"background-color: " + bg_color + "; color:" + color + "; border-top: 1px solid #666; border-bottom: 1px solid #333; padding-left: 3px\" width=\"100%\"><a class=\"" + link_class(type) + "\" href='../index.php?u_id=" + topcode(serial) + "&t=" + topcode(type)  + "&av=" + topcode(available) + "'>" + this.contacts[x].sender + "</a>";
			html += " | <span style=\"font-size: 10px\">" + raw_date(this.contacts[x].date) + "</span><br />";
			if(this.contacts[x].data && this.contacts[x].data != 'undefined') {
				html += "'" + this.contacts[x].data + "'";
			}
			
			if(!valid || valid == '0') {
				html += "<div style=\"font-size: 10px\"><a class=\"" + link_class(type) + "\" onClick=\"validate_contact(" + serial + ", 'update')\">[+] Save Contact</a></div>";
			}
		} else {
			html +=  "<td align=\"center\" style=\"background-color: #0033FF; color: #EEE; border-top: 1px solid #3366CC; border-bottom: 1px solid #333;\">&nbsp;JOB&nbsp;</td>";
			html += "<td style=\"border-top: 1px solid #666; border-bottom: 1px solid #333; background-color: #444; padding-left: 3px\" width=\"100%\"><a href=\"../jobs/index.php?job_id=" +topcode(this.contacts[x].job_id) + "\"><b>" + this.contacts[x].job_name + "</b></a><div style='padding: 2px'>"+ "'" + this.contacts[x].job_info + "'" + "</div>";
		}
		html += "</td></tr><tr>";
	}
		html += "</td></tr>";
		html += "</table></div>";
		
		html += "</td></tr></table>";
	return html;
}

Contact_Widget.prototype.jobs_list_html = function () {
	var jobs_found = false;
	var html = "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\" style=\"padding: 3px; background-color: #333; border-top: 1px solid #666;\"><tr>";
	for(var x=0;x<this.contacts.length;x++) {
		if(!this.contacts[x].sender || this.contacts[x].sender == 'undefined' ) {
			jobs_found = true;
			html +=  "<td align=\"center\" style=\"background-color: #0033FF; color: #EEE; border-top: 1px solid #3366CC; border-bottom: 1px solid #333;\">&nbsp;JOB&nbsp;</td>";
			html += "<td style=\"border-top: 1px solid #666; border-bottom: 1px solid #333; background-color: #444; padding-left: 3px\" width=\"100%\"><a href=\"../jobs/index.php?job_id=" +topcode(this.contacts[x].job_id) + "\"><b>" + this.contacts[x].job_name + "</b></a><div style='padding: 2px'>"+ "'" + this.contacts[x].job_info + "'" + "</div>";
		}
		html += "</td></tr><tr>";
	} 
	
	if(!jobs_found) {
		html += "<td>No Jobs have been posted.";	
	}
	html += "</td></tr>";
	html += "</table>";
	return html;
}

Contact_Widget.prototype.winks_list_html = function () {
	var winks_found = false;
	
	var html = "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\" style=\"padding: 3px; background-color: #333; border-top: 1px solid #666\"><tr>";
	for(var x=0;x<this.contacts.length;x++) {
		if(this.contacts[x].sender && this.contacts[x].sender != 'undefined' ) {
			var serial = this.contacts[x].serial;
			var type = this.contacts[x].sender_type;
			var available = this.contacts[x].sender_avail;
			var valid = this.contacts[x].valid;
			var bg_color = '#444';
			var color = '#EEE';
			if(!valid || valid == '0') {
				winks_found = true;
				html += "<td align=\"center\" style=\"background-color: #222; color: #EEE; border-top: 1px solid #444; border-bottom: 1px solid #333\"><span class=\"" + link_class(type) + "\">&nbsp;--&nbsp;</span></td>";
				html += "<td style=\"background-color: " + bg_color + "; color:" + color + "; border-top: 1px solid #666;  border-bottom: 1px solid #333; padding-left: 3px\" width=\"100%\"><a class=\"" + link_class(type) + "\" href='../index.php?u_id=" + topcode(serial) + "&t=" + topcode(type)  + "&av=" + topcode(available) + "'>" + this.contacts[x].sender + "</a>";
				html += " | <span style=\"font-size: 10px\">" + raw_date(this.contacts[x].date) + "</span><br />";
				if(this.contacts[x].data && this.contacts[x].data != 'undefined') {
					html += "'" + this.contacts[x].data + "'";
				}
				html += "<div style=\"font-size: 10px\"><a class=\"" + link_class(type) + "\" onClick=\"validate_contact(" + serial + ", 'update')\">[+] Save Contact</a></div>";
			}
		}
	}
	
	if(!winks_found) {
		html += "<td>No Winks have been posted.";	
	}
	html += "</td></tr>";
	html += "</table>";
	return html;
}

Contact_Widget.prototype.valid_list_html = function () {
	var winks_found = false;
	
	var html = "<table border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\" height=\"100%\" width=\"100%\" style=\"padding: 3px; background-color: #333; border-top: 1px solid #666\"><tr>";
	for(var x=0;x<this.contacts.length;x++) {
		if(this.contacts[x].sender && this.contacts[x].sender != 'undefined' ) {
			var serial = this.contacts[x].serial;
			var type = this.contacts[x].sender_type;
			var available = this.contacts[x].sender_avail;
			var valid = this.contacts[x].valid;
			
			if(valid && valid != 0 && valid != 'undefined') {
				if(!this.contacts[x].data && this.contacts[x].data != 'undefined') {
					winks_found = true;
					html += "<td align=\"center\" style=\"background-color: #222; color: #EEE; border-top: 1px solid #444; border-bottom: 1px solid #333\"><span class=\"" + link_class(type) + "\">&nbsp;" + "--" + "&nbsp;</span></td>";
					html += "<td style=\"border-top: 1px solid #666; border-bottom: 1px solid #333; background-color: #444; padding-left: 3px\"  width=\"100%\"><a class=\"" + link_class(type) + "\" href='../index.php?u_id=" + topcode(serial) + "&t=" + topcode(type)  + "&av=" + topcode(available) + "'>" + this.contacts[x].sender + "</a>";
					html += " | <span style=\"font-size: 10px\">" + raw_date(this.contacts[x].date) + "</span><br />";
				}
			}
		}
		html += "</td></tr><tr>";
	}
	
	if(!winks_found) {
		html += "<td>No Contacts have been posted.";	
	}
	html += "</td></tr>";
	html += "</table>";
	return html;
}