	function CheckPhone(tel)
	{
		allowed="1234567890.-/";
		for (i = 0; i < tel.length; i++)
		{
			var c=tel.charAt(i);
			// test for spaces
			if(c != " ")
			{
				if(allowed.indexOf(c)==-1)
					return false;
			}		
		}
		return true;
	}

	function validare(param)
	{
	    var username,password,password_cf,firstname,lastname,email,email_cf,city,zip_code,state;
 		
 	    if(param!=1)
		{
		    login=document.contfrm.username;
			password=document.contfrm.password;
 		    password_cf=document.contfrm.password1;		
			email_cf = document.contfrm.email1;
		}	
	    firstname=document.contfrm.fname;
	    lastname=document.contfrm.lname;
	    email=document.contfrm.email;
	    city=document.contfrm.city;		
	    zip_code=document.contfrm.zip;		
	    state=document.contfrm.state;
		
		if(param!=1)
		{
	  	    if (login.value.length==0)
	  	    {
	   	    	alert ("Please insert 'Desired login'!");
				login.focus();
	    		login.select();
	    		return false;
	   	    }
			else
			{
				//detect spaces
				splitlogin = login.value.split(" ");
				if(splitlogin.length > 1)
				{
		   	    	alert ("Please remove spaces from 'Desired login'!");
					login.focus();
		    		login.select();
	    			return false;
				}
				else
				{
				if(CheckPhone(login.value))
					{
		   	    	alert ("'Desired login' must contain characters too!");
					login.focus();
		    		login.select();
	    			return false;
					}
				}
			}			
		    if (password.value.length<6 || password.value!=password_cf.value)
	  	    {
		   		alert ('Please insert a correct password!');
		   		password.focus();
	    		password.select();
				return false;
		    }
		}	
  	    if (firstname.value.length<2)
  	    {
   	    	alert ("Please insert your 'First name'!");
			firstname.focus();
    		firstname.select();
    		return false;
   	    }
  	    if (lastname.value.length<2)
  	    {
   	    	alert ("Please insert your 'Last name'!");
			lastname.focus();
    		lastname.select();
    		return false;
   	    }		

		/* alta varianta
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (!filter.test(email.value))*/
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
	    {
	    	alert('Incorrect email address!');
			email.focus();
			email.select();
			return false;
	    } 
		if(param != 1)
		{
		    if (email.value!=email_cf.value)
	  	    {
		   		alert ('Your email confirmation is incorrect!');
		   		email_cf.focus();
	    		email_cf.select();
				return false;
		    }
		}
  	    if (city.value.length==0)
  	    {
   	    	alert ("Please insert 'City'!");
			city.focus();
    		city.select();
    		return false;
   	    }				
  	    if (state.value=="Please Select")
  	    {
   	    	alert ("Please select 'State'!");
    		return false;
   	    }				

		if(zip_code.value.length==0)
		{
			alert ("Please insert a valid 'zip code'");
			zip_code.focus();
			zip_code.select();
			return false;
		}	   
	

   	}

	function validare_contact()
	{
	    var firstname,lastname,email,city,country,phone,comments;
	    firstname=document.contactfrm.firstname;
	    lastname=document.contactfrm.lastname;
	    email=document.contactfrm.email;
	    city=document.contactfrm.city;		
	    country=document.contactfrm.country;		
	    phone=document.contactfrm.phone;		
	    comments=document.contactfrm.comments;				
 		
  	    if (firstname.value.length==0)
  	    {
   	    	alert ("Please insert your 'First name'!");
			firstname.focus();
    		firstname.select();
    		return false;
   	    }
  	    if (lastname.value.length==0)
  	    {
   	    	alert ("Please insert your 'Last name'!");
			lastname.focus();
    		lastname.select();
    		return false;
   	    }		
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
	    {
	    	alert('Incorrect email address!');
			email.focus();
			email.select();
			return false;
	    }
  	    if (city.value.length==0)
  	    {
   	    	alert ("Please insert 'City'!");
			city.focus();
    		city.select();
    		return false;
   	    }				
	    if(document.forms['contactfrm'].elements['country'].value==0)
	    {
			alert('Please select your country!');
			return false;
	    }
		if(phone.value.length!=0) 
		{
			if(!CheckPhone(phone.value))
			{			
				alert ('Please insert a correct phone number!');
				phone.focus();
				phone.select();
				return false;
			}	
	    }
  	    if (comments.value.length==0)
  	    {
   	    	alert ("Please type your comment!");
			comments.focus();
    		comments.select();
    		return false;
   	    }		
   	}
	
	function CK_log(frm)
	{
	    var uname,pass;
	    uname=document.forms[frm].uname;
 	    pass=document.forms[frm].pass;
  	    if (uname.value.length==0)
  	    {
   	    	alert ("Please insert your login!");
			uname.focus();
    		uname.select();
    		return false;
   	    }
  	    if (pass.value.length==0)
  	    {
   	    	alert ("Please insert password!");
			pass.focus();
    		pass.select();
    		return false;
   	    }
	}

	function CK_image(fru)
	{
	    var up_image;
	    up_image = document.forms[fru].up_image;
  	    if (up_image.value.length==0)
  	    {
   	    	alert ("Please choose a image file!");
			up_image.focus();
    		up_image.select();
    		return false;
   	    }
		/*else
		{
			var file;
			file = up_image.value;
			extArray = new Array(".jpg", ".jpeg");
			allowSubmit = false;

			while (file.indexOf("\\") != -1)
				file = file.slice(file.indexOf("\\") + 1);
			ext = file.slice(file.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArray.length; i++)
			{
				if (extArray[i] == ext) { allowSubmit = true; break; }
			}

			if(!allowSubmit)
			{
	   	    	alert ("Please choose a JPG image file!");
				up_image.focus();
    			up_image.select();
    			return false;
			}
		}*/
		else
		{
			document.all['td1'].style.display='none';
			document.all['td2'].style.display='block';
			return true;
		}	
	}

	function CK_image_ag(fru)
	{
	    var up_image;
	    var terms;
	    terms = document.forms[fru].terms;
	    up_image = document.forms[fru].up_image;
	    
	    if (terms.checked == false)
  	    {
   	    	alert ("Please read the terms and conditions and tick the checkbox if you agree.");
			return false
	    }
  	    if (up_image.value.length==0)
  	    {
   	    	alert ("Please choose a image file!");
			up_image.focus();
    		up_image.select();
    		return false;
   	    }
	    
	}

	function CK_upload(T)
	{
	    var name,description,keywords,terms;
	    name=document.uploadfrm1.title;
	    description=document.uploadfrm1.description;		
	    keywords=document.uploadfrm1.keywords;		
	    terms=document.uploadfrm1.terms;		
  	    
		if (name.value.length==0)
  	    {
   	    	alert ("Please type an image title!");
			name.focus();
    		name.select();
    		return false;
   	    }
  	    if (description.value.length==0)
  	    {
   	    	alert ("Please type an image description!");
			description.focus();
    		description.select();
    		return false;
   	    }
		if(name.value == description.value)
		{
			alert("Title and description have identical data. Please provide a more accurate description of the image.");
			description.focus();
    		description.select();
    		return false;
		}
	    if(document.forms['uploadfrm1'].elements['category_1'].value==0 && document.forms['uploadfrm1'].elements['category_2'].value==0 && document.forms['uploadfrm1'].elements['category_3'].value==0)
	    {
			alert('Please select one or more categories for image!');
			return false;
	    }
  	    if (keywords.value.length==0)
  	    {
   	    	alert ("Please type few keywords for image!");
			keywords.focus();
    		keywords.select();
    		return false;
   	    }		
		if(T == 0)
		{
			if (terms.checked == false)
  		    {
   				alert ("Please read the terms and conditions and tick the checkbox if you agree!");
    			return false;
	   	    }		
		}
		return;
	}
	
	function validare_board()
	{
	    var subject,message;
	    subject=document.boardfrm.subject;
	    message=document.boardfrm.message;		
		
  	    if (subject.value.length==0)
  	    {
   	    	alert ("Please type the subject!");
			subject.focus();
    		subject.select();
    		return false;
   	    }		
  	    if (message.value.length==0)
  	    {
   	    	alert ("Please type the message!");
			message.focus();
    		message.select();
    		return false;
   	    }				
	}
	
	function ConvertCF()
	{
	    var convertvalue;
	    convertvalue=document.convertfrm.convertvalue;
		
  	    if (convertvalue.value.length==0 || convertvalue.value==0 || isNaN(convertvalue.value))
  	    {
   	    	alert ("Incorrect credits value!");
			convertvalue.focus();
    		convertvalue.select();
    		return false;
   	    }		
	}	
	
	function PayCK()
	{
	    var payvalue;
	    payvalue=document.payfrm.payvalue;
  	    if (payvalue.value.length==0 || payvalue.value==0 || isNaN(payvalue.value))
  	    {
   	    	alert ("Incorrect payment value!");
			payvalue.focus();
    		payvalue.select();
    		return false;
   	    }		
	}		
	
	function ImageDownCK(frmname)
	{
	    var agree;		
		agree=document.forms[frmname].agree;
  	    if (agree.checked == false)
  	    {
   	    	alert ("Please read the terms and conditions and tick the checkbox if you agree.");
			return false
   	    }
		else
			return true;
	}

	function TermsCK(frmname)
	{
	    var agree;		
		agree=document.forms[frmname].agree;
  	    if (agree.checked == false)
  	    {
   	    	alert ("Please read the terms and conditions and tick the checkbox if you agree.");
			return false
   	    }
		else
			return true;
	}


	function PassCK()
	{
	    var email_request;
	    email_request=document.passfrm.email_request;

		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_request.value)))
	    {
	    	alert('Incorrect email address!');
			email_request.focus();
			email_request.select();
			return false;
	    }
	}
	
	function ConfirmDelete(frm)
	{
		if (window.confirm("Are you sure you want to delete this file?"))
			document.forms[frm].submit();
	} 
	
	function DisableImage(frm)
	{
		var rd_confirm = document.forms[frm].rd_confirm;
		var reason = document.forms[frm].reason.value;
		if(!rd_confirm[0].checked)
		{
			alert("Please select YES to disable image");
			return false;
		}
		if(reason.length < 3)		
		{
			alert("Please write a reason to disable image");
			return false;
		}
		return true;
	}
	
	function BNewsAdd(field)
	{
		var news = document.forms['frforum'].message;		
		if(news.value.length == 0)
		{
			alert("Please type your text!");
			news.focus();
			news.select();
			return false;
		}
		else
		{
			var MaxCharacters = 255;
			if (news.value.length > MaxCharacters)
			{
				alert('Please type maximum '+MaxCharacters+' characters in this field!');
				news.value = news.value.substring(0, MaxCharacters);
				return false;
			}
		}
	} 
	
	function CollectionsCheck(forma,imageid)
	{
		var collectionid = forma.collectionid.value;
		if(collectionid == 0)
		{
			alert('Please select a collection!');
			return false;
		}
		if(collectionid == -1)
		{
			forma.do_action.value="";
			forma.collectionid.value="";
			forma.action = "collections.php?image_identifier="+imageid+"#point";
		}	
	}
	
	function CollectionsAdd(forma,mode)
	{
		if(mode == 1)
			var image_identifier = forma.image_identifier;		
		var ctitle = forma.ctitle;				
		var cdescription = forma.cdescription;				
		var ckeywords = forma.ckeywords;
						
		if(mode == 1)
		{
			if(image_identifier.value.length == 0)
			{
				alert("Please paste the ID or URL of the first image!");
				image_identifier.focus();
				image_identifier.select();
				return false;
			}
		}	
		if(ctitle.value.length == 0)
		{
			alert("Please type title of collection!");
			ctitle.focus();
			ctitle.select();
			return false;
		}
		if(cdescription.value.length == 0)
		{
			alert("Please type description!");
			cdescription.focus();
			cdescription.select();
			return false;
		}				
		if(ckeywords.value.length == 0)
		{
			alert("Please type keywords!");
			ckeywords.focus();
			ckeywords.select();
			return false;
		}		
	}
	
	function CollectionsSearch(forma)
	{
		var srh_coll = forma.srh_coll;				
		if(srh_coll.value.length == 0 || srh_coll.value=="your keyword here")
		{
			alert("Please type keywords!");
			srh_coll.focus();
			srh_coll.select();
			return false;
		}		
	}
	
	function PaymentRequest(forma)
	{
		var paytype = forma.paytype;				
		var paypalid = forma.paypalid;

		if(paytype[0].checked)
		{
			if(paypalid.value == "")
			{
				alert("Please complete your paypal ID!");
				paypalid.focus();
				paypalid.select();
				return false;
			}
			return true;
		}
		return true;
	}

	function OMS_review(forma)
	{
		var message = forma.message;				
		var do_action = forma.do_action;				
		var reason = forma.reason;				
		var coll = forma.elements;
		if(do_action.value == "escalate")
		{
			if(message.value.length == 0)
			{
				alert("Please type message to site admins!");
				message.focus();
				message.select();
				return false;
			}
		}
		if(do_action.value == "refuse")
		{
			check = false;
			nr = coll.length;
			for (i=0;i<=nr;i++)
			{
				if(null != coll[i] &&  null != coll[i].name)
				{
					if(coll[i].name.substr(0,3)=="rs_")
					{
						if(coll[i].checked == true)
						{		
							check = true;
						}
					}
				}	
			}
			if(reason.value.length == 0 && !check)
			{
				alert("Please type or choose reason to refuse image!");
				reason.focus();
				reason.select();
				return false;
			}
		}
	}
	
