// JavaScript Document

// CHECKING  FOR LOGIN DETAIL ////////////////////////////////////////////////////////////////////////////////////////////////////

function chk_login_info(th)
{
	if(Trim(th.UserName.value) == "")
	{
		alert("Plese Enter Your Username First !");
		th.UserName.select();
		return false;
	}			
	if(Trim(th.Password.value) == "")
	{
		alert("Plese Enter Your Password First !");
		th.Password.select();
		return false;
	}								
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// FOR CREATE TRIP ////////////////////////////////////////////////////////////////////////////////////////////////////

function create_trip(th)
{
	if(th.TripTitle.value == "")
	{
		alert("Plese Give Your Trip Title");	
		th.TripTitle.select();
		return false;
	}
	len =document.frm["Team[]"].length
	i = 0
	b=0;
	for (i = 0; i < len; i++) {
		if (document.frm["Team[]"][i].selected)
		{
			b=1;
			break;
		}			
	}
	if(b==0)
	{
		alert("Please select Trip Type");
		return false;			
	}	
	len1 =document.frm["tripact[]"].length
	m = 0
	t=0;
	for (t = 0; t < len1; t++) {
		if (document.frm["tripact[]"][t].selected)
		{
			m=1;
			break;
		}			
	}
	if(m==0)
	{
		alert("Please Select Trip Activities");
		return false;			
	}	
	if(th.region.value == "")
	{
		alert("Plese Select Trip Region");	
		th.region.select();
		return false;
	}
	if(th.country.value == "")
	{
		alert("Plese Select Trip Country");	
		th.country.select();
		return false;
	}
	/*if(Trim(th.WerRuGo.value) == "")
	{
		alert("Plese Enter Where Are You Go");	
		th.WerRuGo.select();
		return false;
	}*/	
	if(Trim(th.date.value) != "" && Trim(th.date1.value) != "")
	{
		start_date1 = th.date.value.split("-");
		end_date1 = th.date1.value.split("-");	
		start_date = start_date1[2]+start_date1[1]+start_date1[0];
		end_date = end_date1[2]+end_date1[1]+end_date1[0];	
		if(start_date > end_date)
		{
			alert("Start date must be smaller than end date !");
			th.date.focus();
			th.date.select();
			return false;
		}
	}
}
function valDelForm()
{
	  var filledIn = 0;    
		//theForm=document.frm;
		for (var counter=0; counter<document.frm.ActFile.length; counter++)
		{
     		
			val=document.frm.ActFile[counter].value;		
			if(val!="")
			{
				var temp = new Array();
				temp = val.split('.');
				t=temp[1];
				if(t=="jpg" || t=="JPG" || t=="gif" || t=="GIF" || t=="jpeg")
				{
					document.getElementById('act'+counter).innerHTML ="";									
				}
				else
				{
					document.getElementById('act'+counter).innerHTML =	"<strong>Please upload .jpg or .gif image</strong>";
					document.frm.ActFile[counter].select;
					filledIn+=1;
				}
			}			
			
     	}
		if(filledIn > 0)
		{
			alert("Please upload .jpg or .gif image");
			return false;
		}
		else
		{
			return true;
		}
}

function frmcheckactivity(th)
{
	
	if(document.frm.ActType.value == "" || document.frm.ActType.value == "1111111")
	{
		alert("Don't see your activity type here? Send us feedback at feedback@mytripguru.com. In the meantime, choose an activity type that fits best.");	
		document.frm.ActType.focus();
		return false;
	}
	if(document.frm.region.value == "")
	{
		alert("Plese Select Activity Region");	
		document.frm.region.select();
		return false;
	}
	if(document.frm.country.value == "")
	{
		alert("Plese Select Activity Country");	
		document.frm.country.select();
		return false;
	}
	if(document.frm.city.value == "")
	{
		alert("Plese Enter Activity City");	
		document.frm.city.select();
		return false;
	}	
	if(document.frm.ActDuration.value == "")
	{
		alert("Plese Enter Activity Duration");	
		document.frm.ActDuration.focus();
		return false;
	}	
	if(document.frm.ActDate.value == "")
	{
		alert("Plese Enter Activity Date");	
		document.frm.ActDate.select();
		return false;
	}
	if (isDate(document.frm.ActDate.value)==false){
		document.frm.ActDate.focus()
		return false
	} 	
	if(document.frm.ActTitle.value == "")
	{
		alert("Plese Enter Activity Name");	
		document.frm.ActTitle.focus();
		return false;
	}
	/*if(document.frm.ActReview.value == "")
	{
		alert("Plese Write Your Review");	
		document.frm.ActReview.focus();
		return false;
	}	*/
	if(document.frm.ActKeywords.value == "")
	{
		alert("Plese Summarize Review");	
		document.frm.ActKeywords.focus();
		return false;
	}
	if(document.frm.rating.value == "0")
	{
		alert("Plese Enter Activity Rating");	
		document.frm.rating.focus();
		return false;
	}
	return valDelForm();
	
	return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// CHECKING  FOR SIGNUP DETAIL ////////////////////////////////////////////////////////////////////////////////////////////////////
function chk_signup_info(th)
{
	if(Trim(th.UserName.value) == "")
	{
		alert("Plese Enter Your Username First !");
		th.UserName.select();
		return false;
	}
	else if(Trim(th.Password.value) == "")
	{
		alert("Plese Enter Your Password First !");
		th.Password.select();
		return false;						
	}
	else if(Trim(th.Email.value) == "")
	{
		alert("Plese Enter Your Email Address First !");
		th.Email.select();
		return false;
	}
	else if(!emailCheck(Trim(th.Email.value)))
	{
		th.Email.select();
		return false;							
	}
	else if(Trim(th.code.value) == "")
	{
		alert("Plese Enter Verification Code !");
		th.code.select();
		return false;
	}
	else if(th.terms.checked == false)
	{
		alert("Plese read and accept the Terms of Use !");
		th.terms.checked=true;
		return false;						
	}
	else
	{
		return true;
	}
}


function chk_Member_Persong_Info(th)
{
	if(Trim(th.MemFirstname.value) == "")
	{
		alert("Plese enter firstname and lastname !");
		th.MemFirstname.select();
		return false;
	}
	else if(Trim(th.MemName.value) == "")
	{
		alert("Plese Enter Your Username!");
		th.MemName.select();
		return false;
	}	
	else if(Trim(th.MemEmail.value) == "")
	{
		alert("Plese Enter Your Email Address First !");
		th.MemEmail.select();
		return false;
	}
	else if(!emailCheck(Trim(th.MemEmail.value)))
	{
		th.MemEmail.select();
		return false;							
	}
	else if(Trim(th.region.value) == "")
	{
		alert("Plese select region!");
		th.region.select();
		return false;
	}
	else if(Trim(th.country.value) == "")
	{
		alert("Plese select country!");
		th.country.select();
		return false;
	}
	else
	{
		return true;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////  COMMAN FUNCTION /////////////////////////////////////////////////////////////////////////////////////////////////

function emailCheck(s)
{
	if(!(s.match(/^[\w]+([_|\.-][\w]{1,})*@[\w]{2,}([_|\.-][\w]{1,})*\.([a-z]{2,4})$/i) ))
    {
		alert("Please Enter Valid Email Address");
		return false;
	}
	else
	{
		return true;
	}	
}


function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
} 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 /////////  SEARCH GURU FUNCTION /////////////////////////////////////////////////////////////////////////////////////////////////
 
 
function search_guru(field,val)
{
	if(field == 'region')
	{
		makePOSTRequest('search_guru.php','region=' + val , 'search_result');
	}

	if(field == 'state')
	{
		makePOSTRequest('search_guru.php','state=' + val , 'search_result');
	}
	if(field =='TrType')
	{
		makePOSTRequest('search_guru.php','TrType=' + val , 'search_result');								
	}
	if(field =='TrAct')
	{
		makePOSTRequest('search_guru.php','TrAct=' + val , 'search_result');								
	}								
} 
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
 /////////  RATING  FUNCTION /////////////////////////////////////////////////////////////////////////////////////////////////
   
   
	function selstar(rr,val) //Replaces the star image when selected.
	{
		var x = rr;
		for(var y=1;y<=val;y++)
		{
			document['image'+x+''+y].src="http://www.images.mytripguru.com/rating-img-hover.jpg";
		}
	}
	
	function remstar(rr,val) //Replaces the star image when unselected.
	{
		if(document.getElementById('rating').value == 0)
		{								 	
			var x =rr;
			for(var y=1;y<=val;y++)
			{
				document['image'+x+''+y].src="http://www.images.mytripguru.com/rating-img.jpg";
			}
		}
		else										
		{
			var x =rr;
			var starty =parseInt(document.getElementById('rating').value)+1;											
			for(var y=starty;y<=5;y++)
			{
				document['image'+x+''+y].src="http://www.images.mytripguru.com/rating-img.jpg";
			}
		
		}	
	}								
	function setrating(rr,val)
	{
		document.getElementById('rating').value = val;	
		var x = rr;
		for(var y=1;y<=val;y++)
		{
			document['image'+x+''+y].src="http://www.images.mytripguru.com/rating-img-hover.jpg";
		}
	}																 


  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function get1() {				
		rtid=document.frmtrip.sregion.value;
		ctid=document.frmtrip.scountry.value;
		ttid=document.frmtrip.striptype.value;
		atid=document.frmtrip.stripactivity.value;
		pgn=document.frmtrip.pn.value;
		var poststr="sregion="+rtid+"&scountry="+ctid+"&striptype="+ttid+"&stripactivity="+atid+"&pn="+pgn;
		makePOSTRequest3('browse-trip1.php', poststr,"content");		
}
function paging(pg)
{
	document.frmtrip.pn.value=pg;
	get1();
}
/*function get2(val) {				
		rtid=document.frmtrip.sregion.value;
		ctid=document.frmtrip.scountry.value;
		stid=document.frmtrip.sstate.value;
		<!--ttid=document.frmtrip.striptype.value;-->
		atid=document.frmtrip.stripactivity.value;
		sdid=document.frmtrip.sduration.value;
		pgn=document.frmtrip.pn.value;
		oby=document.frmtrip.orderby.value;
		sby=document.frmtrip.sortby.value;
		scid=document.frmtrip.scity.value;
		alctid=document.frmtrip.allcity.value;
		
		//var poststr="sregion="+rtid+"&scountry="+ctid+"&striptype="+ttid+"&stripactivity="+atid+"&pn="+pgn;
		if(val==1)
		{
			ctid="";
			atid="";
			stid="";
		}
		if(val==2)
		{
			atid="";
			stid="";
		}
		var poststr="sregion="+rtid+"&scountry="+ctid+"&sstate="+stid+"&scity="+scid+"&stripactivity="+atid+"&sduration="+sdid+"&pn="+pgn+"&orderby="+oby+"&sortby="+sby+"&allcity="+alctid;
		makePOSTRequest3('browse-gurus1.php', poststr,"container1","","",alctid);		
}*/
function get2(val) {				
		rtid=document.frmtrip.sregion.value;
		ctid=document.frmtrip.scountry.value;
		<!--ttid=document.frmtrip.striptype.value;-->
		atid=document.frmtrip.stripactivity.value;
		pgn=document.frmtrip.pn.value;
		//var poststr="sregion="+rtid+"&scountry="+ctid+"&striptype="+ttid+"&stripactivity="+atid+"&pn="+pgn;
		if(val==1)
		{
			ctid="";
			atid="";
		}
		if(val==2)
		{
			atid="";
		}
		var poststr="sregion="+rtid+"&scountry="+ctid+"&stripactivity="+atid+"&pn="+pgn;
		makePOSTRequest3('http://www.mytripguru.com/browse-gurus1.php', poststr,"container1");		
}

function paging1(pg)
{
	document.frmtrip.pn.value=pg;
	get2();
}
function get3(val) {
		rtid=document.frmtrip.sregion.value;
		ctid=document.frmtrip.scountry.value;
		stid=document.frmtrip.sstate.value;
		citid=document.frmtrip.scity.value;
		<!--ratid=document.frmtrip.srating.value;-->
		dtid=document.frmtrip.sduration.value;
		actid=eval(document.frmtrip.acid.value);		
		alltid=document.frmtrip.allcity.value;
		//alert(alltid);
		memaid=document.frmtrip.memberid.value;
		oby=document.frmtrip.orderby.value;
		sby=document.frmtrip.sortby.value;
		pgn=document.frmtrip.pn.value;
		if(val==1)
		{
			ctid="";
			dtid="";
			stid="";
			citid="";			
		}
		if(val==2)
		{
			dtid="";
			stid="";
			citid="";
		}
		if(val==3 || val==4 || val==5 )
			citid="";
		if(val==6)
		{
			actid="";
			ctid="";
			dtid="";
			stid="";
			rtid="";
			stid="";
		}
		
		var poststr="acid="+actid+"&memberid="+memaid+"&sregion="+rtid+"&scountry="+ctid+"&sduration="+dtid+"&pn="+pgn+"&scity="+citid+"&allcity="+alltid+"&sstate="+stid+"&orderby="+oby+"&sortby="+sby;
	//	var poststr="acid="+actid+"&memberid="+memaid+"&sregion="+rtid+"&scountry="+ctid+"&sduration="+dtid+"&pn="+pgn+"&allcity="+alltid+"&sstate="+stid+"&orderby="+oby+"&sortby="+sby;
		makePOSTRequest3('http://www.mytripguru.com/browse-type-activities1.php', poststr,"content","","",alltid);	
}
function paging3(pg)
{
	document.frmtrip.pn.value=pg;
	get3();
}
function getser() {				
		rkeyword=document.frmtrip.keyword.value;
		for (var i=0; i < document.frmtrip.searchtype1.length; i++)
		{
			if (document.frmtrip.searchtype1[i].checked)
			{
				document.frmtrip.searchtype.value = document.frmtrip.searchtype1[i].value;
			}
		}
		rsearchtype=document.frmtrip.searchtype.value;
		if(!document.frmtrip.pn.value)
			pgn=1;
		else
			pgn=document.frmtrip.pn.value;
		var poststr="keyword="+rkeyword+"&searchtype="+rsearchtype+"&pn="+pgn;
		rstate=document.frmtrip.state.value;
		if(rstate)
			poststr="&state="+rstate;
		rcountry=document.frmtrip.country.value;
		if(rcountry)
			poststr="&country="+rcountry;
		rmemberid=document.frmtrip.memberid.value;
		rregion=document.frmtrip.region.value;
		if(rregion)
			poststr="&region="+rregion;
		rmemberid=document.frmtrip.memberid.value;
		if(rmemberid)
			poststr="&memberid="+rmemberid;
		rActType=document.frmtrip.ActType.value;
		if(rActType)
			poststr="&ActType="+rActType;	
		//alert(poststr);
		
		makePOSTRequest3('http://www.mytripguru.com/browse-search-results1.php', poststr,"content");		
}
function pagingser(pg)
{
	document.frmtrip.pn.value=pg;
	getser();
}
var dtCh= "-";
var minYear=1900;
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;
}

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 daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)	
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd-mm-yyyy")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}		
function funfrmsearch()
{
	if(document.frmsearch.keyword.value=="")
	{
		alert("Please enter keyword for search");
		document.frmsearch.keyword.focus();
		return false;
	}
	return true;	
}
function funfrmsearch1()
{
	if(document.frmtrip.keyword.value=="")
	{
		alert("Please enter keyword for search");
		document.frmtrip.keyword.focus();
		return false;
	}
	else
	{
		
		getser();
	}
}
function feedbackvalid()
{
	ffrm=document.feedfrm;
	
	if(ffrm.firstname.value=="")
	{
		alert("Please Insert First Name");
		ffrm.firstname.focus();
		return false;
	}
	if(ffrm.lastname.value=="")
	{
		alert("Please Insert Last Name");
		ffrm.lastname.focus();
		return false;
	}
	if(ffrm.email.value=="")
	{
		alert("Insert Email Name Please");
		ffrm.email.focus();
		return false;
	}
	emailStr=ffrm.email.value;
		
		var emailPat=eval(/^(.+)@(.+)$/);

		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

		var validChars="\[^\\s" + specialChars + "\]"

		var quotedUser="(\"[^\"]*\")"

		var ipDomainPat=eval(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);

		var atom=validChars + '+'

		var word="(" + atom + "|" + quotedUser + ")"

		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

		var matchArray=emailStr.match(emailPat)

		if (matchArray==null) {

			alert("Email address seems incorrect (check @ and .'s)")
            ffrm.email.select();
			return false
		}
	if(ffrm.description.value=="")
	{
		alert("Insert Description Please");
		ffrm.description.focus();
		return false;
	}
	return true;
}
function hidealldiv()
{
	document.getElementById("alljobcode").style.display="none";	
}
function frmcheckfor()
{
	frm=document.frmbody;
	
	if(frm.email.value=="")
	{
		alert("Please insert your email address");
		frm.email.select();
		return false;
	}
	emailStr=frm.email.value;
		
		var emailPat=eval(/^(.+)@(.+)$/);

		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

		var validChars="\[^\\s" + specialChars + "\]"

		var quotedUser="(\"[^\"]*\")"

		var ipDomainPat=eval(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);

		var atom=validChars + '+'

		var word=eval("(" + atom + "|" + quotedUser + ")");

		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

		var matchArray=emailStr.match(emailPat)

		if (matchArray==null) {

			alert("Email address seems incorrect (check @ and .'s)")
            frm.email.select();
			return false
		}
	
	return true;
}
function get4(val) {				
		rtid=document.frmtrip.sregion.value;
		ctid=document.frmtrip.scountry.value;
		stid=document.frmtrip.sstate.value;
		atid=document.frmtrip.stripactivity.value;
		sdid=document.frmtrip.sduration.value;
		pgn=document.frmtrip.pn.value;
		oby=document.frmtrip.orderby.value;
		sby=document.frmtrip.sortby.value;
		scid=document.frmtrip.scity.value;		
		mid=document.frmtrip.memberid.value;
		//var poststr="sregion="+rtid+"&scountry="+ctid+"&striptype="+ttid+"&stripactivity="+atid+"&pn="+pgn;
		/*if(val==1)
		{
			ctid="";
			atid="";
		}
		if(val==2)
		{
			atid="";
		}*/
		//alert(atid);
		var poststr="mid="+mid+"&sregion="+rtid+"&scountry="+ctid+"&sstate="+stid+"&scity="+scid+"&stripactivity="+atid+"&sduration="+sdid+"&pn="+pgn+"&orderby="+oby+"&sortby="+sby;
		makePOSTRequest3('http://www.mytripguru.com/view-gurus1.php', poststr,"viewact");	
		
		
}
function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) 
	{
		field.value = field.value.substring(0, maxlimit);
	} 
	else 
	{
		countfield.value = maxlimit - field.value.length + " Characters left";		
	}
	
}

function settime1()
{
	setTimeout('Effect.toggle(\'mmmmm\',\'appear\')',5000)
}
function update_user_box() 
{ 
	//var user_box = document.getElementById("user"); 
	// add in some XFBML. note that we set useyou=false so it doesn't display "you" 
	//user_box.innerHTML = "<span>" + "<fb:profile-pic uid=loggedinuser facebook-logo=true></fb:profile-pic>" + "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account." + "</span>"; // because this is XFBML, we need to tell Facebook to re-process the document 
	document.frmface.fbuserdt.value="1";
	document.frmface.submit();
	FB.XFBML.Host.parseDomTree();	
} 
