function cnt(w,x,tot)
{
	var y=w.value;
	var r = 0;
	var words = '';
	a=y.replace(/\s/g,' ');
	a=a.split(' ');
	for (z=0; z<a.length; z++) 
	{	
		if (a[z].length > 0) 
		{
			words += a[z]+" ";
			/*if(r>tot)
			{				 
				
				x.value=r;
			}
			else
			{*/
			r++;
			x.value=r;
			//}
		}
		else
		{
			x.value=r;
		}
	}
	
	
} 

function countTotal(w,x,c,bb,tot,pakName)
{
	var cnt = '0';
	cnt = parseInt(c.value)+parseInt(bb.value);
	//alert(cnt);
	if(cnt>tot)
	{
		//w.disabled=true;
		//alert("You can enter "+tot+" words for package '"+pakName+"'.");
		var y=w.value;
		var words = '';
		a=y.replace(/\s/g,' ');
		a=a.split(' ');
		for (z=0; z<a.length; z++) 
		{		
			if (a[z].length > 0 && a[z].length<tot) 
			{
				words += a[z]+" ";			
			}
		}
		
		//var lastWordLength = a[z-1].length+2;				
		//var RemainingWords = words.substring(0, (words.length-lastWordLength));
		//var RemainingWords = words;
		//w.value = RemainingWords;
		//break;
		
		//var RemainingWords = words.substring(0, (words.length-3));
		//w.value = RemainingWords;
		//x.value=parseInt(x.value)-1;
		//w.disabled=false;	
	}
}
/*
 * Parameters
 *	w: name of textarea where text enter
 *	x: name of text box where count display corresponding to textarea
 *	c: name of first textbox where count display
 *	bb: name of second text box where count display
 *	tot: total number of words count
 *	pakName: Package name
 */
function callBoth(w,x,c,bb,tot,pakName,totlCount)
{
	if(tot == '')
	{
		tot = '0';
	}
	cnt(w,x,tot);
	countTotal(w,x,c,bb,tot,pakName);
	totlCount.value = parseInt(c.value)+parseInt(bb.value);
}

function getPkg(pkg,hiddTot,hiddName)
{
	
	var pkgVal = pkg.value;
	
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    try
	      {
	      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    catch (e)
	      {
	      alert("Your browser does not support AJAX!");
	      return false;
	      }
	    }
	  }
	  xmlHttp.onreadystatechange=function()
	    {
	    if(xmlHttp.readyState==4)
	      {
		      var strTotal=xmlHttp.responseText;
		      //alert(strTotal);
		      var splTotal = strTotal.split(",");
		      var tot = splTotal['0'];
		      var pakName = splTotal['1'];
		      hiddTot.value = tot;
		      hiddName.value = pakName;
	      }
	    }
	  xmlHttp.open("GET","pakValue.php?pkgVal="+pkgVal,true);
	  xmlHttp.send(null);
}

function countFeature() 
{
  var hiddIdCT = document.getElementById('hiddIdCT').value;
  var tot='0';
  var err='0';
  for(i='1';i<hiddIdCT;i++)
  {
    
    if(document.getElementById('fact'+i).checked)
    {
      tot++;
    }
    if(tot>'8')
    {
      err='1';
      break;
    }
  }
  //alert(i);
  if(err == '1')
  {
    //alert("1111");
    return false;
  }
}
function renewPage(cotVal)
{
  if(cotVal == '')
  {
    alert("Please select any package");
    return false;
  }
  else
  {
  document.forms['upgradeCottage'].submit();
  }
}
function newcottage(val)
{
  if(document.getElementById('addNewCot').checked)
  {
    document.location.href="index.php?sec=add";
  }
}
function checkSearch()
{
  rating_id = document.getElementById('rating_id').value;
  ratingto_id = document.getElementById('ratingto_id').value;
  if(rating_id == '0' && ratingto_id != '0')
  {
    alert("Please select star rating From. ");
    return false;
  }
  else if(rating_id != '0' && rating_id != 'all' && ratingto_id != '0' && ratingto_id < rating_id)
  {
    alert("Star rating From can not be greater then To. ");
    return false;
  }
  return true;
}
