// JavaScript Document
//Email Check
function emailcheck(emailvalue)
{
	if ((emailvalue.length > 0 && (emailvalue.indexOf("@",0) == - 1 || emailvalue.indexOf(".",0) == - 1)))  
	{
		flagcheck=true;
	}
	emailval=emailvalue
	apos=emailval.indexOf("@");
	dotpos=emailval.lastIndexOf(".");
	lastpos=emailval.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
	{
		flagcheck=true;
	}
	return flagcheck=false;
	
}

function member_register()
{
	if (document.register.txtUsername.value=="" )
	{ 
		alert ("You need to have a Username");
		document.register.txtUsername.focus();
		return false;
	}	
	if (document.register.txtEmail.value=="" )
	{ 
		alert ("You need to have a E-mail address");
		document.register.txtEmail.focus();
		return false;
	}
	var emailid=document.register.txtEmail.value;
	var res=emailcheck(emailid);
	if(res)
	{
		alert("Enter valid Email Address with correct domain name (i.e).com,.org.in");
		document.register.txtEmail.focus();
		flagcheck=false;
		return false;
	}	
	if (document.register.txtPassword.value=="" )
	{ 
		alert ("You need to have a password");
		document.register.txtPassword.focus();
		return false;
	}	
	if (document.register.txtConfirm.value=="" )
	{ 
		alert ("You need to have a confirm password");
		document.register.txtConfirm.focus();
		return false;
	}
	if (document.register.txtPassword.value != document.register.txtConfirm.value) 
	{
		alert("Your password and confirm password must be the same");
		document.register.txtConfirm.value="";
		document.register.txtConfirm.focus();
		return false;
	}
}

// -------------Used in Member view page-----------
function poptastic(url)
{
	newwindow=window.open(url,'name','scrollbars=yes,height=500,width=779');
	if (window.focus) {newwindow.focus()}
}
function SortMember()
{
	sortby = document.form1.SortType.value;
	key = document.form1.hidkey.value;
	if(sortby != "select")
	{
		document.form1.action = "member_view.php?key="+key+"&sort="+sortby;
		document.form1.submit();
	}
}
//-------------------------------------------------

//-----------Used in member_edit Page --------------
function member_edit()
{	
	if (document.register.txtUsername.value=="" )
	{ 
		alert ("You need to have a Username");
		document.register.txtUsername.focus();
		return false;
	}	
	if (document.register.txtEmail.value=="" )
	{ 
		alert ("You need to have a E-mail address");
		document.register.txtEmail.focus();
		return false;
	}
	var emailid=document.register.txtEmail.value;
	var res=emailcheck(emailid);
	if(res)
	{
		alert("Enter valid Email Address with correct domain name (i.e).com,.org.in");
		document.register.txtEmail.focus();
		flagcheck=false;
		return false;
	}	
}
//---------------------------------------------------

//-------------------Used in admin account info page
function account_validate()
{	
	if (document.frm_accountinfo.txtUser.value=="" )
	{ 
		alert ("You need to have a Username");
		document.frm_accountinfo.txtUser.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtPass.value=="" )
	{ 
		alert ("You need to have a Password");
		document.frm_accountinfo.txtPass.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtCompany.value=="" )
	{ 
		alert ("You need to have a Company Name");
		document.frm_accountinfo.txtCompany.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtContact.value=="" )
	{ 
		alert ("You need to have a ContactPerson Name");
		document.frm_accountinfo.txtContact.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtAddress.value=="" )
	{ 
		alert ("You need to have a Address");
		document.frm_accountinfo.txtAddress.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtCity.value=="" )
	{ 
		alert ("You need to have a City");
		document.frm_accountinfo.txtCity.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtState.value=="" )
	{ 
		alert ("You need to have a State");
		document.frm_accountinfo.txtState.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtCountry.value=="" )
	{ 
		alert ("You need to have a Country");
		document.frm_accountinfo.txtCountry.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtPhone.value=="" )
	{ 
		alert ("You need to have a Phone  Number");
		document.frm_accountinfo.txtPhone.focus();
		return false;
	}	
	if (isNaN(document.frm_accountinfo.txtPhone.value))
	{ 
		alert ("Phone  Number must be Numeric");
		document.frm_accountinfo.txtPhone.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtEmail.value=="" )
	{ 
		alert ("You need to have a E-mail address");
		document.frm_accountinfo.txtEmail.focus();
		return false;
	}
	var emailid=document.frm_accountinfo.txtEmail.value;
	var res=emailcheck(emailid);
	if(res)
	{
		alert("Enter valid Email Address with correct domain name (i.e).com,.org.in");
		document.frm_accountinfo.txtEmail.focus();
		flagcheck=false;
		return false;
	}	
	if (document.frm_accountinfo.txtWebsite.value=="" )
	{ 
		alert ("You need to have a Website");
		document.frm_accountinfo.txtWebsite.focus();
		return false;
	}	
	if (document.frm_accountinfo.FromYear.value=="" )
	{ 
		alert ("You need to have FromYear");
		document.frm_accountinfo.FromYear.focus();
		return false;
	}	
	if (isNaN(document.frm_accountinfo.FromYear.value))
	{ 
		alert ("FromYear Must be a Numeric");
		document.frm_accountinfo.FromYear.focus();
		return false;
	}	
	if (document.frm_accountinfo.ToYear.value=="" )
	{ 
		alert ("You need to have ToYear");
		document.frm_accountinfo.ToYear.focus();
		return false;
	}	
	if (isNaN(document.frm_accountinfo.ToYear.value))
	{ 
		alert ("ToYear Must be a Numeric");
		document.frm_accountinfo.ToYear.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtColumns.value=="" )
	{ 
		alert ("You need to have a Posts per Page");
		document.frm_accountinfo.txtColumns.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtRows.value=="" )
	{ 
		alert ("You need to have a number of Items");
		document.frm_accountinfo.txtRows.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtMessage.value=="" )
	{ 
		alert ("You need to have a maximum Messages");
		document.frm_accountinfo.txtMessage.focus();
		return false;
	}	
	if (document.frm_accountinfo.Datedisp.value=="" )
	{ 
		alert ("You need to have a Date Format");
		document.frm_accountinfo.Datedisp.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtOrdermsg.value=="" )
	{ 
		alert ("You need to have a Email Message");
		document.frm_accountinfo.txtOrdermsg.focus();
		return false;
	}	

}
//---------------------- End of Used in admin account info page

//uesed in cat_edit,cat_add.php
function category_add()
{
	if (document.frm_accountinfo.varCatName.value=="" )
	{ 
		alert ("You need to have a Category Name");
		document.frm_accountinfo.varCatName.focus();
		return false;
	}	
	if (document.frm_accountinfo.intCatOrder.value=="" )
	{ 
		alert ("You need to have a Category Order");
		document.frm_accountinfo.intCatOrder.focus();
		return false;
	}	

}

//uesed in avatar_add.php
function avatar()
{
	if (document.frm_accountinfo.varImageName.value=="" )
	{ 
		alert ("You need to have a Image Name");
		document.frm_accountinfo.varImageName.focus();
		return false;
	}	
}

//Used for Forum Jump

function forum_jump()
{
	catid = document.form1.jump.value;
	document.location.href = "forum_view.php?cid="+catid;
}

function forum_jump1(catid)
{
	//alert(catid);
	//catid = document.form1.jump.value;
	document.location.href = "forum_view.php?cid="+catid;
}


//Used in message.php

function Reply()
{
	document.indexform.action = "message_reply.php";
	document.indexform.submit();
}

//Used in index.php

function login_validation()
{
	if (document.Login.txtUsername.value=="" )
	{ 
		alert ("You need to have a User Name");
		document.Login.txtUsername.focus();
		return false;
	}	
	if (document.Login.txtPassword.value=="" )
	{ 
		alert ("You need to have a Password");
		document.Login.txtPassword.focus();
		return false;
	}	
}

//Used in Avatar_add.php
function confirmMsg(m)
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}
function poporder(url)
{
	newwindow=window.open(url,'name','scrollbars=yes,height=500,width=779');
	if (window.focus) {newwindow.focus()}
}

//Used in forum_add.php,forum_edit.php

function addforum_validate()
{
	if (document.frm_accountinfo.txtForumName.value=="" )
	{ 
		alert ("You need to have a Forum Name");
		document.frm_accountinfo.txtForumName.focus();
		return false;
	}	
	if (document.frm_accountinfo.txtForumDesc.value=="" )
	{ 
		alert ("You need to have a Forum Description");
		document.frm_accountinfo.txtForumDesc.focus();
		return false;
	}	
}

//Used in news_send.php,news_thanks.php

function thankscript()
{
	if (document.form1.varFromName.value=="" )
	{ 
		alert ("You need to have a From Name");
		document.form1.varFromName.focus();
		return false;
	}	
	if (document.form1.varFromEmail.value=="" )
	{ 
		alert ("You need to have a From Email");
		document.form1.varFromEmail.focus();
		return false;
	}	
	var emailid=document.form1.varFromEmail.value;
	var res=emailcheck(emailid);
	if(res)
	{
		alert("Enter valid Email Address with correct domain name (i.e).com,.org.in");
		document.form1.varFromEmail.focus();
		flagcheck=false;
		return false;
	}	
	if (document.form1.varSubject.value=="" )
	{ 
		alert ("You need to have a Subject");
		document.form1.varSubject.focus();
		return false;
	}	
}

//--------Used inforum_posts.php
function calldel(m)
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}

function callmsg(s)
{
  if(!confirm(s))
  {
    return false;
  }
  else
    location.href="forumlogin.php";
  return true;
}

function member_register_new()
{
	if (document.register.txtUsername.value=="" )
	{ 
		alert ("You need to have a Username");
		document.register.txtUsername.focus();
		return false;
	}	
	if (document.register.txtEmail.value=="" )
	{ 
		alert ("You need to have a E-mail address");
		document.register.txtEmail.focus();
		return false;
	}
	var emailid=document.register.txtEmail.value;
	var res=emailcheck(emailid);
	if(res)
	{
		alert("Enter valid Email Address with correct domain name (i.e).com,.org.in");
		document.register.txtEmail.focus();
		flagcheck=false;
		return false;
	}	
	if (document.register.txtPassword.value=="" )
	{ 
		alert ("You need to have a password");
		document.register.txtPassword.focus();
		return false;
	}	
	if (document.register.txtConfirm.value=="" )
	{ 
		alert ("You need to have a confirm password");
		document.register.txtConfirm.focus();
		return false;
	}
	if (document.register.txtPassword.value != document.register.txtConfirm.value) 
	{
		alert("Your password and confirm password must be the same");
		document.register.txtConfirm.value="";
		document.register.txtConfirm.focus();
		return false;
	}
	/*var date	=	document.register.date.value;
	var month	=	document.register.month.value;
	var year	=	document.register.year.value;
	alert(date);
	alert(month);
	alert(year);
	if(!(date == "00" && month == "00" && year == "0000"))
	{
		alert("Enter Date,Month and Year");
	}*/
}
function ChangeList()
{
	imagename = document.register.selectAvatar.value;
	if(imagename != "")
	{
		var AvatarShow=document.getElementById("AvatarShow");
		if(AvatarShow)
		{
			AvatarShow.style.visibility="visible";
		}
	 	document.register.ShowAvatar.src="avatar_uploaded_images/"+imagename;
	}
	else
	{
		var AvatarShow=document.getElementById("AvatarShow");
		if(AvatarShow)AvatarShow.style.visibility="hidden";
	}
}
