// JavaScript Document
// Description:  This script validate the send a friend section of the video section. 
function echeck(str) {
		//Description:  This function checks that an email has a proper syntax.
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }
 		 return true					
	}



function ValidateForm_userupload(){

	//Description: Validate the from User Upload on the videos section of the insight magazine 
	var email=document.uploadfiles.txtEmail
	var nick = document.uploadfiles.txtNickname
	var vname = document.uploadfiles.txtVideoName
	var vdescription = document.uploadfiles.txtDescription
	var vfile = document.uploadfiles.vfile
	
	if((nick.value==null)|| (nick.value==""))
	{
	
	  alert("Please Enter Your Nick Name")
	  nick.focus()
	  return false
	}
	if((email.value==null)|| (email.value==""))
	{
	
	  alert("Please Enter a Valid Email Addressed")
	  email.focus()
	  return false
	}
	
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	
	if((vname.value==null)|| (vname.value==""))
	{
	
	  alert("Please Enter a Title for Your Video")
	  vname.focus()
	  return false
	}
	
	if((vdescription.value==null)|| (vdescription.value==""))
	{
	
	  alert("Please Enter a Title for Your Video")
	  vdescription.focus()
	  return false
	}
	
	if((vfile.value==null)|| (vfile.value==""))
	{
	
	  alert("Please Enter a video file path")
	  vfile.focus()
	  return false
	}
   ShowProgress()	
	return true
 }
 
 function ValidateForm_send_tofriend(){

//Description: validates form sent to friend on the video section 
	var efriend=document.emailafriend.txtFrieds
	var eyours = document.emailafriend.txtYours
	
	
	if((eyours.value==null)|| (eyours.value==""))
	{
	
	  alert("Please enter a valid email for you")
	  eyours.focus()
	  return false
	}
	
	if (echeck(eyours.value)==false){
		eyours.value=""
		eyours.focus()
		return false
	}
	
	if ((efriend.value==null)||(efriend.value=="")){
		alert("Please Enter a valid e-mail for your friend")
		efriend.focus()
		return false
		
	}
	
	if (echeck(efriend.value)==false){
		efriend.value=""
		efriend.focus()
		return false
	}
	
	return true
 }
