function createUrlCookie() {

      var name = "originUrl";
      var value = document.URL;
      var days = 1;  
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";

}



function createProdCookie() {
// executed just if the cookie is empty -> so value will contain just one product
      var name = "prodToform";
      var value = document.getElementById('prodName').innerHTML;
      var days = 1;  
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";


createUrlCookie();

}


function Delete_Cookie( name, path, domain ) {
if ( readCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function FillForm() 
{

var valuetoadd = readCookie('prodToform');
if (valuetoadd)
{
 document.getElementById("desc").innerHTML = "Please, send me more information about "+valuetoadd;

$("#fillProdName").text(valuetoadd);
$("#fillProdName").addClass("prodAdded");

Delete_Cookie('prodToform','/','');
}
}

function privacyCheck() 
{

 if (document.getElementById('privacycheckbox').checked) 
     {
    document.getElementById('submitbutton').style.display = 'block';
    document.getElementById('submitbuttonOFF').style.display = 'none';
     }
 else
    {
    document.getElementById('submitbutton').style.display = 'none';
    document.getElementById('submitbuttonOFF').style.display = 'block';
     }
}
 

function privacyChange()
{
    if ($("#privacycheckbox").is(':checked'))
    {
       $("#submitbutton").removeAttr("disabled");
       $("#submitbutton").removeClass("isDisabled");
       $("#submitbuttonLayerOver").hide();
    }
    else
    {
       $("#submitbutton").attr("disabled","disabled");
       $("#submitbutton").addClass("isDisabled");
       $("#submitbuttonLayerOver").show();
    }

}




$(document).ready(function(){



if ($("#webpacForm").length != 0)
{
var frmvalidator = new Validator("webpacForm");
frmvalidator.addValidation("contacts_firstname","req","First name is a required field");
frmvalidator.addValidation("contacts_lastname","req","Last name is a required field");
frmvalidator.addValidation("contacts_email","email","Email is incorrect");
frmvalidator.addValidation("contacts_email","req","Email is a required field");
frmvalidator.addValidation("contacts_telephone","phone","Telephone is incorrect");
frmvalidator.addValidation("contacts_homefacsimile","phone","Fax is incorrect");
frmvalidator.addValidation("contacts_acceptedprivacy","req","Please mark the checkbox verifying that you have read and agree to our privacy policy");
afterProcess();

 FillForm();



  $("#webpacForm").submit(function(){
    if (!($("#privacycheckbox").is(':checked')))
 {   alert("You have to accept Quadpack Privacy Statement before sending the form.");
    return false;
}
  });

  

  $("#submitbuttonLayerOver").click(function(){
    if ($("#submitbutton").is(':disabled'))
    {
       alert("You have to accept Quadpack Privacy Statement before sending the form.");
    }
   

  });
 }
});
