//*************login page validation***************

function verifyLogin()
{	
	
	if(frmLogin.userName.value=="")
		{
		alert("Please fill  userId  to login")		
		frmLogin.userName.focus()
		return false;
		}
	
	if(frmLogin.password.value=="")
		{
		alert("Please enter the password")		
		frmLogin.password.focus()
		return false;
		}
}
function forgotPassword()
{
	if(frmForgot.userName.value=="")
	{
		alert("please Fill Your UserId or Email to get the password")
			frmForgot.userName.focus()
			return false;
	}
}

function changePassword()
{
	if(frmChange.oldPassword.value=="")
	{
		alert("please Fill Your Old Password")
			frmChange.oldPassword.focus()
			return false;
	}

	if(frmChange.newPassword.value=="")
		{
		alert("Please enter new password")
		frmChange.newPassword.focus()
		return false
		}
		if(frmChange.newPassword.value.length<4 || frmChange.newPassword.value.length>15)
		{
			alert("Password should be of 4 to 15 characters")
			frmChange.newPassword.select()
			frmChange.newPassword.focus()
			return false
		}
			
	if(frmChange.confirmPassword.value=="")
		{
			alert("Please confirm the password")
			
			frmChange.confirmPassword.focus()
			return false
		}
	if(frmChange.newPassword.value!=frmChange.confirmPassword.value)
		{
			alert("Please write the same  password")
			frmChange.confirmPassword.select()
			frmChange.confirmPassword.focus()
			return false
		}
}
//********************** validation for registration page
function verify()
{
	
	if(register.userName.value=="")
		{
		alert("Please write the user Name")
		
		register.userName.focus()
		return false
		}

			//***Password***
		

		if( register.password.value=="")
		{
		alert("Please enter password")
		register.password.focus()
		return false
		}
		if(register.password.value.length<4 || register.password.value.length>15)
		{
			alert("Password should be of 4 to 15 characters")
			register.password.select()
			register.password.focus()
			return false
		}
			
		if(register.confirmPassword.value=="")
		{
			alert("Please confirm the password")
			
			register.confirmPassword.focus()
			return false
		}
		if(register.password.value!=register.confirmPassword.value)
		{
			alert("Please write the same  password")
			register.confirmPassword.select()
			register.confirmPassword.focus()
			return false
		}
		
		

		//*******e mail *******
			if(echeck(register.email.value)=="")
			{				
				register.email.focus();
				return false;
			}
			
			
		function echeck(str) 
		{
			
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   alert("Please Enter A Valid E-mail ID")
			   return false
			}
			
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   alert("Invalid E-mail ID")
			   return false
			}
			
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				alert("Invalid E-mail ID")
				return false
			}
			
			 if (str.indexOf(at,(lat+1))!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.indexOf(dot,(lat+2))==-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.indexOf(" ")!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 return true
		}
	


			//***Name***
		if(register.firstName.value=="")
		{
		alert("Please Fill  Your First Name")
		
		register.firstName.focus()
		return false
		}
		//***Last Name***
		if(register.lastName.value=="")
		{
		alert("Please Fill  Your Last Name")	
		register.lastName.focus()
		return false
		}
		
		//***gender***
		if(register.userGender.checked==0)
		{
		alert("Please Fill  Your Gender")	
		register.userGender.focus()
		return false
		}
		
		//***Day***
		if (register.dobDay.selectedIndex<=0)
		{
		alert("Please Select Day")
		register.dobDay.focus()
		return false;
		}
		
			//***Month***
		if (register.dobMonth.selectedIndex<=0)
		{
		alert("Please Select Month")
		register.dobMonth.focus()
		return false;
		}
		
			//***Year***
		if (register.dobYear.selectedIndex<=0)
		{
		alert("Please Select Year")
		register.dobYear.focus()
		return false;
		}
		
}
//******************edit profile validation******



function verifyProfile()
{
	if(frmEditProfile.firstName.value=="")
		{
		alert("Please Fill  Your First Name")
		
		frmEditProfile.firstName.focus()
		return false
		}
		//***Last Name***
		if(frmEditProfile.lastName.value=="")
		{
		alert("Please Fill  Your Last Name")	
		frmEditProfile.lastName.focus()
		return false
		}
		if(frmEditProfile.email.value=="")
		{
		alert("Please Fill  Your email")	
		frmEditProfile.email.focus()
		return false
		}
		//*******e mail *******
			if(echeck(frmEditProfile.email.value)=="")
			{
				
				frmEditProfile.email.focus();
				return false;
			}
			
		function echeck(str) 
		{
			
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   alert("Please Enter A Valid E-mail ID")
			   return false
			}
			
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   alert("Invalid E-mail ID")
			   return false
			}
			
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				alert("Invalid E-mail ID")
				return false
			}
			
			 if (str.indexOf(at,(lat+1))!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.indexOf(dot,(lat+2))==-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.indexOf(" ")!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 return true
		}
	

	//***Day***
		if (frmEditProfile.dobDay.selectedIndex<=0)
		{
		alert("Please Select Day")
		frmEditProfile.dobDay.focus()
		return false;
		}
		
			//***Month***
		if (frmEditProfile.dobMonth.selectedIndex<=0)
		{
		alert("Please Select Month")
		frmEditProfile.dobMonth.focus()
		return false;
		}
		
			//***Year***
		if (frmEditProfile.dobYear.selectedIndex<=0)
		{
		alert("Please Select Year")
		frmEditProfile.dobYear.focus()
		return false;
		}
}
//*********************************uplload photo validation********************8
function uploadEditPhoto()
	{	
		if(frmEditPhoto.photo.value=="")
		{
			alert("Please browse the photo")	
			frmEditPhoto.photo.focus()
			return false
		}
	}
//************************community create validation**************
function verifyAddCommunity()
{
	if(frmAddCommunity.name.value=="")
	{
		alert("Please write the community name")
		frmAddCommunity.name.focus()
			return false
	}
	
	if(frmAddCommunity.category.value<=0)
	{
		alert("Please select the community category")
		frmAddCommunity.category.focus()
			return false
	}
	
	if(frmAddCommunity.description.value<=0)
	{
		alert("please write a description of your community")
		frmAddCommunity.description.focus()
			return false
	}
}

function verifyCommunityPhoto()
{
	if(frmAddCommunityPhoto.photo.value=="")
	{
		alert("Please browse the photo")	
			frmAddCommunityPhoto.photo.focus()
			return false
	}
}
//*****populate dynamic select*******************************************

function deleteOption(theSel,theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}


function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function moveOptions(theSelFrom,theSelTo)
{

	var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;

  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
     
	  deleteOption(theSelFrom, i);
      selectedCount++;
	 
	  
    }
  }
 
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo,selectedText[i],selectedValues[i]);
	
  }
  	
// if(NS4) history.go(0);

}

//**************************8ends here********************************

function formatText(str)
{
	str=replace(str,vbcrlf,"<br>")
	alert(str)
	formatedText=str
	
}

//********************************REPORT Abuse********************************

function reportAbuse()
{	
	
	if(frmAbuse.abuseName.checked==0)
	{ 
		alert("Please select the inappropriate or illegal content")
		return false
	}
	if(frmAbuse.reportAbuseDetail.value=="")
	{
		alert("Please provide detailed information about the abuse.")
		frmAbuse.reportAbuseDetail.focus()
		return false
	}
	
}
//********************************SEND MESSAGE********************************

function verifyWriteMessage()
{
	if(frmWriteMessage.message.value=="")
	{
		alert("please write the message")
		frmWriteMessage.message.focus()
			return false
	}

	if(frmWriteMessage.subject.value=="")
	{
		if(!confirm("Do you want to send the message with the blank subject?"))
		{
			
			return false
		}
	}
	
}
//***********************skip registration**********
function skipRegistration()
{
	if(confirm("Do you want to skip details?"))
	{
		location.href="register-skip.asp"
	}
}

//***********************validation for posting events**********

function checkEventPost()
{
	if(frmCommunityEvent.name.value=="")
	{
		alert("Please provide the Title of the event.")
		frmCommunityEvent.name.focus()
		return false
	}
	if(frmCommunityEvent.eventDay.value<=0)
	{
		alert("Please provide the Day.")
		frmCommunityEvent.eventDay.focus()
		return false
	}
	if(frmCommunityEvent.eventMonth.value<=0)
	{
		alert("Please provide the Month.")
		frmCommunityEvent.eventMonth.focus()
		return false
	}
	if(frmCommunityEvent.eventYear.value<=0)
	{
		alert("Please provide the Year.")
		frmCommunityEvent.eventYear.focus()
		return false
	}
	if(frmCommunityEvent.eventHr.value<=0)
	{
		alert("Please provide the Time.")
		frmCommunityEvent.eventHr.focus()
		return false
	}
	if(frmCommunityEvent.eventMin.value<=0)
	{
		alert("Please provide the Time.")
		frmCommunityEvent.eventMin.focus()
		return false
	}	
	if(frmCommunityEvent.location.value=="")
	{
		alert("Please provide the location of the event.")
		frmCommunityEvent.location.focus()
		return false
	}
	if(frmCommunityEvent.city.value=="")
	{
		alert("Please provide the city for the event.")
		frmCommunityEvent.city.focus()
		return false
	}
	if(frmCommunityEvent.details.value=="")
	{
		alert("Please provide the details of the event.")
		frmCommunityEvent.details.focus()
		return false
	}
}
//***************

function popitup(url)
		{
			newwindow=window.open(url,'name','scrollbars,height=300,width=400');
			if (window.focus) {newwindow.focus()}
			return false;
		}
//********************forum post***************
function checkForumPost()
{
	if(frmCommunityForum.subject.value=="")
	{
		alert("Please provide the subject.")
		frmCommunityForum.subject.focus()
		return false
	}
	if(frmCommunityForum.message.value=="")
	{
		alert("Please provide the message.")
		frmCommunityForum.message.focus()
		return false
	}
}


var numbers='1234567890'
var signs='+-'
var mathsigns='+-=()*/'


function alpha(e,allow) {
var k;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
return (allow.indexOf(String.fromCharCode(k))!=-1);
}



	/**
version 1.0
March 17, 2005
Julian Robichaux, http://www.nsftools.com
*/

/**** adjust these two parameters to control how fast or slow
 **** the images grow/shrink ****/
// how many milliseconds we should wait between resizing events
var resizeDelay = 10;
// how many pixels we should grow or shrink by each time we resize
var resizeIncrement = 5;

// this will hold information about the images we're dealing with
var imgCache = new Object();


/**
The getCacheTag function just creates a (hopefully) unique identifier for
each <img> that we resize.
*/
function getCacheTag (imgElement) {
	return imgElement.src + "~" + imgElement.offsetLeft + "~" + imgElement.offsetTop;
}


/**
We're using this as a class to hold information about the <img> elements
that we're manipulating.
*/
function cachedImg (imgElement, increment) {
	this.img = imgElement;
	this.cacheTag = getCacheTag(imgElement);
	this.originalSrc = imgElement.src;
	
	var h = imgElement.height;
	var w = imgElement.width;
	this.originalHeight = h;
	this.originalWidth = w;
	
	increment = (!increment) ? resizeIncrement : increment;
	this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
	this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}


function resizeImg (imgElement, percentChange, newImageURL) {
	// convert the percentage (like 150) to an percentage value we can use
	// for calculations (like 1.5)
	var pct = (percentChange) ? percentChange / 100 : 1;
	
	// if we've already resized this image, it will have a "cacheTag" attribute
	// that should uniquely identify it. If the attribute is missing, create a
	// cacheTag and add the attribute
	var cacheTag = imgElement.getAttribute("cacheTag");
	if (!cacheTag) {
		cacheTag = getCacheTag(imgElement);
		imgElement.setAttribute("cacheTag", cacheTag);
	}
	
	// look for this image in our image cache. If it's not there, create it.
	// If it is there, update the percentage value.
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal) {
		imgCache[cacheTag] = new Array(new cachedImg(imgElement), pct);
	} else {
		cacheVal[1] = pct;
	}
	
	// if we're supposed to be using a rollover image, use it
	if (newImageURL)
		imgElement.src = newImageURL;
	
	// start the resizing loop. It will continue to call itself over and over
	// until the image has been resized to the proper value.
	resizeImgLoop(cacheTag);
	return true;
}


/**
This is the function that actually does all the resizing. It calls itself
repeatedly with setTimeout until the image is the right size.
*/
function resizeImgLoop (cacheTag) {
	// get information about the image element from the image cache
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal)
		return false;
	
	var cachedImageObj = cacheVal[0];
	var imgElement = cachedImageObj.img;
	var pct = cacheVal[1];
	var plusMinus = (pct > 1) ? 1 : -1;
	var hinc = plusMinus * cachedImageObj.heightIncrement;
	var vinc = plusMinus * cachedImageObj.widthIncrement;
	var startHeight = cachedImageObj.originalHeight;
	var startWidth = cachedImageObj.originalWidth;
	
	var currentHeight = imgElement.height;
	var currentWidth = imgElement.width;
	var endHeight = Math.round(startHeight * pct);
	var endWidth = Math.round(startWidth * pct);
	
	// if the image is already the right size, we can exit
	if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
		return true;
	
	// increase or decrease the height and width, making sure we don't get
	// larger or smaller than the final size we're supposed to be
	var newHeight = currentHeight + hinc;
	var newWidth = currentWidth + vinc;
	if (pct > 1) {
		if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	} else {
		if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	}
	
	// set the image element to the new height and width
	imgElement.height = newHeight;
	imgElement.width = newWidth;
	
	// if we've returned to the original image size, we can restore the
	// original image as well (because we may have been using a rollover
	// image in the original call to resizeImg)
	if ((newHeight == cachedImageObj.originalHeight) || (newWidth == cachedImageObj.originalwidth)) {
		imgElement.src = cachedImageObj.originalSrc;
	}
	
	// shrink or grow again in a few milliseconds
	setTimeout("resizeImgLoop('" + cacheTag + "')", resizeDelay);
}

