// JavaScript Document
function validate()
{
	if(document.form1.title.value=="selecttitle")
	{
		alert("Please Select Title");
		document.form1.title.focus();
		return false;
	}
	if(document.form1.fname.value=="")
	{
		alert("Please Enter Firstname");
		document.form1.fname.focus();
		return false;
	}
	if(document.form1.lname.value=="")
	{
		alert("Please Enter Lastname");
		document.form1.lname.focus();
		return false;
	}
	if(document.form1.email.value=="")
	{
		alert("Please Enter Email");
		document.form1.email.focus();
		return false;
	}
	else
	{
		if(!func_is_email(document.form1.email.value))
		{
			alert("Incorrect email format !! Please enter proper email");
			document.form1.email.focus();
			return false;
		}
	}
	
	if(document.form1.media.value=="selectmedia")
	{
		alert("Please Select Media");
		document.form1.media.focus();
		return false;
	}
	
	if(document.form1.pub_website.value=="")
	{
		alert("Please Enter Website");
		document.form1.pub_website.focus();
		return false;
	}
	else
	{
		var v = new RegExp(); 
    	v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
    	if (!v.test(document.form1.pub_website.value)) 
		{ 
        	alert("You must supply a valid url starts from http://");
        	return false; 
    	} 
	}
}

function func_show_other_media()
{
		if(document.form1.media.value=="0")
		{ 
			document.getElementById('other_media').style.display = "block"; 
		}
		else
		{
			document.getElementById('other_media').style.display = "none"; 
		}
}

function isUrl(url) 
{
	//var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)( 0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/	
	return regexp.test(url);
}

/*function Validate(form) 
{ 
    var v = new RegExp(); 
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
    if (!v.test(form["URL"].value)) 
	{ 
        alert("You must supply a valid URL."); 
        return false; 
    } 
} */


function func_show_other_title()
{
		if(document.form1.title.value=="0")
		{ 
			document.getElementById('other_title').style.display = "block"; 
		}
		else
		{
			document.getElementById('other_title').style.display = "none"; 
		}
}

function func_is_email(param_email)
{
	var str_current_character;
	var b_valid_email,b_period_present; 
	var i_last_position_of_period,b_correct_length_extension;
	var i_num_at_symbol=0;
	var i_pos_at_symbol;
	var i_length_of_server_name=1;
	var i_pos_consecutive_dots;
	var str_email=new String(func_trim(param_email));
	i_length=str_email.length;
	b_period_present=1;
	b_correct_length_extension=1;
	i_last_position_of_period=0;
	
	if(i_length==0)
	{
		return true;
	}
	
	for(i_loop=0; i_loop<i_length; i_loop++)
	{
		if(!((str_email.charCodeAt(i_loop)>=65 && str_email.charCodeAt(i_loop)<=90)
		  || (str_email.charCodeAt(i_loop)>=97 && str_email.charCodeAt(i_loop)<=122)
		  || (str_email.charCodeAt(i_loop)>=48 && str_email.charCodeAt(i_loop)<=57)
		  || (str_email.charAt(i_loop)=="@")
		  || (str_email.charAt(i_loop)=="_")
		  || (str_email.charAt(i_loop)=="-")
		  || (str_email.charAt(i_loop)=="'")
		  || (str_email.charAt(i_loop)==".")))
		{
			return false;
		}
	}
	
	i_pos_consecutive_dots=str_email.indexOf('..');
	if(i_pos_consecutive_dots!=-1)
	{
		return false;
	}
	
	var i_pos_space;
	i_pos_space = str_email.indexOf(' ');
	if(i_pos_space!=-1)
	{
		return false;
	}
	
	i_last_position_of_period = str_email.lastIndexOf('.');
	if(i_last_position_of_period<=0)
	{
		b_period_present=0;
	}
	
	if(((i_length-i_last_position_of_period)>4) || ((i_length-i_last_position_of_period)<3))
	{
		b_correct_length_extension=0;
	}
	
	for(i_loop=0;i_loop<=i_length;i_loop++)
	{
		str_current_character=str_email.charAt(i_loop);
		if (str_current_character=='@')
		{
			i_num_at_symbol=i_num_at_symbol + 1;
		}
	}
	
	if(i_num_at_symbol!=1)
	{
		return false;
	}
	
	i_pos_at_symbol = str_email.indexOf('@');
	if(str_email.charAt(i_pos_at_symbol+1) == '.')
	{
		i_length_of_server_name=0;
	}
	
	if((i_num_at_symbol==1) && (b_period_present==1) && (b_correct_length_extension==1) && (i_length_of_server_name==1))
	{
		b_valid_email=1;
	}
	else
	{
		 b_valid_email=0;
	}
	
	if(b_valid_email==0)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function func_trim(param_text)
{
	var str_text=new String(param_text);
	var str_return_text;
	str_return_text="";
	b_non_blank_started=false;
	b_non_blank_ended=false;
	str_intermediate_blank_chunk="";
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(str_text.charCodeAt(i_loop)!=32)
		{
			if(!b_non_blank_started)
			{
				b_non_blank_started=true;
			}
			if(b_non_blank_started && !b_non_blank_ended)
			{
				str_return_text+=str_text.charAt(i_loop);
			}
			if(b_non_blank_ended)
			{
				str_return_text+=(str_intermediate_blank_chunk+str_text.charAt(i_loop));
				b_non_blank_ended=false;
				str_intermediate_blank_chunk="";
			}
		}
		else
		{
			if(b_non_blank_started)
			{
				b_non_blank_ended=true;
				str_intermediate_blank_chunk+=" ";
			}
		}
	}
	return str_return_text;
}


