function TribeRegistrationValidataion()
{
	var agree=document.getElementById('agree').checked;
	var c = document.getElementById('password1').value;
	var usrlen = document.getElementById('username').value;
	if(isEmpty("username","Please enter your Username") )
		return false;
	else
     if(usrlen.length < 4)
	{
		alert("Username should contain minimum four characters");
		document.getElementById('username').focus();
		document.getElementById('username').select();
		return false;
	}
	else
	if( isEmpty("email","Please enter your Email Address") || CheckEmail("email") || isEmpty("password1","Please enter your Password") || isEmpty("password2","Please enter your Retype Password") || ChkPassword("password1","password2")  )
		return false;
	else
	if(c.length < 4)
	{
		alert("Password should contain minimum four characters");
		document.getElementById('password1').focus();
		return false;
	}
	else
	if(!agree)
	{
		alert("Please accept  Terms & Conditions");
		document.getElementById('agree').focus();
		return false;
	}
	else
		return true;
	
}
function ThanksValid()
{
	var img=document.thankyouform.upload.value;
	var proimage=img.split('.');
	if(isEmpty("nickname","Please enter your Name/Nickname") || isEmpty("stance","Please enter your Stance") || isEmpty("Levels","Please select your  i.S.k.a.t.e Level") || isEmpty("parkhome","Please enter your Home Skate Park") || isEmpty("me1","Please enter your Me In Three Words") ||  isEmpty("me2","Please enter your Me In Three Words") || isEmpty("me3","Please enter your Me In Three Words"))
		return false;
else if(document.thankyouform.filepath.value=="")
{
if(isEmpty("upload","Please upload your Photo"))
return false;

if(proimage[proimage.length-1]!='jpg' && proimage[proimage.length-1]!='JPG'	&& proimage[proimage.length-1]!='jpeg' &&  proimage[proimage.length-1]!='png' && proimage[proimage.length-1]!='PNG' && proimage[proimage.length-1]!='gif' && proimage[proimage.length-1]!='GIF')
{
		alert("Please upload your Valid  Photo");
		document.thankyouform.upload.select();
		return false;
}
}
else
	return true;

		
		
}
function LoginValidations(username,userpassword)
{
	if(isEmpty(username,"Please enter your Username") || isEmpty(userpassword,"Please enter your Password"))
		return false;
	
}
/*FOR MEMBEREDIT FORM START*/
function ManageProfileValid()
{
	var img=document.editprofile.upload.value;
	var proimage=img.split('.');
	var c = document.getElementById('password1').value;
	if(isEmpty("TribeNickname","Please enter your Name/Nickname"))
			return false;
			
	 if(isEmpty("stance","Please enter your Stance") || isEmpty("Levels","Please select your i.S.k.a.t.e.Level") || isEmpty("SkatePark","Please enter your Home Skate Park") || isEmpty("me1","Please enter your Me in Three words ")|| isEmpty("me2","Please enter your Me in Three words") || isEmpty("me3","Please enter your Me in Three words"))
			return false;
	if(document.getElementById('upload').value!="")
	{
		if(proimage[proimage.length-1]!='jpg' && proimage[proimage.length-1]!='JPG'	&& proimage[proimage.length-1]!='jpeg' &&  proimage[proimage.length-1]!='png' && proimage[proimage.length-1]!='PNG' && proimage[proimage.length-1]!='gif' && proimage[proimage.length-1]!='GIF')
		{
			alert("Please upload your valid Photo");
			document.editprofile.upload.select();
			return false;
		}
	}
	if(isEmpty("email","Please enter your Email Address") || CheckEmail("email"))
		return false
	 if(document.getElementById('password1').value!="")
   {
	   if(isEmpty("password2","Please enter your Retype Password") || ChkPassword("password1","password2"))
	   		return false
	if(c.length < 4)
	{
		alert("Password should contain minimum four characters");
		document.getElementById('password1').focus();
		return false;
	}
   }	
	

} 
/*FOR MEMBEREDIT FORM END*/

function isEmpty(idname,msg)
{
	var val=trim(document.getElementById(idname).value);
	
	if(val=="")
	{
		alert(msg);
		document.getElementById(idname).focus();
		return true;
	}
	else
		return false;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}


function ChkPassword(pwd1,pwd2)
{
	var pwdvalue1= document.getElementById(pwd1).value;
	var pwdvalue2= document.getElementById(pwd2).value;
	if(pwdvalue1!=pwdvalue2)
	{
		alert("Password and RetypePassword should be same");
		document.getElementById(pwd2).focus();
		document.getElementById(pwd2).select();
		return true;
	}
	else 
		return false;
		
}
function CheckEmail(emailid)
{
	var val=document.getElementById(emailid).value;
	var regex = /^[a-zA-Z]{1}[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if(regex.test(val)==0)
	{
		alert("Invalid Email Address");
		document.getElementById(emailid).select();
		document.getElementById(emailid).focus();
		return true;
	}
	else
	return false;
}
/*AJAX CODE FOR RATING START*/

var http_request = false;
var usrid;
var currentrating;
var rate;

function star(userid,prevrating,currentRating,Rate,tablename)
{

alert(currentRating);

usrid=userid;
currentrating=currentRating;
rate=Rate;
var str2="rating.php?usrid="+userid+"&rating="+currentRating+"&tablename="+tablename;
makeRequest(str2);	
}

function makeRequest(url) {

	if (window.ActiveXObject) 
	{
	http_request =  new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) 
	{
		http_request = new XMLHttpRequest();
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		   } catch (e) {
			//alert("Permission UniversalBrowserRead denied.");
		   }
	}
	else
	{
		alert("Your browser does not support AJAX.");
		return null;
	}

    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
    if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
    }
    http_request.onreadystatechange = function(){
    
    try
    {
        if(http_request.readyState == 4)
		{
			var temp =http_request.responseText;		    
		    for(var i=1;i<=currentrating;i++)
				document.getElementById(usrid+i).innerHTML="<img src='images/thumbUp.png' width='17' height='19' border='0'>";
		    for(var j=rate;j<=5;j++)
			document.getElementById(usrid+j).innerHTML="<img src='images/thumbUp_grey.png' width='17' height='19' border='0'>";
	    }
    }
    catch(e)
    {
        alert(e);
    }
    
    }
    http_request.open('GET', url, true);
    http_request.send(null);
    
    
  }
  

  
  
/*AJAX CODE FOR RATING END*/

function iskateLevels(img)
{
	var imageid = img.id;
	document.getElementById('i').style.border="";
	document.getElementById('is').style.border="";
	document.getElementById('isk').style.border="";
	document.getElementById('iska').style.border="";
	document.getElementById('iskat').style.border="";
	document.getElementById('iskate').style.border="";
	document.getElementById(imageid).style.border="thin solid #021a40";
	document.getElementById('Levels').value=img.id;
}
function GalleryUploadItem()
{
	var Galleryitemlen = document.uploadpage.categorytype.length;
	var chosen =0;
	var chosen1=0;
	var img=document.uploadpage.upload.value;
	var proimage=img.split('.');
	for(var i =0; i < Galleryitemlen; i++)
	{
		if(document.uploadpage.categorytype[i].checked==true)
		{
			chosen++;
			var k =i+1;
		}
		
	}
	if(chosen==0)
	{
		alert("Please select your Sharing");												
		document.getElementById('categorytype').focus();		  
		return false;
	}
	if(k==4)
	{
		var subcatlen = document.uploadpage.subcategorytype.length;
		for(var i =0; i < subcatlen; i++)
		{
			if(document.uploadpage.subcategorytype[i].checked==true)
				chosen1++;
		}
		if(chosen1==0)
		{
			alert("Please select iSkate Challenges");												
			document.getElementById('subcategorytype').focus();		  
			return false;
		}
		
	}
	
	if(document.getElementById('filepath').value=="")
	{
	if(k==1)
	{			
				if(isEmpty('upload',"Please Upload Skate Items") )
					return false;
				else	
				if(proimage[proimage.length-1]!='jpg' && proimage[proimage.length-1]!='JPG'	&& proimage[proimage.length-1]!='jpeg' &&  proimage[proimage.length-1]!='png' && proimage[proimage.length-1]!='PNG' && proimage[proimage.length-1]!='gif' && proimage[proimage.length-1]!='GIF')
				{
					alert("Please upload Valid  Skate Type");
					document.uploadpage.upload.select();
					return false;
				}
				
	}
	if( k==2)
	{
				if(isEmpty('upload',"Please Upload Art Items") )
					return false;
				else	
				if(proimage[proimage.length-1]!='jpg' && proimage[proimage.length-1]!='JPG'	&& proimage[proimage.length-1]!='jpeg' &&  proimage[proimage.length-1]!='png' && proimage[proimage.length-1]!='PNG' && proimage[proimage.length-1]!='gif' && proimage[proimage.length-1]!='GIF')
				{
					alert("Please upload Valid  Art Type");
					document.uploadpage.upload.select();
					return false;
				}
				
	}
	if(k==3)
	{
			if(isEmpty('upload',"Please Upload  Music Items") )
					return false;
				else	
				if(proimage[proimage.length-1]!='mp3' && proimage[proimage.length-1]!='MP3' )
				{
					alert("Please upload Valid  Music Files");
					document.uploadpage.upload.select();
					return false;
				}
	}
	}
	if(k==4)
	{
		var tch= document.getElementById('upload').value;	
		if(isEmpty('upload',"Enter the unique youtube ID") )
				return false;
		if(tch.length<11)
		{
				alert("Please enter valid unique youtube ID");
				document.uploadpage.upload.select();
				return false;
		}
	}
	/*if(isEmpty("shortstory","Please Enter Shortstory"))
		return false;*/

}

function Checkstatus(pagename,catid)
{
	document.location.href="uploadFiles.php?page_id=219&option="+catid;
}
function popitup(pagename,id)
{
	newwindow=window.open(pagename+".php?id="+id,'popup','height=600,width=800');
}
function popitupprofile(pagename,id)
{
	newwindow=window.open(pagename+".php?galleryid="+id,'popup','height=300,width=300');
}
function popitup_music(pagename,id)
{
	newwindow=window.open(pagename+".php?id="+id,'popup','height=100,width=300');
}

function popupterms(file)
{
	newwindow=window.open(file+".php",'popup','height=600,width=600,scrollbars=yes');
}


function checkdrop(k)
{
document.location.href="google-new.php?key="+k.value;
}

  function display()
            {
                  // var miles = directions.getDistance().html;
                  // GLog.writeHtml("The distance is " + miles);
            }
function CheckforgotEmail()
{

	var val=document.forget.email.value;

	var regex = /^[a-zA-Z]{1}[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if(regex.test(val)=="0")
	{
		alert("Invalid Email Address");
		document.forget.email.select();
		document.forget.email.focus();
		return false;
	}
	
}
function refpage()
{
	document.location.href="/forgetinfo.php";
}

function DisplayMonthlyNews(month,year)
{
	document.location.href="newsevents.php?newsm="+month+"&newsy="+year;
}
