/* CONFIG FOR JS */
var _path = '/';

function isset(varname)
{
	if(typeof( window[ varname ] ) != "undefined") return true;
	else return false;
}

function sure(msg)
{
	if (msg == undefined)
	{
		var msg = 'Are you sure?';
	}

	var ask = confirm(msg);
	if (ask == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function showstates()
{
	var country = $("#country").val();
	changecountry(country);

	if (country === 'US')
	{
		$("#state-p").fadeIn();
		$("#states").removeAttr("disabled");
	}
	else
	{
		if ($("#state-p").css("display") != 'none' )
		{
			$("#state-p").fadeOut();
			$("#states").attr("disabled","disabled");
		}
	}
}

function changecountry(country)
{
	country = country.toLowerCase();
	if ( country == '')
	{
		$("#countryimg").remove();
	}

	if ($("#countryimg").length > 0 )
	{
		$("#countryimg").attr("src","/images/flags/"+country+".gif");
	}
	else
	{
		$("#country").after("<img style=\"margin-left:5px;\" src=\"/images/flags/"+country+".gif\" id=\"countryimg\" alt=\"\"/>");
	}
}

function cp_imadd()
{
	var count = $(".ims").length;

	if ((count+1) > 5)
	{
		alert('You can only add up to 5 different type of IM Screen Names');
		return false;
	}

	var height = $("#im_opt").children("strong").css("height");
	var height2 = height.replace(/px/,'');

	var newheight = parseInt(height2) + 20 +"px";

	$("#im_opt").children("strong").css("height",newheight);

	var next = count+1;

	$(".ims:last").after("<span class=\"ims\">\n<input type=\"text\" name=\"im["+next+"]\" class=\"inputtext\" style=\"width:120px;\" />\n<select name=\"im_prog["+next+"]\" id=\"im_prog_"+next+"\"><option value=\"aim\">AIM</option><option value=\"skype\">Skype</option><option value=\"msn\">MSN</option><option value=\"ym\">Yahoo!</option><option value=\"gtalk\">gTalk</option></select>\n</span>");

	$(".ims:last").hide();
	$(".ims:last").slideDown('fast');

	return false;
}

/*
* resizehandle.js (c) Fil 2007, plugin pour jQuery ecrit
* a partir du fichier resize.js du projet DotClear
* (c) 2005 Nicolas Martin & Olivier Meunier and contributors
*/
jQuery.fn.resizehandle = function() {
return this.each(function() {
var me = jQuery(this);
me.after(
  jQuery('<div class="resizehandle" title="Click and hold to resize textbox"></div>')
  .bind('mousedown', function(e) {
	var h = me.height();
	var y = e.clientY;
	var moveHandler = function(e) {
	  me
	  .height(Math.max(20, e.clientY + h - y));
	};
	var upHandler = function(e) {
	  jQuery('html')
	  .unbind('mousemove',moveHandler)
	  .unbind('mouseup',upHandler);
	};
	jQuery('html')
	.bind('mousemove', moveHandler)
	.bind('mouseup', upHandler);
  })
);
});
}

function useropt()
{
	$("#useropt").toggle();
}

function changebg(what,to)
{
	switch (to)
	{
		case 'yes' :	var color = '#F2FFE4 url(\'/images/sign_yes.png\') no-repeat 95% 50%'; break;
		case 'no':		var color = '#FFF2F2 url(\'/images/sign_no.png\') no-repeat 95% 50%'; break;
		case 'def':		var color = '#F8FAFD'; break;
	}
	
	//$('#'+what).parent().css("background-color",color);
	$('#'+what).parent().css("background",color);
	$('#'+what).focus();
	
	if ( to == 'no')
	{
		$("#"+what).parent().find("small").css("color","red");
		$("#"+what).parent().find("span").css("color","red");
	}
	else
	{
		$("#"+what).parent().find("small").css("color","#9e9e9e");
		$("#"+what).parent().find("span").css("color","#9e9e9e");
	}
}

function locksubmit(what)
{
	if ( what == 1 )
	{
		$("#submitbutton").attr("disabled","disabled");
	}
	else
	{
		$("#submitbutton").removeAttr("disabled");
	}
}

function sendresume(id)
{
	var data = 'do=send&id='+id;

	var html = '';
	var html = $.ajax({
					   type: "POST",
					   url: _path + "ajax.resume.php",
					   data: data,
					   async: false
					 }).responseText;
	
	
	if (html != 'ok')
	{
		alert(html);
	}
	else
	{
		$(".postjob").addClass("disabled");
		$(".postjob").empty();
		$(".postjob").html("<a>Resume Sent</a>");
		$("#content").prepend("<p id=\"resumenotify\" class=\"notes\">Your resume has been sent</p>");
		setTimeout("change("+id+")",1500);
		
		change = function () {
			$("#resumenotify").fadeOut('fast');
		}
	}

	return false;
}

function deleteping(id)
{
	var ask = sure();

	if ( sure === false )
	{
		return false;
	}
	
	var html = '';	
	var html = $.ajax({
					   type: "GET",
					   url: _path + 'ajax.resume.php?do=delete',
					   data: 'id='+id,
					   async: false,
					   global: true
					 }).responseText;
	
	var test2 = html.search(/No resumes/);
	if ( test2 != -1)
	{
		$(".resumelist").append(html);
		
		$("#resumeping-"+id).fadeOut('fast');
		return false;
	}
	
	

	var test = html.search(/ok/);
	if ( test == -1 )
	{
		alert(html);
		return false;
	}
	
	$("#resumeping-"+id).fadeOut('fast');

	return false;
}