function emailval(obj) {
    var str = obj.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;    
    if (!str.match(re))
	{
        alert("Enter Valid E-mail Address");
		obj.focus();
        return false;
    }
	else
	{
		dtspos=str.lastIndexOf('.');
		if(dtspos > 0)
		{
			//alert(str.substring(dtspos).length-1)		
			if(str.substring(dtspos).length > 4)
			{
				alert("Enter Valid E-mail Address");
				obj.focus();
				return false;
			}
		}
        return true;
    }
}
function check_blankval(obj)
{
	if(obj.value=="")
	{
		alert("Fields with * are mandatory");
		obj.focus();
		return false;
	}
	return true;
}

function check_confirm_password(mobj,cobj)
{
	if(mobj.value!=cobj.value)
	{
		alert("Your password does not match with the confirm password.")
		mobj.value="";
		cobj.value="";
		mobj.focus();
		return false;
	}
	return true;
}

function check_length(obj,leng)
{
    var objlen=obj.value.length
	if( objlen < leng )
	{
		alert("length must be less than limited characters.");
		obj.focus();
		return false;
	}
	return true;
}
function open_newwindow(path,wdth,hght)
{
	wnd=window.open(path,"","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width="+(wdth+20)+",height="+(hght+15)+",top=0,left=0"); 
}
function check_login(fm)
{
	if(fm.username.value=="" || fm.password.value=="")
	{	
		alert("You can't left blank User Name & Password field.");
		return false;
	}
	return true;
}
textval="";
var height;
var width;

//Use in index.php page for rating
function give_rating(val)
{
	document.frm1.rating.value=val;
	document.frm1.submit();
}
//Use in index.php,login.php,smile_send.php pages
function checklogin(frm)
{
	if(frm.username.value=="" || frm.password.value=="")
	{
		alert("Username & Password both are mandatory fields");
		return false;
	}
	return true;
}
//Use in index.php page for Quick Jump
function check_quickjump(frm)
{
	if(frm.username.value=="")
	{
		alert("Please enter User Id Name for Quick Jump.");
		return false;
	}
	return true;
}
//Use in signup.php,edit_profile.php pages
function check_signupform(frm)
{
	if(!check_length(frm.username,"Username","4-16",4))	return false;
	if(!check_length(frm.password,"Password","4-16",4))	return false;
	if(!check_length(frm.name,"Name","3-48",3))	return false;
	if(!isdate(frm.month.value,frm.day.value,frm.year.value))
	{
		alert("Enter valid birthday");
		frm.day.focus();
		return false;
	}
	if(frm.country.value=="")
	{
		alert("Please select Country name");
		frm.country.focus();
		return false;
	}
	if(!emailval(frm.email))		return false;
	if(frm.url.value!="")
	{
		protocol=frm.url.value.substr(0,5);
		if(protocol!="http:")
		{
			alert("URL field must begin with 'http://' .");
			return false;
		}
	}
	if(!confirm_password(frm.password,frm.cpassword))	return false;
	if(frm.country.value=="United_States.gif")
	{
		if(frm.usastate.value=="")
		{
			alert("Please select USA state")
			frm.usastate.focus();
			return false;
		}
		if(frm.zipcode.value=="")
		{
			alert("Please enter zipcode")
			frm.zipcode.focus();
			return false;
		}
	}
	if(frm.username.value.indexOf(" ")!= -1 || frm.username.value.indexOf("&")!= -1)
	{
		alert("Space, & or special characters are not allowed in Username");
		frm.username.value="";
		frm.username.focus();
		return false;	
	}
	var objphoto=frm.elements["photo_file[]"];
	if(objphoto)
	{
		for(i=0;i<objphoto.length;i++)
		{
			if(objphoto[i].value!="")
			{
				pos=objphoto[i].value.lastIndexOf(".");
				len=objphoto[i].value.length;
				ext=objphoto[i].value.substring(pos+1,len);
				if(ext!="gif" && ext!="jpg" && ext!="jpeg" && ext!="jpe" && ext!="png" && ext!="bmp")
				{
					alert("Sorry! You can't upload ."+ext+" file. \n\n Upload only gif, jpg, jpeg, jpe, png and bmp file.");
					return false;
				}
			}
		}
	}
	return true;
}
//Use in edit_photo.php page
function upload_photo(frm)
{
	var flag=false;
	for(i=0;i<frm.elements["photo_file[]"].length;i++)
	{
		if(frm.elements["photo_file[]"][i].value!="")	
		{
			flag=true;
			break;
		}
	}
	if(!flag)
	{
		alert("You have to select at least one photo file");
		return false;
	}
	var objphoto=frm.elements["photo_file[]"];
	for(i=0;i<objphoto.length;i++)
	{
		if(objphoto[i].value!="")
		{
			pos=objphoto[i].value.lastIndexOf(".");
			len=objphoto[i].value.length;
			ext=objphoto[i].value.substring(pos+1,len);
			if(ext!="gif" && ext!="jpg" && ext!="jpeg" && ext!="jpe" && ext!="png" && ext!="bmp")
			{
				alert("Sorry! You can't upload ."+ext+" file. \n\n Upload only gif, jpg, jpeg, jpe, png and bmp file.");
				return false;
			}
		}
	}
	return true;
}
//Use in check_signupform() function
function check_length(obj,name,len,minval)
{
	if(obj.value.length < minval)
	{
		alert(name+" must required "+len+" characters.")
		obj.focus();
		return false;
	}
	return true;
}
function blankval(obj)
{
	if(obj.value=="")
	{
		alert("Fields with green color are mandatory");
		obj.focus();
		return false;
	}
	return true;
}
//Use in check_signupform() function
function emailval_old(obj)
{
	var em=obj.value;
	atspos=em.lastIndexOf('@');
	dtspos=em.indexOf('.',atspos);
	if(atspos < 0 || dtspos < 0)
	{
		alert("Enter Valid E-mail Address for Signup");
		obj.focus();
		return false;
	}
	return true;
}
//Use in check_signupform() function
function confirm_password(mobj,cobj)
{
	if(mobj.value!=cobj.value)
	{
		alert("Your password does not match with the confirm password \n\n Please retype your password")
		mobj.value="";
		cobj.value="";
		mobj.focus;
		return false;
	}
	return true;
}
//Use in check_signupform() function
function isdate(mm,dd,yy)
{
	if(mm==2)
	{
		if(dd>29)
		{
			return false;
		}
		else if(dd==29 && ((yy%4)>0))
		{
			return false;
		}
	}
	else if( dd > 30 && (mm==4 || mm==6 || mm==9 || mm==11))
	{
		return false;
	}
	return true;	
}
//Use in every pages where photo is display
function open_photo(path,wdth,hght)
{
	if(wdth>780)
		wdth=780;	
	if(hght>600)
		hght=600;
	//alert(path);
	wnd=window.open("open_photo.php?path="+path,"","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width="+(wdth+27)+",height="+(hght+15)+",top=0,left=0"); 
}
function open_index_photo(path)
{
	//alert(path);
	if(width>780)
		width=780;	
	if(height>600)
		height=600;
		
	wnd=window.open("open_photo.php?path="+path,"","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width="+(width+27)+",height="+(height+15)+",top=0,left=0");
}
//Use in forward_profile.php page
function forward_email(frm)
{
	 if(!blankval(frm.yourname))	return false;
	 if(!blankval(frm.friendname))	return false;
	 if(!blankval(frm.mailto))	return false;
	 
	 return true;
}
//Use in message.php, message_reply.php pages
function check_message(frm)
{
	if(!blankval(frm.subject))	return false;
	if(!blankval(frm.message))	return false;
	
	return true;
}
//Use in matchups.php page
function checkage(frm,msg)
{
	from=frm.agefrom.value;
	to=frm.ageto.value;
	if(from=="" || to=="")
	{
	 	alert("Enter valid age for "+msg+". You can't left blank.");
		return false;
	}
	if(isNaN(from) || isNaN(to))
	{
		alert("Enter valid age for "+msg+". You can enter only number.");
		return false;
	}
	if(parseInt(from) > parseInt(to))
	{
		alert("Enter valid age for "+msg+". Always To age is greater then From age.");
		return false;
	}
	return true;
}
//Use in search.php page
function check_searchform(frm)
{
	if(frm.agefrom.value=="" && frm.ageto.value=="")
	{
		return true;
	}
	else
	{	return checkage(frm,'Search');	}
	return true;
}
//Use in all these pages when Delete command is run.
function delete_confirm(msg,page)
{
	if(confirm("Are you sure you want to delete this "+msg+"?"))
	{
		location.replace(page);
	}
}
function journal_add(frm)
{
	if(frm.journal.value=="") 
	{
		alert("Please enter journal.")
		return false;
	}
	if(frm.smiletext.value!="")
	{
		flg=false;
		rbtn = frm.elements['smilename'];
		for(i=0;i<rbtn.length;i++)
		{
			flg=rbtn[i].checked;
			if(flg)break;		
		}
		if(!flg)
		{
			alert("Please select smile to add with journal.");
			return false;
		}
	}
	if(frm.smiletext.value.length>150)
	{
		alert("You cannot enter smile text greater then 150 charaters.");
		return false;
	}
	
	return true;
}
function deselect_othersmile(frm,obj)
{
	if(obj.checked)
	{
		chbox = frm.elements['smilename'];
		for(i=0;i<chbox.length;i++)
		{
			if(obj.value!=chbox[i].value)
				chbox[i].checked=false;
		}
		frm.smiletext.value=textval;
	}
	else
	{
		frm.smiletext.value="";
	}
}
//Use in forget_password.php page
function check_forgetpassword(frm)
{
	if(frm.username.value=="" && frm.email.value=="")
	{
		alert("Please enter Username or Email Adderss.");
		return false;
	}
	return true;
}

function delete_selected(frm,msg,caption)
{
	flg=false;
	chbox = frm.elements['delete[]'];
	if(!chbox)
		chbox = frm.elements['move[]'];
	
	if(chbox)
	{
		for(i=0;i<chbox.length;i++)
		{
			flg=chbox[i].checked;
			if(flg)break;		
		}
		if(!chbox.length)
			flg=chbox.checked;
		if(flg)
		{
			//alert("Are you sure! You want to "+msg+" all selected "+caption+"?");
			if(confirm("Are you sure that you want to "+msg+" all of the selected "+caption+"?"))
			{
				return true;
			}
		}		
		else
		{
			alert("Please select any "+caption+" to "+msg+".");
			return false;
		}
	}
	else
	{
		alert("Record does not Exist for "+msg+".");
		return false;
	}
	return false;
}
function selectall_checkbox(frm,e,msg)
{
	chbox = frm.elements['delete[]'];
	if(!chbox)
		chbox = frm.elements['move[]'];
	
	if(chbox)
	{
		if(!chbox.length)	chbox.checked=e.checked;
		for(i=0;i<chbox.length;i++)
			chbox[i].checked=e.checked;
	}
	else
	{
		e.checked=false;
		alert("Record does not Exist for "+msg+".");
	}	
}
function set_fieldvalue(frmfield,val)
{
	frmfield.value=val;
}
function change_photo(photo,w,h)
{
	main=document.mainphoto.src;
	thumb=photo.src;
	
	document.mainphoto.src=thumb;
	//photo.src=main;
	
	width=w;
	height=h;
}
function comment_add(frm)
{
	if(frm.loginby)
	{
		//alert(frm.loginby[0].checked)
		if(frm.loginby[0].checked)
		{
			if(frm.username.value=="" || frm.password.value=="")
			{
				alert("If you are member, please enter username & password.")
				return false;
			}
		}
	}
	
	if(frm.comment.value=="")
	{
		alert("Please enter comment.It is It is required field.");
		return false;
	}
	return true;
}
function check_playlist(frm)
{
	 if(!blankval(frm.artist))	return false;
	 if(!blankval(frm.trackname))	return false;
	 if(!blankval(frm.genre))	return false;
	return true;
}

self.focus();
if (window.Event) // Only Netscape will have the CAPITAL E.
	document.captureEvents(Event.MOUSEUP); // catch the mouse up event
function nocontextmenu()  // this function only applies to IE4, ignored otherwise.
{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
}
function norightclick(e)	// This function is used by all others
{
	if (window.Event)	// again, IE or NAV?
	{
		if (e.which == 2 || e.which == 3)
		return false;
	}
	else
		if (event.button == 2 || event.button == 3)
	{
		event.cancelBubble = true
		event.returnValue = false;
		return false;
	}
}

function check_photoapprv(frm,msg,obj)
{
	flg=false;
	chbox = frm.elements['delete[]'];
	if(chbox)
	{
		for(i=0;i<chbox.length;i++)
		{
			flg=chbox[i].checked;
			if(flg)break;		
		}
		if(!chbox.length)
			flg=chbox.checked;
		if(flg)
		{
			if(!obj)
			{
				if(confirm("Are you sure to perform any action on all selected "+msg+"?"))
				{
					return true;
				}
				else return false;
			}
		}		
		else
		{
			alert("Please select at least one "+msg);
			return false;
		}
	}
	else
	{
		alert("Record does not Exist");
		return false;
	}
	return true;
}
//document.oncontextmenu = nocontextmenu;		// for IE5+
//document.onmousedown = norightclick;		// for all others