﻿	function setCookie(name, value, expires, path, domain, secure) {
		document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
	}
	
	function fadeinplayer() { 
		$('div.taustavideoplayer').fadeIn(2000);
	}
	function fadeoutplayer() { 
		$('div.taustavideoplayer').fadeOut(2000);
	}
	function fadeoutplayer2() { 
		$('div.video1').fadeOut(2000);
	}
	function piilotakirjautuminen() { 
		$("div.videopaikka1").remove();
		$("div.videoplayeri2").remove();
	}

function ValidPhone(field)
{
	if(field=="") 
	{
	return false;
	}
	
    var ValidChars = "0123456789.+";
    var IsNumber=true;
    var Char;

	for (i = 0; i < field.length && IsNumber == true; i++) 
    { 
    Char = field.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
    {
      return false;
     }
    }

	return true
}

function valid_date(field)
{
	if(field=="")
	{
	alert("Please fill in all details!")
	return false;
	}
	
	

	var valid = "0123456789/";
	var slashcount = 0;

	if (field.length!=10) 
	{
	alert("Invalid date! The correct date format is like '01/01/2004'.   Please try again.")
	return false;
	}
		for (var i=0; i < field.length; i++)
		 {
		temp = "" + field.substring(i, i+1);
		if (temp == "/") 
		slashcount++;
			if (valid.indexOf(temp) == "-1") 
			{
			alert("Invalid characters in your date.  Please try again.")
			return false;
			}
		if (slashcount > 2) 
		{
		alert("Invalid Date!  The slash character should be used with a properly formatted 8 digits like  '01/01/2004'.   Please try again.")
		return false;
  		 }
		if((field.charAt(2)!= '/')||(field.charAt(5) != '/'))
		{
		alert("Invalid date! The slash character should be used with a properly formatted 8 digits like  '01/01/2004'.   Please try again.")
		return false;
		}
	}
	return true;


}

function valid_required(field)
{
	if(field=="") 
	{
	return false;
	}

	return true;
}


function EmailValid(email)
	{
		if(email=="")
		{
		alert("Email is required field!")
		return false
		}
		len = email.length
		
		if((email.charAt(1)=='@')||(email.charAt(1)=='.'))
		{
		alert("Invalid Email Please try again!")
		return false
		}
		if((email.charAt(len-2)=='@')||(email.charAt(len-2)=='.'))
		{
		alert("Invalid Email Please try again!")
		return false
		}
		
				

		count=0
		dotcount=0
	for (i=0; i< email.length; i++)
		{
			if(email.charAt(i)=='@')
			count++
			if(email.charAt(i)=='.')
			dotcount++
		 }
		
			 if((count !=1)||(dotcount !=1))
			 	{
			 	alert("Invalid Email Please try again!")
			 	return false
			 	}
		
		
	return true
	}



function tarkista()
{

		//call valid_required function to check if field is not empty for first name
         if(!valid_required(document.yhtotto.first_name.value))
         {
		alert("Please fill in all details!")
         return false
         }
		 
		//call valid_required function to check if field is not empty for last name
             if(!valid_required(document.yhtotto.last_name.value))
        {
		alert("Please fill in all details!")
         return false
         }
		 
		// call ValidPhone function to validate phone field value
         if(!valid_required(document.yhtotto.phone.value))
         {
		 alert("Please fill in all details!")
         return false
         }
		 
		//call Emailvalid function to validate email entered by user
         if(!valid_required(document.yhtotto.email.value))
         {
		 alert("Please fill in all details!")
         return false
         }


	// if everything passed - return true
	return true
}

function tarkistademotunnus()
{

		//call valid_required function to check if field is not empty for first name
         if(!valid_required(document.form1.contactName.value))
         {
		alert("Please fill in all details!")
         return false
         }
		 
		//call valid_required function to check if field is not empty for last name
             if(!valid_required(document.form1.contactCompany.value))
        {
		alert("Please fill in all details!")
         return false
         }
		 
		// call ValidPhone function to validate phone field value
         if(!valid_required(document.form1.contactPhone.value))
         {
		 alert("Please fill in all details!")
         return false
         }
		 
		//call Emailvalid function to validate email entered by user
         if(!valid_required(document.form1.contactEmail.value))
         {
		 alert("Please fill in all details!")
         return false
         }


	// if everything passed - return true
	return true
}


