/*******************************************************************************************************************
// just gets rid of border & bg image of search box to give impression that is selected to user
********************************************************************************************************************/

function resetSearchRateOnly(){

//document.myform.searchbox.style.
document.getElementById('resetsearch').innerHTML="";
//document.getElementById('resetsearch').style.color="#ffffff";
document.myform.searchbox.style.fontWeight='normal';
document.myform.searchbox.style.borderColor="#000000";
document.myform.searchbox.style.backgroundImage='url(../images/search_background.png)';
document.getElementById('selectplacebtn_img').style.visibility="visible";
document.getElementById('selectplacebtn_img').style.width='134px';
}

/*******************************************************************************************************************
// just gets rid of border & bg image of search box to give impression that is selected to user
********************************************************************************************************************/

function rateOnlySelectPlace(){

//document.myform.searchbox.style.
//document.getElementById('searchbox').style.borderColor="#ffffff";
document.myform.searchbox.style.borderColor="#ffffff";
document.myform.searchbox.style.backgroundImage='url()';
//document.getElementById('searchbox').style.backgroundImage='url()';
document.myform.searchbox.style.fontWeight='bold';
document.getElementById('selectplacebtn_img').style.visibility="hidden";
document.getElementById('selectplacebtn_img').style.width='0px';

//document.getElementById('resetsearch').style.color="#002BB8";
document.getElementById('resetsearch').innerHTML="Change your selection";
}



/*******************************************************************************************************************
// is called when combo for extra category filter on comments2.php clicked
********************************************************************************************************************/

function extraCategFilter(state, place){
	var temp=document.myform.extracateg.value;
	location.href = 'comments2.php?state='+state+'&place='+place+'&category='+temp;	
}

/*******************************************************************************************************************
// is used when searching for a rank for all US
********************************************************************************************************************/

function rankAnchorLinkUS(display,num_records){

	
	if (num_records > display) 
	{ // More than 1 page.
		num_pages = Math.ceil(num_records/display);
	}
	else
	{
		num_pages = 1;
	}
	
	rank=document.forms['myform']['rank'].value-1
	
	if(!isFinite(rank)){
		alert("You must enter a valid rank.")
		location.href = 'index.php';
	}else{
		s=(Math.floor(rank/display)*display);
		np=num_pages;
		anchornum=rank+1;	
		passedVals='s='+s+'&np='+np+'#anchor'+anchornum;
		location.href = 'index.php?'+passedVals;		
	}

}

/*******************************************************************************************************************
//is used when searching for a rank for all US
********************************************************************************************************************/

function rankAnchorLinkState(display,num_records,state){

	if (num_records > display) 
	{ // More than 1 page.
		num_pages = Math.ceil(num_records/display);
	}
	else
	{
		num_pages = 1;
	}
	
	rank=document.forms['myform']['rank'].value-1
	
	if(!isFinite(rank)){
		alert("You must enter a valid rank.")
		location.href = 'state.php';
	}else{
		s=(Math.floor(rank/display)*display);
		np=num_pages;
		anchornum=rank+1;	
		passedVals='state='+state+'&s='+s+'&np='+np+'#anchor'+anchornum;
		location.href = 'state.php?'+passedVals;		
	}

}


/*******************************************************************************************************************
//Validating mm/yyyy for fame.php
********************************************************************************************************************/

var dtCh= "/";
var minMonth=1;
var maxMonth=12;
var minYear=2008;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

// Checking if date is all numbers apart from '\' so here returns date without '\'
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isDate(myDate){

	var pos1=myDate.indexOf(dtCh);
	var strMonth=myDate.substring(0,pos1);
	var strYear=myDate.substring(pos1+1);	
	
	month=parseInt(strMonth);
	year=parseInt(strYear);
		
	
	// Check the month
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	
	// Check the year
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	
	// Make sure there is only one '\' and that the date when stripped of '\' is all numbers
	if (myDate.indexOf(dtCh,pos1+1)!=-1 || isInteger(stripCharsInBag(myDate, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}	
	return true;		
		
}

function validatedate(){
	
	var myDate=document.myform.famedate.value;
	var pos1=myDate.indexOf(dtCh);
	var strMonth=myDate.substring(0,pos1);
	var strYear=myDate.substring(pos1+1);	



	if(isDate(myDate)==true){
		passedVals='year='+strYear+'&month='+strMonth;
		location.href = 'fame.php?'+passedVals;				
	}
	
	
}

/*******************************************************************************************************************
//set session cookie for rate page
********************************************************************************************************************/
function setCookie(c_name,value)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value);
}



