// JavaScript Document
function ajax(){
	var addr;
	var browser=navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	addr=new ActiveXObject('Microsoft.XMLHTTP');
	else
	addr=new XMLHttpRequest();
	return addr;
}
/*if(location.hostname=="localhost"){
var SITEURL="http://"+location.hostname+"/challenge2/";	
}else{
var SITEURL="http://"+location.hostname+"/";
}*/

var SITEURL="http://"+location.hostname+"/";

//var SITEURL="http://"+location.hostname+"/challenge2/";	

var req=ajax();
var signup=ajax();
var login=ajax();
var postcomment=ajax();
var challengesta=ajax();
var coomentschallenge=ajax();
var coomentslist=ajax();
var objcountry=ajax();
var objcountryname=ajax();
var reqfeb=ajax();
var pagecomments=ajax();
var cap=ajax();


/////////////////////   paging  new   /////////////

var mychallengepaging=ajax();
var mywilldo=ajax();
var mydoneit=ajax();

function pagenation_mychllenge(a)
{
	
	mychallengepaging.open('get',SITEURL+'mychallenge.php?page='+a);
	mychallengepaging.onreadystatechange=resultmychallenge;
	mychallengepaging.send('');
	
}

function resultmychallenge()
{
	
	
	  if(mychallengepaging.readyState==4){
	   var myString=trim(mychallengepaging.responseText)
	 document.getElementById('myadded').innerHTML=myString;
	  }
	
}


function pagenation_willdo(a)
{
	//alert(a);
	mywilldo.open('get',SITEURL+'willdo.php?page='+a);
	mywilldo.onreadystatechange=resultmywilldolist;
	mywilldo.send('');
	
}

function resultmywilldolist()
{
	
	
	  if(mywilldo.readyState==4){
	   var myString=trim(mywilldo.responseText)
	 // alert(mywilldo.responseText);
	 document.getElementById('willdo').innerHTML=myString;
	  }
	
}



function pagenation_donelist(a)
{
	
	mydoneit.open('get',SITEURL+'doneit.php?page='+a);
	mydoneit.onreadystatechange=resultmywilldo;
	mydoneit.send('');
	
}

function resultmywilldo()
{
	
	
	  if(mydoneit.readyState==4){
	   var myString=trim(mydoneit.responseText)
	  // alert(mywilldo.responseText);
	 document.getElementById('donelist').innerHTML=myString;
	  }
	
}



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



function pagenation_comments(a)
{
	
	pagecomments.open('get',SITEURL+'commentslist.php?page='+a);
	pagecomments.onreadystatechange=resultpagecontets;
	pagecomments.send('');
	
}

function resultpagecontets()
{
	   var myString=trim(pagecomments.responseText)
	   
	  if(pagecomments.readyState==4){
		  //alert(myString);
	  document.getElementById('loaddata').innerHTML=myString;
	  }
	
}



function getcountrylist(regionid)
{
	//var t=setTimeout("getcountrylist("+regionid+")",100);
//	alert(regionid);
	if(regionid!='-1'){
	objcountry.open('get',SITEURL+'getcountry.php?regionid='+regionid);
	objcountry.onreadystatechange=getcontrydropdowm;
	objcountry.send('');
	}
	
}

function getcontrydropdowm()
{
	  var myString=trim(objcountry.responseText)
	  if(objcountry.readyState==4){
	
	  document.getElementById('countrylist').innerHTML=myString;
	  }
	
}

function changeinnertext(value,id)
{
	
	//alert(id);
	
	objcountryname.open('get',SITEURL+'getcountryname.php?value='+value+'&id='+id);
	objcountryname.onreadystatechange=getcountrynamedisply;
	objcountryname.send('');
	
	
}


function getcountrynamedisply()
{
	   if(objcountryname.readyState==4){
		   resultsplit=trim(objcountryname.responseText);
		    var mySplitResult = resultsplit.split("||");
			document.getElementById(mySplitResult[1]).innerHTML=mySplitResult[0];
			
		
	   }
	
}


///  comments reply  module starts

function commentsreply(id)
{  
    document.getElementById("postreply_"+id).innerHTML='';
			if(document.getElementById('sessionid').value=='') {
			document.getElementById("logintext_"+id).style.display='block';
		}
		else{
	document.getElementById("commenttext_"+id).style.display='block';
	//document.getElementById("commenttextreply_"+id).style.display='none';
		}


	
}


function addcommentsreply(id)
{
	var description=document.getElementById("description_"+id).value;
	coomentschallenge.open('get',SITEURL+'replycomment.php?commentid='+id+'&des='+description);
	coomentschallenge.onreadystatechange=commentreply;
	coomentschallenge.send('');
	document.getElementById("description_"+id).value='';
	document.getElementById("commenttext_"+id).style.display='none';
	
	//selectreplies(id);
}

function commentreply()
{
	  	 if(coomentschallenge.readyState==4){
		// alert(coomentschallenge.responseText);
		mystringnew=trim(coomentschallenge.responseText);
	
		var mySplitResult = mystringnew.split("||");
		   var nid=trim(mySplitResult[1]);
	 


		//alert("postreply_"+nid);
	if(mySplitResult[0]==1){
	   document.getElementById("postreply_"+nid).innerHTML='Thank you, your reply has been successfully posted';
	    selectreplies(nid);
	//   alert(document.getElementById("commentcount_"+nid).innerHTML);
	
	  var precount= parseInt(document.getElementById("commentcount_"+nid).innerHTML)
	  if(precount==''){
		 precount=0;
	  }
	    document.getElementById("commentcount_"+nid).innerHTML=precount +1;
      
		}
		else
		 {
		    document.getElementById("postreply_"+nid).innerHTML='Please fill in reply ';	 
		 }
	  // document.getElementById(id).style.innerHTML=mySplitResult[0];
		 }
	
}

function selectreplies(id)
{
	

	coomentslist.open('get',SITEURL+'selectreply.php?commentid='+id);
	coomentslist.onreadystatechange=selectreply;
	coomentslist.send('');
	
	
}

function selectreply()
{ 

  if(coomentslist.readyState==4){
	   mystringnew=coomentslist.responseText;
	   
	   var mySplitResult = mystringnew.split("||");
	  id="commenttextreply_"+trim(mySplitResult[1]);
	   idhide="commenttext_"+trim(mySplitResult[1]);
	  
	    document.getElementById(id).style.display='block';
	  
	  document.getElementById(idhide).style.display='none';
	  
	
	document.getElementById(id).innerHTML=mySplitResult[0];
   }
	  
}

//// end 
function challengestatusto(challengeid,stateid,displayid)
{
	
	
	challengesta.open('get',SITEURL+'challengestatus.php?challengeid='+challengeid+'&stateid='+stateid+'&displayid='+displayid);
	challengesta.onreadystatechange=challengestatus;
	challengesta.send('');
	
}


function challengestatus()
{
	if(challengesta.readyState==4){
	var myString=challengesta.responseText
	 var mySplitResult = myString.split("||");

     id =trim(mySplitResult[1]);
	 // alert(mySplitResult[0])
     document.getElementById(id).innerHTML=mySplitResult[0];
	}
	
}



function check_invd_email(){

	var reason="";
	
	email_ch=document.getElementById('femail').value;
	reason += validateEmail(email_ch);
    
	if(reason==''){
	req.open('get',SITEURL+'invd_check_availability.php?mail='+email_ch);
	req.onreadystatechange=showavail;
	req.send('');
	}
	else
	{
	   document.getElementById('errorforgot').innerHTML=reason;	
		
	}
}




function check_forum_posting()
 {
	 
	  var subject=document.getElementById("subject").value;
	   var messages=document.getElementById("messages").value;
	   
	   
	   	  var reason='';
	  if(subject=='')
	  {
		   reason +='<li>Please enter subject</li>';  
	  }
	  
	    if(messages=='' || messages==' ')
	  {
		   reason +='<li>Please enter messages</li>';  
	  }
	  
	  if(reason!=''){
	  	var errormessage='<ul>'+reason+'</ul>';
		document.getElementById("commentserror").innerHTML=errormessage;	
		return false;
	  }
	  
	

 }


function changeendmonthofbest()
{
//	changeendmonth
	
var t=setTimeout("changeendmonthofbest()",100);
	
       /*if(document.getElementById("bfrom").value=='00'){
	    document.getElementById("btoshow").style.display="none";
		document.getElementById("btohide").style.display="block";	
		}
		else
		{
		document.getElementById("btoshow").style.display="block";
		document.getElementById("btohide").style.display="none";
		}*/

		document.getElementById("btoshow").style.display="block";
		document.getElementById("btohide").style.display="none";


}


function wordcount()
{
		if(document.addcha.pdesc.value!=""){
	 
	  var des=document.addcha.pdesc.value;
		 if(des.length > 100)
		  {
		  document.addcha.pdesc.value=des.substr(0,100);
		  }
	}
	
}

function wordcountconfim(id)
{
	
	   var des=document.getElementById('text_'+id).value;
		 if(des.length > 100)
		  {
		  document.getElementById('text_'+id).value=des.substr(0,100);
		  }
	}

function wordcountimage(id)
{
	
	   var des=document.getElementById(id).value;
		 if(des.length > 100)
		  {
		  document.getElementById(id).value=des.substr(0,100);
		  }
	}	
	
function wordcommntste(id)
{
	
	   var des=document.getElementById(id).value;
		 if(des.length > 500)
		  {
		  document.getElementById(id).value=des.substr(0,500);
		  }
	}		

	function addchallenge()
	{
	
	 var error="";
	 var reason="";
	if(document.addcha.cname.value == ""){
		//alert("Challenge name required");
		reason +='<li>Challenge name required </li>';

	}
	
	chllengename= document.addcha.cname.value;
	
	if(chllengename!='') {
		if(chllengename.length == 0 || chllengename.search(/[^a-zA-Z0-9 ]/g) != -1 )
		{
			reason +='<li>No special character is allowed for challenge name  </li>';
		}
	}
	
	
	if(document.addcha.ccat.value == "-1"){
		//alert("Please select challenge catgeory");
		reason +='<li>Please select challenge catgeory</li>';
	}
	
/*	if(document.addcha.cdesc.value == ""){
		//alert("Challenge description required");
	reason +='<li>Challenge description required</li>';
	}*/
	

if(document.addcha.ckey.value == "" || document.addcha.ckey.value=="e.g. cycling, london, challenge, road, bike"){
		//alert("Challenge keyword required");
	//	 document.addcha.ckey.focus();
		 reason +='<li>Challenge keyword required</li>';
		
	}
	if(document.addcha.cregi.value == "-1"){
		//alert("Please select region");
		  reason +='<li>Please select region</li>';
		
	}
/*	if(document.addcha.con1.value == "-1"){
		
		 reason +='<li>Please select Country1</li>';
	
	}
	if(document.addcha.con2.value == "-1"){
		 reason +='<li>Please select Country2</li>';
	}
	if(document.addcha.con3.value == "-1"){
	 reason +='<li>Please select Country3</li>';
	}*/
	
	if(document.addcha.rate.value == "-1"){
		 reason +='<li>Please select difficulty rating</li>';
	}
	
	if(document.addcha.bfrom.value == "-1"){
	 		 reason +='<li>Please select best time of year: from</li>';

	}
	
/*	if(document.addcha.bto.value == "-1"){
		  reason +='<li>Please select best time of year: to</li>';
	}*/
	
	if(document.addcha.ctime.value == "-1"){
		 reason +='<li>Please enter time required</li>';
	}
	
/*	if(document.addcha.ctime1.value == "-1"){
		 reason +='<li>Please select how long time required</li>';
	}
	*/
	if(document.addcha.cost.value == ""){
		//alert("Please enter how much cost required");
		reason +='<li>Please enter a cost estimate</li>';
		
	}
	
	
/*	if(document.addcha.cmonth.value!= "-1"  &&  document.addcha.cmonth.value!= "00"  && document.addcha.cday.value != "-1"){
	 
	  if(document.addcha.cyear.value == "-1")
	  {
		  reason +='<li>Please select year of start date</li>';
		  
	  }
	  else
	  {
	   var cdatevalue =document.addcha.cday.value+"/"+document.addcha.cmonth.value+"/"+document.addcha.cyear.value;
	 
	 if (isDate(cdatevalue)==false){
			reason +='<li>Please select valid start date</li>';
	  }
	  }
	
	}
	
	
		if(document.addcha.emonth.value!= "-1"  &&  document.addcha.emonth.value!= "00" && document.addcha.endday.value != "-1"){
	 
	  if(document.addcha.eyear.value == "-1")
	  {
		  reason +='<li>Please select year of  End date</li>';
		  
	  }
	  else {
	   var edatevalue =document.addcha.endday.value+"/"+document.addcha.emonth.value+"/"+document.addcha.eyear.value;
	 
	 if (isDate(edatevalue)==false){
			reason +='<li>Please select valid end date</li>';
	  }
	  
	  }
	
	}
	*/
	
	/*if(document.addcha.cmonth.value == "-1"){
		//alert("Please select create date month");
		reason +='<li>Please select create date month</li>';
	}
	
	if(document.addcha.cday.value == "-1"){
		 reason +='<li>Please select create date</li>';
	}
	
	if(document.addcha.cyear.value == "-1"){
		//alert("Please select create date year");
		 reason +='<li>Please select create date year</li>';
	}
	
	if(document.addcha.cyear.value == "-1"){
		//alert("Please select create date year");
		 reason +='<li>Please select create date year</li>';
	}
	
	if(document.addcha.emonth.value == "-1"){
		//alert("Please select end date month");
		reason +='<li>Please select end date month</li>';
	}
	
	if(document.addcha.endday.value == "-1"){
		//alert("Please select end date");
		reason +='<li>Please select end date</li>';
	}
	
	if(document.addcha.eyear.value == "-1"){
		//alert("Please select end date year");
		reason +='<li>Please select end date year</li>';
	}*/	
	
/*	if(document.addcha.ufile.value!=''){
		if(!/(\.jpg)$/i.test(document.addcha.ufile.value)) {
		reason +='<li>Only jpg files are allowed</li>';
	   }
	}
	*/
	
	if(document.addcha.ufile.value==''){
		reason +='<li>Please upload challenge image</li>';
	}
	
	if(reason!='')
	{
	  errormess= reason;
	  document.getElementById('error').innerHTML=errormess;
	  document.addcha.cname.focus();
	  return false;
	}
	
	if(reason=='')
	{
		  document.getElementById('loadingnew').style.display='block';
	  return true;
	}
	
	
	return true;
}





function mutilpleupload() {
	
	    var error='';
		var imgvalue=0;
	for(i=1;i<5;i++){	
	idfieldname="images"+i;
	 	
	 if(document.getElementById(idfieldname).value != '')
	 {
		 var imgvalue=1;
	   if (!/(\.(jpg|jpeg))$/i.test(document.getElementById(idfieldname).value))
        {
               error+="<li>Please upload JPG file for image "+i+"</li>";
		
		}
     }
	 
	
   }
   
     if(imgvalue==0)
		  {
			  error+="<li>Please upload atleast a image ,else click skip to submit the challenge</li>";  
		  }
	 
   
     if(error!=''){
	  	var errormessage=error;
		document.getElementById("imageerror").innerHTML=errormessage;	
		return false;
	  }
	  


    
}


function focusfunctionreg(a,v,id,showtext)
{
document.getElementById(showtext).style.display="block";
 if(a==v) {
  document.getElementById(id).value='';
 }

}

function onBlurfunctionreg(a,v,id,showtext)
{
document.getElementById(showtext).style.display="none";
 if(a=='') {
  document.getElementById(id).value=v;
 }

}


function showavail(){	
	if(req.readyState==4){
		avail=trim(req.responseText);
		//alert(avail);
		if(avail == 0){
		document.getElementById('errorforgot').innerHTML="<li>Sorry,we don't have that email address registered.Please try again... </li>";
			return false;
		}
		else{
		  document.getElementById('messagepop').innerHTML="A reminder of your password has been sent to you by email.";
		   document.getElementById('showclose').style.display='block';
			return true;
		}
	
	}
}


function registration(a)
 {
	var reason = "";
	  
	document.getElementById('error').style.display='block';		
	displyname=document.getElementById('dispalyname').value;
	// alert(displyname);
	email=document.getElementById('email').value;
	password=document.getElementById('password').value;
	confirmpassword=document.getElementById('confirmpassword').value;
	type='1';
	 
reason += validateEmpty(displyname,'Display Name','Display name...');
reason += validateEmail(email);
reason += validatePassword(password,'Password...');
reason += validateEmail(email);
reason +=validateconfirmpassword(confirmpassword,password,'Confirm Password...')
	 
	 if(reason=='')
	 {
	captchaval=document.getElementById('captchaval').value;
	cap.open('get',SITEURL+'ajax_process.php?type=cpt&captcha='+captchaval);
	cap.onreadystatechange=showcaptcha_advpop;
	cap.send('');
	return false;		 
	/*signup.open('get',SITEURL+'ajaxsignup.php?type='+type+'&dispalyname='+dispalyname+'&email='+email+'&password='+password);
	signup.onreadystatechange=showregister;
	signup.send('');
	return false*/
	 }
	 else
	 {
		// alert(reason);
		
		 if(a==0)
		  {
		   document.getElementById('error_pop').innerHTML=reason;
		    return false;
		  }
		  else
		  {
			 document.getElementById('error').innerHTML=reason; 
			/*  
			  var idval = document.getElementById('myBox');			 
			  idval.style.height = "";	
			  idval.style.height = "550px";
			  
			  var children = document.getElementById('error').children;			  		 			  
			  var element = document.getElementById('myBox').children[0];
			  element.style.height = "";
			  height_val = 470;
			  for(var i = 0; i < children.length; i++) {
					height_val = parseInt(height_val) + 10;
			  }
			  element.style.height = height_val+"px";*/
			//  alert(element.style.height);		
			  document.getElementById('loginerror2').style.display='none';			 			 
			  return false;
		  }
	 }
 }
 
 
 function registration_pop(a)
 {
	 
	  var reason = "";
	 dispalyname=document.getElementById('dispalyname_pop').value;
	 email=document.getElementById('email_pop').value;
	 password=document.getElementById('password_pop').value;
	 confirmpassword=document.getElementById('confirmpassword_pop').value;
reason += validateEmpty(dispalyname,'Display Name','Display name...');
reason += validateEmail(email);
reason += validatePassword(password,'Password...');
reason += validateEmail(email);
reason +=validateconfirmpassword(confirmpassword,password,'Confirm Password...');
//reason +=validatecaptcha();
	 
	 if(reason=='')
	 {
	captchaval=document.getElementById('captchaval').value;
	cap.open('get',SITEURL+'ajax_process.php?type=cpt&captcha='+captchaval);
	cap.onreadystatechange=showcaptcha_pop;
	cap.send('');
	return false;

	signup.open('get',SITEURL+'ajaxsignup.php?dispalyname='+dispalyname+'&email='+email+'&password='+password);
	signup.onreadystatechange=showregister_pop;
	signup.send('');
	return false
	 }
	 else
	 {
		// alert(reason);
		
		 if(a==0)
		  {
		   document.getElementById('error_pop').innerHTML=reason;
		    return false;
		  }
		  else
		  {
			 document.getElementById('error').innerHTML=reason;  
			  return false;
		  }
	 }
 }
 
 
  
  function showregister_pop(){	
 
   if(signup.readyState < 4)
   {
	  document.getElementById('error_pop').innerHTML="Loading...... ";
	    return false   
   }
	if(signup.readyState==4){
		avail=trim(signup.responseText);
		if(avail == 0){
			 document.getElementById('error_pop').innerHTML="<p style='color:#FF0000'>This email address is already registered  \n  </p>";
			 
			return false;
		}
		else{
		  /*document.getElementById('message_pop').innerHTML="<p style='color:#00CC00'>Thanks. We've sent an activation code to your email address. Please check your spam folder and add us to your safe list if it is not in your inbox. Just click on the link in the email to activate your account  </p> ";*/
		//   document.getElementById('showclose').style.display="block";
		   window.location.href=SITEURL+"7";
			return true;
		}
	}
}
 
 function showregister(){	

  if(signup.readyState < 4)
   {
	  document.getElementById('error').innerHTML="<font color='green'>Please Wait Loading......</font> ";
	
	    return false   
   }
 
	if(signup.readyState==4){
		avail=trim(signup.responseText);
		if(avail == 0){
	 document.getElementById('error').innerHTML="<p style='color:#FF0000'>This email address is already registered  \n  </p>";
			 
			return false;
		}
		else{ 
		  document.getElementById('error').innerHTML="   ";
		  window.location.href=SITEURL+"7";
	
	    return false   
		   document.getElementById('showclose').style.display="block";
			return true;
		}
	}
}
 

function validateFormOnSubmit(theForm,formid) {
var reason = "";
if(theForm.loggedid.value==''){
  reason += validateEmail(theForm.email.value);
  reason += validatePassword(theForm.Password.value);  
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage=reason;
	
	if(formid==2)
	 {
		   document.getElementById('loginerror2').style.display='block';	
		  document.getElementById('loginerror2').innerHTML=errormessage;
	 }
	if(formid==1)
	 {
		 document.getElementById('loginerror').innerHTML=errormessage; 
	 }
	 if(formid==3)
	 {
		 document.getElementById('loginerror3').innerHTML=errormessage; 
	 }
	 
	//alert(errormessage);
    return false;
  }
  
  else if(reason=="" && formid==2)
   {
	   
	login.open('get',SITEURL+'signin?email='+theForm.email.value+'&Password='+theForm.Password.value);
	login.onreadystatechange=showlogin;
	login.send('');
	   return false;
   }
  
  else
   {
  return true;
   }
 }
 else
 {
	 document.getElementById('loginerror2').style.display='block';	
		  document.getElementById('loginerror2').innerHTML="<li>You are already logged in. Please logout and then login or sign-up as a business user.</li>";
		  return false;
	 
 }
}



function showlogin(){	
	if(login.readyState==4){
		avail=trim(login.responseText);
	
		if(avail == 0){
			window.location.href=SITEURL+"challenge2/promo";
			return false;
		}
		else{
		    	window.location.href=SITEURL+"challenge2/promo";
			return true;
		}
	
	}
}


function focusfunction(a,v,id)
{

 if(a==v) {
  document.getElementById(id).value='';
 }

}

function onBlurfunction(a,v,id)
{

 if(a=='') {
  document.getElementById(id).value=v;
 }

}

function  hideerror()
{
   document.getElementById("loginerror").innerHTML='';	
	
}



function postchallengecomment()
{
	
	  var com=document.getElementById("comments").value;
	   var challengeid=document.getElementById("challengeid").value;
	  
	  var reason='';
	  if(com=='' || com=='Comments...')
	  {
		   reason +='<li>Please enter comments</li>';  
	  }
	  if(reason!=''){
	  	var errormessage=reason;
		document.getElementById("commentserror").innerHTML=errormessage;	
	  }
	  
	  else {
		   document.getElementById("commentserror").innerHTML='';	
	postcomment.open('get',SITEURL+'postcomment?com='+com+'&challengeid='+challengeid);
	postcomment.onreadystatechange=showpostcomment;
	postcomment.send('');
	  }
	  
}

 

function showpostcomment()
{
	
	 if(postcomment.readyState==4){
		 if(postcomment.responseText==1){
	  document.getElementById("commentserror_log").style.display='block';	
		 }
		 else
		 {
		  document.getElementById("commentserror").innerHTML=postcomment.responseText;		 
		 }
	   document.getElementById("comments").value='Comments...';	
	  //  var f = document.getElementById('listcomments');
        // f.contentWindow.location=document.getElementById('listcomments').src;
		var f= pagenation_comments(1);
	  
	 }
}


function loginalertbox()
{
	  document.getElementById("commentserror_log").style.display='block';	
	
}

function imagevalidatefunction(idfieldname)
{
     var error='';
	 /*	 if(document.getElementById(idfieldname).value == '')
		  {
			  error+="<li>Please upload image</li>";  
		  }*/
	 if(document.getElementById(idfieldname).value != '')
	 {
	   if (!/(\.(jpg|jpeg|png|gif))$/i.test(document.getElementById(idfieldname).value))
        {
               error+="<li>Please upload image in JPG/PNG/GIF Format</li>";
		
		}
     }
   
   return error;
}

function change_password(theForm)
{
	
	var reason = "";
	
	 reason += validateEmpty(theForm.txtCurPwd.value,'Current Password','Current Password');
	 reason += validateEmpty(theForm.txtNewPwd.value,'New Password','New Password');
	 reason += validateEmpty(theForm.txtConPwd.value,'Confirm password','Confirm password');
	  if (reason == "") {
	 reason += newvalidateconfirmpassword(theForm.txtConPwd,theForm.txtNewPwd);
	  }
	  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage=reason;
	document.getElementById('changepassword_error').innerHTML=errormessage;
    return false;
  }

  return true;

}

function imagevalidate(idfieldname)
{
 var reason	=imagevalidatefunction(idfieldname);
  var des=document.getElementById('description').value;
		 if(des.length > 100)
		  {
		    reason+="<li> Descrption should be in  100 characters, its "+ des.length+ "  characters now </li>";  
		  }
     if(reason!=''){
	  	var errormessage=reason;
		document.getElementById("imageerror").innerHTML=errormessage;
		return false;
	  }
	  else
	  {
		   return true;
	  }
	  
}

function changeendmonth(count)
{
 


		 var month=document.getElementById("emonth").value;
 var limit;

 switch(month) {
     case '1':
      var  limit=31;
        break;
    case '2':
      var limit=29;
        break;
    case '3':
       var  limit=31;
        break;
	case '4':
      var limit=30;
        break;
    case '5':
       var limit=31;
        break;
    case '6':
       var  limit=30;
        break;
	case '7':
      var limit=31;
       break;
    case '8':
      var limit=31;
        break;
    case '9':
       var limit=30;
        break;
	case '10':
      var  limit=31;
        break;
    case '11':
     var limit=30;
        break;
    default:
        limit=31;
 }


		if(document.getElementById("emonth").value=='00' && document.getElementById("cmonth").value=='00')
	   {
		  
		document.getElementById("endanyshow").style.display="block";
		document.getElementById("endanyhide").style.display="none";
		document.getElementById("lsday").style.display="none";
		document.getElementById("lsyear").style.display="none";
		document.getElementById("leday").style.display="none";
		document.getElementById("leyear").style.display="none";
		document.getElementById("lsday29").style.display="none";
		document.getElementById("lsday30").style.display="none";
		}
		
		else if(limit=='29')
		{
			
		     document.getElementById("leday29").style.display="block";     
			  document.getElementById("leday").style.display="none";  
			  document.getElementById("leday30").style.display="none";
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
		document.getElementById("leyear").style.display="block";
		
		} 
		else if(limit=='30')
		{
			  		 
					
			 document.getElementById("leday29").style.display="none";     
			  document.getElementById("leday").style.display="none";  
			  document.getElementById("leday30").style.display="block";
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
		document.getElementById("leyear").style.display="block";
			
		}
		
		else if(limit=='31')
		 {
			 
			  document.getElementById("leday29").style.display="none";     
			  document.getElementById("leday").style.display="block";  
			  document.getElementById("leday30").style.display="none"; 
	
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
		document.getElementById("leyear").style.display="block";
	
		 }
		count=count+1;
	 var k=setTimeout("changeendmonth("+count+")",100);
	
}


function changestartmonth(){
	//alert('testing start');
	
 
 var month=document.getElementById("cmonth").value;
 //alert(month);
 var limit;

 switch(month) {
     case '1':
      var  limit=31;
        break;
    case '2':
      var limit=29;
        break;
    case '3':
       var  limit=31;
        break;
	case '4':
      var limit=30;
        break;
    case '5':
       var limit=31;
        break;
    case '6':
       var  limit=30;
        break;
	case '7':
      var limit=31;
       break;
    case '8':
      var limit=31;
        break;
    case '9':
       var limit=30;
        break;
	case '10':
      var  limit=31;
        break;
    case '11':
     var limit=30;
        break;
    default:
        limit=31;
 }


    if(document.getElementById("cmonth").value=='00' &&  document.getElementById("emonth").value=='-1')
	   {
		  
		document.getElementById("endanyshow").style.display="block";
		document.getElementById("endanyhide").style.display="none";
		document.getElementById("lsday").style.display="none";
		document.getElementById("lsyear").style.display="none";
		document.getElementById("leday").style.display="none";
		document.getElementById("leyear").style.display="none";
		document.getElementById("lsday29").style.display="none";
		document.getElementById("lsday30").style.display="none";
		//document.getElementById("ledayfeb").style.display="none";  
		}
		else if(limit=='29')
		{
			
		     document.getElementById("lsday29").style.display="block";     
			  document.getElementById("lsday").style.display="none";  
			  document.getElementById("lsday30").style.display="none";
			// document.getElementById("leday29").style.display="none";     
			//  document.getElementById("leday").style.display="block";  
			//  document.getElementById("leday30").style.display="none"; 
		//document.getElementById("leyear").style.display="block";
		document.getElementById("lsyear").style.display="block";
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
		} 
		else if(limit=='30')
		{
			  		 
					
			 document.getElementById("lsday29").style.display="none";     
			  document.getElementById("lsday").style.display="none";  
			  document.getElementById("lsday30").style.display="block";
			  	  //	  document.getElementById("leday29").style.display="none";     
			//  document.getElementById("leday").style.display="block";  
			//  document.getElementById("leday30").style.display="none"; 
		//document.getElementById("leyear").style.display="block";
		document.getElementById("lsyear").style.display="block";
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
			
		}
		
		else
		 {
			 
			  document.getElementById("lsday29").style.display="none";     
			  document.getElementById("lsday").style.display="block";  
			  document.getElementById("lsday30").style.display="none"; 
			/*	  document.getElementById("leday29").style.display="none";     
			  document.getElementById("leday").style.display="block";  
			  document.getElementById("leday30").style.display="none"; */
		document.getElementById("leyear").style.display="block";
		document.getElementById("lsyear").style.display="block";
				document.getElementById("endanyshow").style.display="none";
		document.getElementById("endanyhide").style.display="block";
	
		 }
		 
	
		
		  var t=setTimeout("changestartmonth()",100);
	
}


function innertextdisplay(id)
{
	
	var a =document.getElementById("cday").value;
    if(a > 0){
	document.getElementById(id).innerHTML=a;
	}
	else
	{
	  document.getElementById(id).innerHTML='Select Day';
	}
	
	//setTimeout("innertextdisplay(1)",100);
	//document.getElementById('cyear').focus();

}

function innertextdisplayeday(id)
{
	
	var a =document.getElementById("endday").value;
    if(a > 0){
	document.getElementById(id).innerHTML=a;
	}
	else
	{
	  document.getElementById(id).innerHTML='Select Day';
	}
	
	//setTimeout("innertextdisplayeday(2)",100);
	//document.getElementById('leyear').focus();
}



function reqfebcall()
{
	
	
	  if(reqfeb.readyState==4){
	   var myString=reqfeb.responseText;
	   //alert(myString);
	 document.getElementById('lsdayreply').innerHTML=myString;
	  }
	
}




function reqfebcalltwo()
{
	
	
	  if(reqfeb.readyState==4){
	   var myString=reqfeb.responseText;
	 document.getElementById('ledayreply').innerHTML=myString;
	  }
	
}


/////////////////////////////////// Date   //////////////////////////////


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 (strMonth.length<1 || month<1 || month>12){
	//	alert("Please enter a valid month")
		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 (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
}




///////////////////////////////////  commom validation   ////////////////////////////


function validateEmail(value) {
    var error="";
    var tfld = trim(value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (value == "") {
       // fld.style.background = 'White';
        error = "<li>You didn't enter an email address.</li>";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
       // fld.style.background = 'White';
        error = "<li>Please enter a valid email address.</li>";
    } else if (value.match(illegalChars)) {
      //  fld.style.background = 'White';
        error = "<li>The email address contains illegal characters.</li>";
    } else {
       // fld.style.background = 'White';
    }
    return error;
}



function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}


function validateEmpty(fld,fieldname,defaultvalue) {
    var error = "";
 
 if(fld==defaultvalue)
  {
	     error = "<li>"+fieldname +"   has not been filled in.</li>"
	
  }
    if (fld.length == 0) {
       // fld.style.background = 'White'; 
        error = "<li>"+fieldname +"   has not been filled in.</li>"
    } else {
        //fld.style.background = 'White';
    }
    return error;  
}



function validatePassword(fld,defaultvalue) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld == "") {
       // fld.style.background = 'White';
        error = "<li>You didn't enter a password </li>";
    }
	else if(fld==defaultvalue)
     {
	     error = "<li>You didn't enter a password </li>";
    }
	else if ((fld.length < 4) || (fld.length > 15)) {
        error = "<li>The password is the wrong length</li>";
    } else if (illegalChars.test(fld)) {
        error = "<li>The password contains illegal characters</li>";
    } else if (!((fld.search(/(a-z)+/)) && (fld.search(/(0-9)+/)))) {
        error = "<li>The password must contain at least one numeral</li>";
    } else {
      //  fld.style.background = 'White';
    }
   return error;
} 








function validateconfirmpassword(fld,passwordfield,defaultvalue) {
        var error = "";
	    if (fld == "") {
      //  fld.style.background = 'White';
        error = "<li>You didn't enter a confirm password </li>";
		}
		else if(fld==defaultvalue)
        {
	     error = "<li>You didn't enter a confirm password</li>";
        }
        else if (fld!= passwordfield) {
         error = "<li>The confirm password and password should be same</li>";
        } 
    return error;
}



function newvalidateconfirmpassword(fld,passwordfield) {
    var error = "";
    
	    if (fld.value == "") {
        error = "<li>You didn't enter a confirm password </li>";
		}
        else if (fld.value!= passwordfield.value) {
         error = "<li>The  password and confirm password should be same</li>";
        } 
    return error;
}


function validatecaptcha(){
	captchaval=document.getElementById('captchaval').value;
	cap.open('get',SITEURL+'ajax_process.php?type=cpt&captcha='+captchaval);
	cap.onreadystatechange=showcaptcha_pop;
	cap.send('');
	return false;
}

  function showcaptcha_pop(){	
  var res="";
	if(cap.readyState==4){
		res=trim(cap.responseText);
		if(res==0){
		document.getElementById('error_pop').innerHTML="<p style='color:#FF0000'>Invalid captcha text. Please enter the valid captcha text. \n  </p>";
		document.getElementById('captcha').src=SITEURL+'vvv/captcha.php?'+Math.random();
		return false;			
		}else{
			signup.open('get',SITEURL+'ajaxsignup.php?dispalyname='+dispalyname+'&email='+email+'&password='+password);
			signup.onreadystatechange=showregister_pop;
			signup.send('');
			return false		
		}
	}
	 
}

 function showcaptcha_advpop(){	
  var res="";
	if(cap.readyState==4){
		res=trim(cap.responseText);
		if(res==0){
		document.getElementById('error').innerHTML="<p style='color:#FF0000'>Invalid captcha text. Please enter the valid captcha text. \n  </p>";
		document.getElementById('captcha').src=SITEURL+'captcha.php?'+Math.random();
		return false;			
		}else{
	signup.open('get',SITEURL+'ajaxsignup.php?type='+type+'&dispalyname='+displyname+'&email='+email+'&password='+password);
	signup.onreadystatechange=showregister;
	signup.send('');
	return false
		}
	}
	 
}
