function getTotal(frm, obj, mode)
{
	//$(tgt).value = $(id).value;
	frm.total_cost.value = obj.value;
	frm.amount.value = (obj.value/45).toFixed(2);
	frm.item_name.value = obj.getAttribute('product');
	var return_url = 'http://www.jobsshell.com/booster/payments/md/'+mode+'/pd/'+obj.getAttribute('product')+'/pr/'+frm.amount.value;
	//frm.return.value = return_url;
	$('paypal_return').value = return_url;
	frm.notify_url.value = return_url;
}

function setMaximumSelected(amount,element)
{
	var itemsSelected = [];
	for (var i=0;i<element.options.length;i++) {
		if (element.options[i].selected) itemsSelected[itemsSelected.length]=i;

	}

	if (itemsSelected.length>3) {
		itemsSelected = element.getAttribute("itemsSelected").split(",");

		for (i=0;i<element.options.length;i++) {
			element.options[i].selected = false;
		}

		for (i=0;i<itemsSelected.length;i++) {
			element.options[itemsSelected[i]].selected = true;
		}			
	} else {
		element.setAttribute("itemsSelected",itemsSelected.toString());	
	}
}

function showTr(type)
{
	$(type+'_cnt').value = Number($(type+'_cnt').value) + 1;	
	var cnt = $(type+'_cnt').value;
	$(type+'_tr_'+cnt).show();

	if(cnt == 3)
		$(type+'_add').disabled = true;
}

function showTr1(type)
{
	$(type+'_cnt').value = Number($(type+'_cnt').value) + 1;	
	var cnt = $(type+'_cnt').value;

	$(type+'_tr_'+cnt).show();
	if(cnt == 5)
		$(type+'_add').disabled = true;
}

function hideTr(type)
{
	$(type+'_cnt').value = Number($(type+'_cnt').value) - 1;	
	var cnt = $(type+'_cnt').value;
	alert('close => '+cnt);
	//if(cnt == 1)
	//	$(type+'_tr_close').hide();
	$(type+'_tr_'+cnt).hide();
	if(cnt < 3)
		$(type+'_add').disabled = false;
}

function changeSubCategory(id_sub_cat)
{
	var id_category = $('id_category').value;
	new Ajax.Request('/jobs/getsubcategory',
  {
    method:'get',
    parameters: {id_category: id_category, id_sub_category: id_sub_cat },
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      $('td_sub_cat').innerHTML = response;
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}

function changeLocation(id_location)
{
	var id_country = $('id_country').value;
	new Ajax.Request('Index.php/employee/getlocation',
  {
    method:'post',
    parameters: {id_country: id_country, id_location: id_location},
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      $('td_location').innerHTML = '';
	  $('td_location').innerHTML = response;
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}

function funDurCost(cost, id, form)
{
	form.total_cost.value = cost;
	form.id_plan_duration.value = id;
}

function funPostCost(cost, id, form)
{
	document.getElementById('PostCostTD').innerHTML =  cost;
	form.total_cost.value = eval(eval(form.pre_cost.value) + eval(cost));
	form.id_plan_posting.value = id;
}

function checkAvailable(username)
{	
	//alert(trim(username))
	if(trim(username))
	{
		new Ajax.Request('Index.php/employee/checkAvailable',
		{
			method:'post',
			parameters: {username: username},
			onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
			  $('available_div').innerHTML = response;
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
	else
		$('available_div').innerHTML = "Username can not be blank";
}

// LTrim(string) : Returns a copy of a string without leading spaces.

function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.

function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces

function trim(str) {

   return rtrim(ltrim(str));
}

function GetSubCategory(val,action)
{	
	//alert(trim(username))
	if(trim(val))
	{
		new Ajax.Request(action,
		{
			method:'post',
			parameters: {category_id: val},
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  $('div-subcat').innerHTML = response;
			},onFailure: function(){ alert('Something went wrong...')}});
	}
}