// JavaScript Document

//Login Form Validation
function login_validate()
{
	if(document.login_form.username.value=="")	
	{
		alert("Please Enter Username");	
		document.login_form.username.focus();
		return false;
	}
	if(document.login_form.password.value=="")	
	{
		alert("Please Enter Password");	
		document.login_form.password.focus();
		return false;
	}
	if((document.login_form.sec_code) && document.login_form.sec_code.value=="")	
	{
		alert("Please Enter Security Code");	
		document.login_form.sec_code.focus();
		return false;
	}
}

//MOD Search Validation
function check_search()
{	
	if(document.search_form.mod_name.value=="")
	{
		alert("Please Enter Search Keyword");
		document.search_form.mod_name.focus();
		return false;
	}
}

//Search Form Validation
function search_validate()
{	
	if(document.search_form.keyword.value=="")
	{
		alert("Please Enter Search Keyword");
		document.search_form.keyword.focus();
		return false;
	}
}


//Forgot Password Form Validation
function forgot_validate()
{
	var valid_email = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if(document.forgot_pass_form.email.value=="")	
	{
		alert("Please Enter Email Address");	
		document.forgot_pass_form.email.focus();
		return false;
	}
	if(document.forgot_pass_form.email.value.search(valid_email) == -1)	
	{
		alert("Please Enter Valid Email Address");	
		document.forgot_pass_form.email.value="";
		document.forgot_pass_form.email.focus();
		return false;
	}
}

//ADD ADMIN VALIDATION
function admin_validate()
{
	var valid_email = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if(document.add_admin.username.value=="")	
	{
		alert("Please Enter Username");	
		document.add_admin.username.focus();
		return false;
	}
	if(document.add_admin.password.value=="")	
	{
		alert("Please Enter Password");	
		document.add_admin.password.focus();
		return false;
	}
	if(document.add_admin.email.value=="")	
	{
		alert("Please Enter Email Address ");	
		document.add_admin.email.focus();
		return false;
	}
	if(document.add_admin.email.value.search(valid_email) == -1)	
	{
		alert("Please Enter Valid Email Address");	
		document.add_admin.email.value="";
		document.add_admin.email.focus();
		return false;
	}
}

//ADD GAME VALIDATION
function game_validate()
{
	if(document.add_game.game_name.value=="")	
	{
		alert("Please Enter Game Name");	
		document.add_game.game_name.focus();
		return false;
	}
}

//ADD ENGINE VALIDATION
function engine_validate()
{
	if(document.add_mod_engine.engine_name.value=="")	
	{
		alert("Please Enter Engine Name");	
		document.add_mod_engine.engine_name.focus();
		return false;
	}
}


//ADD CATEGORY VALIDATION
function category_validate()
{
	if(document.add_category.category_name.value=="")	
	{
		alert("Please Enter Category Name");	
		document.add_category.category_name.focus();
		return false;
	}
}

//ADD BRACKET VALIDATION
function bracket_validate()
{
	if(document.add_bracket.bracket_type.value=="")	
	{
		alert("Please Enter Bracket Type");	
		document.add_bracket.bracket_type.focus();
		return false;
	}
}

//ADD LINK VALIDATION
function link_validate()
{
	if(document.add_link.link_name.value=="")	
	{
		alert("Please Enter Link Name");	
		document.add_link.link_name.focus();
		return false;
	}
	if(document.add_link.link_desc.value=="")	
	{
		alert("Please Enter Link Description");	
		document.add_link.link_desc.focus();
		return false;
	}
	if(document.add_link.link_url.value=="")	
	{
		alert("Please Enter Link URL");	
		document.add_link.link_url.focus();
		return false;
	}
}

//ADD LINK VALIDATION
function feed_validate()
{
	if(document.add_feed.feed_name.value=="")	
	{
		alert("Please Enter Feed Name");	
		document.add_feed.feed_name.focus();
		return false;
	}
	if(document.add_feed.notes.value=="")	
	{
		alert("Please Enter Feed Notes");	
		document.add_feed.notes.focus();
		return false;
	}
	if(document.add_feed.feed_url.value=="")	
	{
		alert("Please Enter Feed URL");	
		document.add_feed.feed_url.focus();
		return false;
	}
}

//Register Form Validation
function reg_validate()
{
	var valid_email = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

	if(document.reg_form.username.value=="")	
	{
		alert("Please Enter Username");	
		document.reg_form.username.focus();
		return false;
	}
	if(document.reg_form.password.value=="")	
	{
		alert("Please Enter Password");	
		document.reg_form.password.focus();
		return false;
	}
	if(document.reg_form.password.value.length<4)	
	{
		alert("Password At least 4 characters");	
		document.reg_form.password.focus();
		return false;
	}
	if(document.reg_form.confirm_password.value=="")	
	{
		alert("Please Enter Confirm Password");	
		document.reg_form.confirm_password.focus();
		return false;
	}
	if(document.reg_form.password.value!=document.reg_form.confirm_password.value)	
	{
		alert("Password and Confirm Password Should be Same");	
		document.reg_form.confirm_password.focus();
		return false;
	}
	if(document.reg_form.email.value=="")	
	{
		alert("Please Enter Email Address ");	
		document.reg_form.email.focus();
		return false;
	}
	if(document.reg_form.email.value.search(valid_email) == -1)	
	{
		alert("Please Enter Valid Email Address");	
		document.reg_form.email.value="";
		document.reg_form.email.focus();
		return false;
	}
	if(document.reg_form.confirm_email.value=="")	
	{
		alert("Please Enter Confirm Email Address");	
		document.reg_form.confirm_email.focus();
		return false;
	}
	if(document.reg_form.confirm_email.value.search(valid_email) == -1)
	{
		alert("Please Enter Valid Confirm Email Address");	
		document.reg_form.confirm_email.value=="";
		document.reg_form.confirm_email.focus();
		return false;
	}
	if(document.reg_form.email.value!=document.reg_form.confirm_email.value)	
	{
		alert("Email Address and Confirm Email Address Should be Same Address");	
		document.reg_form.confirm_email.focus();
		return false;
	}
	if(document.reg_form.security_code.value=="")	
	{
		alert("Please Enter Security Code");	
		document.reg_form.security_code.focus();
		return false;
	}
	/*if(document.reg_form.sec_code.value!=document.reg_form.code_sec.value)	
	{
		alert("Invalid Security Code:Please Re-Enter");	
		document.reg_form.sec_code.value="";
		document.reg_form.sec_code.focus();
		return false;
	}*/
}

function change_pass_validate()
{
	if(document.change_pass.old_password.value=="")	
	{
		alert("Please Enter Old Password");	
		document.change_pass.old_password.focus();
		return false;
	}
	if(document.change_pass.password.value=="")	
	{
		alert("Please Enter New Password");	
		document.change_pass.password.focus();
		return false;
	}
	if(document.change_pass.password.value.length<4)	
	{
		alert("New Password At least 4 characters");	
		document.change_pass.password.focus();
		return false;
	}
	if(document.change_pass.confirm_password.value=="")	
	{
		alert("Please Enter Confirm New Password");	
		document.change_pass.confirm_password.focus();
		return false;
	}
	if(document.change_pass.password.value!=document.change_pass.confirm_password.value)	
	{
		alert("New Password and New Confirm Password Should be Same");	
		document.change_pass.confirm_password.focus();
		return false;
	}	
}

function change_email_validate()
{
	var valid_email = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	if(document.email_form.email.value=="")	
	{
		alert("Please Enter New Email Address ");	
		document.email_form.email.focus();
		return false;
	}
	if(document.email_form.email.value.search(valid_email) == -1)	
	{
		alert("Please Enter Valid New Email Address");	
		document.email_form.email.value=="";
		document.email_form.email.focus();
		return false;
	}
	if(document.email_form.confirm_email.value=="")	
	{
		alert("Please Enter Confirm New Email Address");	
		document.email_form.confirm_email.focus();
		return false;
	}
	if(document.email_form.confirm_email.value.search(valid_email) == -1)
	{
		alert("Please Enter Valid Confirm New Email Address");	
		document.email_form.confirm_email.value=="";
		document.email_form.confirm_email.focus();
		return false;
	}
	if(document.email_form.email.value!=document.email_form.confirm_email.value)	
	{
		alert("New Email Address and Confirm New Email Address Should be Same Address");	
		document.email_form.confirm_email.focus();
		return false;
	}
}

//TUTORIAL COMMENTS FORM VALIDATION
function post_comment_validate()
{
	if(document.comment_form.FCKeditor1.value=="")	
	{
		alert("Please Enter Tutorial Comments");	
		document.comment_form.FCKeditor1.focus();
		return false;
	}	
}

//TUTORIAL FORM VALIDATION
function tutorial_form_validate()
{
	if(document.tutorial_form.title.value=="")	
	{
		alert("Please Enter Tutorial Title");	
		document.tutorial_form.title.focus();
		return false;
	}	
	if(document.tutorial_form.short_desc.value=="")	
	{
		alert("Please Enter Tutorial Description");	
		document.tutorial_form.short_desc.focus();
		return false;
	}	
	if(document.tutorial_form.game_type.value=="")	
	{
		alert("Please Select Tutorial Game Type");	
		document.tutorial_form.game_type.focus();
		return false;
	}	
	if(document.tutorial_form.category.value=="")	
	{
		alert("Please Select Tutorial Category");	
		document.tutorial_form.category.focus();
		return false;
	}	
	if(document.tutorial_form.tutorial_id.value=="")
	{
		if(document.tutorial_form.thumbnail.value=="")	
		{
			alert("Please Upload Tutorial Thumbnail");	
			document.tutorial_form.thumbnail.focus();
			return false;
		}
	}
}

//GROUP FORM VALIDATION
function group_form_validate()
{
	// declare which special chars to validate
	var illegalChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";	
	if(document.group_form.group_name.value=="")	
	{
		alert("Please Enter Group Name");	
		document.group_form.group_name.focus();
		return false;
	}	
	/*var strToSearch = document.getElementById('group_name').value;
	for (var i = 0; i < strToSearch.length; i++)
	{
		if (illegalChars.indexOf(strToSearch.charAt(i)) != -1)
		{
			alert ("Special Charater not allowed in Group Name.");
			document.getElementById('group_name').value="";
			document.getElementById('group_name').focus();
			return false;
		}
	}*/
	if(document.group_form.group_tag.value=="")	
	{
		alert("Please Enter Group Tag");	
		document.group_form.group_tag.focus();
		return false;
	}	
	var strTag = document.getElementById('group_tag').value;
	for (var i = 0; i < strTag.length; i++)
	{
		if (illegalChars.indexOf(strTag.charAt(i)) != -1)
		{
			alert ("Special Charater not allowed in Group/Clan Tag.");
			document.getElementById('group_tag').value="";
			document.getElementById('group_tag').focus();
			return false;
		}
	}
	if(document.group_form.group_desc.value=="")	
	{
		alert("Please Enter Group Description");	
		document.group_form.group_desc.focus();
		return false;
	}		
}

//MOD FORM VALIDATION
function mod_form_validate()
{
	if(document.mod_form.title.value=="")	
	{
		alert("Please Enter Mod Title");	
		document.mod_form.title.focus();
		return false;
	}	
	if(document.mod_form.description.value=="")	
	{
		alert("Please Enter Mod Description");	
		document.mod_form.description.focus();
		return false;
	}	
	if(document.mod_form.game_type.value=="")	
	{
		alert("Please Select The Game");	
		document.mod_form.game_type.focus();
		return false;
	}	
	if(document.mod_form.category.value=="")	
	{
		alert("Please Select The Category");	
		document.mod_form.category.focus();
		return false;
	}		
	
	//VALUE 4 IS FOR SOUNDS FILE
	if(document.mod_form.category.value==4)		
	{
		
		var screenshot = document.getElementsByName('screen_shot[]');
		var imageFileName = screenshot[0].value;
		if(imageFileName=="")	
		{
			alert("Please Upload Sound File");	
			return false;
		}
			
		var imgext = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);		
		//alert(imgext);
		if(imgext=="mp3" || imgext=="wav" || imgext=="flv" || imgext=="mp4")
		{		
			if(document.mod_form.mod_file.value!="")
			{	
				var fileName = document.mod_form.mod_file.value;
				var ext = fileName.substring(fileName.lastIndexOf('.') + 1);			
				if(ext=="zip" || ext=="rar" || ext=="ZIP" || ext=="RAR")
				{
					return true;
				}else{
					alert("Upload File must be Zip or Rar Format Only");
					return false;	
				}
			}
			
		}else{
			if(imageFileName!="")
			{
				alert("Sound File must be mp3, wav or mp4 Format Only");
				return false;
			}
		}
	}else{
		//alert(document.mod_form.mod_id);return false;
		//alert(document.getElementById("mod_id"));
		var screenshot = document.getElementsByName('screen_shot[]');
		var imageFileName = screenshot[0].value;
		//alert(imageFileName[0].value);
		if(imageFileName=="")	
		{
			alert("Please Upload Some screenshots");	
			//document.mod_form.screen_shot0.focus();
			return false;
		}
			
		var imgext = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
		//alert(imgext);
		if(imgext=="gif" || imgext=="jpg" || imgext=="tif" || imgext=="jpeg" || imgext=="JPG" || imgext=="JPEG" || imgext=="png" || imgext=="PNG")
		{		
			if(document.mod_form.mod_file.value!="")
			{	
				var fileName = document.mod_form.mod_file.value;
				var ext = fileName.substring(fileName.lastIndexOf('.') + 1);			
				if(ext=="zip" || ext=="rar" || ext=="ZIP" || ext=="RAR")
				{
					return true;
				}else{
					alert("Upload File must be Zip or Rar Format Only");
					return false;	
				}
			}
			
		}else{
			if(imageFileName!="")
			{
				alert("Screenshot must be Gif, Jpg, Png or Tif Format Only");
				return false;
			}
		}
	}
	
	if(document.mod_form.file_link.value=="" && document.mod_form.mod_file.value=="")
	{
		alert("Please enter Offsite Link Or Upload a File");
		document.mod_form.file_link.focus();
	    return false;
	}
	//document.getElementById("submit").disabled = true;
}

function mod_associate_validate() 
{
	if(document.associate_form.mod_id.value=="")
	{
		alert("Please Select Your Mod Name");
		document.associate_form.mod_id.focus();
		return false;
	}	
	if(document.associate_form.title.value=="")
	{
		alert("Please Enter Title");
		document.associate_form.title.focus();
		return false;
	}	
	if(document.associate_form.title.value.length>30)
	{
		alert("Title should be maximum 30 Characters");
		document.associate_form.title.focus();
		return false;
	}	
	if(document.associate_form.associate_content.value=="")
	{
		alert("Please Enter Associate Content");
		document.associate_form.associate_content.focus();
		return false;
	}	
}



//SHOW GROUP FORM MESSAGES
function show_group_msg(msg_group)
{
	if(msg_group=="1")
	{
		document.getElementById("group_1").style.display='';
		document.getElementById("group_2").style.display='none';	
		document.getElementById("group_3").style.display='none';
	}else if(msg_group=="2"){
		document.getElementById("group_2").style.display='';
		document.getElementById("group_1").style.display='none';	
		document.getElementById("group_3").style.display='none';
	}else if(msg_group=="3"){
		document.getElementById("group_3").style.display='';
		document.getElementById("group_1").style.display='none';	
		document.getElementById("group_2").style.display='none';
	}
}


//SHOW USER REGISTRATION FORM MESSAGES
function show_msg(msg)
{
	if(msg=="user_msg")
	{
		document.getElementById("user_msg").style.display='';	
		document.getElementById("pass_msg").style.display='none';	
		document.getElementById("con_pass").style.display='none';
		document.getElementById("email_msg").style.display='none';	
		document.getElementById("conf_email").style.display='none';
		document.getElementById("sec_code").style.display='none';
	}else if(msg=="pass_msg"){
		document.getElementById("pass_msg").style.display='';
		document.getElementById("con_pass").style.display='none';
		document.getElementById("user_msg").style.display='none';	
		document.getElementById("email_msg").style.display='none';	
		document.getElementById("conf_email").style.display='none';
		document.getElementById("sec_code").style.display='none';
	}else if(msg=="con_pass"){
		document.getElementById("con_pass").style.display='';	
		document.getElementById("pass_msg").style.display='none';		
		document.getElementById("user_msg").style.display='none';	
		document.getElementById("email_msg").style.display='none';	
		document.getElementById("conf_email").style.display='none';
		document.getElementById("sec_code").style.display='none';
	}else if(msg=="email_msg"){
		document.getElementById("email_msg").style.display='';
		document.getElementById("user_msg").style.display='none';	
		document.getElementById("pass_msg").style.display='none';
		document.getElementById("con_pass").style.display='none';
		document.getElementById("conf_email").style.display='none';
		document.getElementById("sec_code").style.display='none';
	}
	else if(msg=="conf_email"){
		document.getElementById("conf_email").style.display='';
		document.getElementById("email_msg").style.display='none';
		document.getElementById("user_msg").style.display='none';	
		document.getElementById("pass_msg").style.display='none';
		document.getElementById("con_pass").style.display='none';
		document.getElementById("sec_code").style.display='none';
	}
	else if(msg=="sec_code"){
		document.getElementById("sec_code").style.display='';
		document.getElementById("user_msg").style.display='none';	
		document.getElementById("pass_msg").style.display='none';
		document.getElementById("con_pass").style.display='none';
		document.getElementById("conf_email").style.display='none';
	}
}

//SHOW GROUP FORM MESSAGES
function show_homepage_content(select_value,no)
{
	//HIDE SECOND AND THIRD OPTION
	if(document.manage_homepage.content_type_1.value=="auto")
	{
		document.getElementById("show_row").style.display='none';	
	}else{
		document.getElementById("show_row").style.display='';	
	}
	//HIDE SECOND AND THIRD OPTION
	
	if(select_value!=="" && no!="")
	{	//alert(select_value);
		document.getElementById("content_"+no).style.display='none';	
		document.getElementById("mod_"+no).style.display='none';
		document.getElementById("tutorial_"+no).style.display='none';
		document.getElementById(select_value+"_"+no).style.display='';		
	}else{
		document.getElementById("content_"+no).style.display='none';	
		document.getElementById("mod_"+no).style.display='none';
		document.getElementById("tutorial_"+no).style.display='none';
	}
}






