//FUNCTION: PASSWORD
function password(length, special) {

	var iteration = 0;
	var password = "";
	var randomNumber;
	if(special == undefined) {
  
		var special = false;
		
	}

	while(iteration < length) {

		randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
		if (!special) {
  
			if ((randomNumber >= 33) && (randomNumber <= 47)) { continue; }
			if ((randomNumber >= 58) && (randomNumber <= 64)) { continue; }
			if ((randomNumber >= 91) && (randomNumber <= 96)) { continue; }
			if ((randomNumber >= 123) && (randomNumber <= 126)) { continue; }
			
		}

		iteration++;
		password += String.fromCharCode(randomNumber);
	}

return password;

}

function nascondiAvviso(){
	var el=document.getElementById('avviso');
	el.style.display='none';
}

function nascondiCome_funziona(){
	var el=document.getElementById('come_funziona');
	el.style.display='none';
}

function nascondiRiga(){
	$('#scoprilo').css('display','inline');
	$('#chiudere').css('display','none');
	document.getElementById("col_1").innerHTML= "";
	document.getElementById("col_2").innerHTML= "";
	document.getElementById("col_3").innerHTML= "";
	document.getElementById("col_4").innerHTML= "";
	$('.col_scoprilo').css('border-right','0px');
	$('.col_scoprilo').css('padding','0px');
	$('.col_scoprilo_2').css('padding','0px');
}

function visualizzaRiga(){
	$('#scoprilo').css('display','none');
	$('#chiudere').css('display','inline');
	document.getElementById("col_1").innerHTML= "<img src='img/n1.png' align='left' style='border:0px solid;padding-right:10px;'><span style='color:#474545;font-size:14px;'> Ogni giorno CarpeDeal propone un'<b>offerta strepitosa</b> nella tua citt&agrave;!</span>";
	document.getElementById("col_2").innerHTML= "<img src='img/n2.png' align='left' style='border:0px solid;padding-right:10px;'><span style='color:#474545;font-size:14px;'> Se sei interessato al deal puoi acquistarlo facilmente cliccando su <b>Compra!</b></span>";
	document.getElementById("col_3").innerHTML= "<img src='img/n3.png' align='left' style='border:0px solid;padding-right:10px;'><span style='color:#474545;font-size:14px;'> A fine giornata il deal si conclude e <b>ti arriva via e-mail</b> il coupon acquistato</span>";
	document.getElementById("col_4").innerHTML= "<img src='img/n4.png' align='left' style='border:0px solid;padding-right:10px;'><span style='color:#474545;font-size:14px;'>Potrai utilizzare il coupon <b>entro 6 mesi</b> dall'acquisto!</span>";
	$('.col_scoprilo').css('border-right','1px solid #D56A00');
	$('.col_scoprilo').css('padding','20px');
	$('.col_scoprilo_2').css('padding','20px');
}

function Set_Cookie( name, value, expires, path, domain, secure ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function changeCity(city){
	Set_Cookie('city',city, 1000, '/', '', '' );
	window.location.href="index.php";
}

function go(url){
	document.location.href=url;
}

function changeCityOtherCities(city){
	Set_Cookie('city',city, 1000, '/', '', '' );
	window.location.href="http://www.carpedeal.it";
}

function doConvert(){
	//var bodyID = document.getElementsByTagName("body")[0];
	var mainID = document.getElementById("main");
	var newFrame = document.createElement('iframe');
	newFrame.src = 'google_adv.html';
	newFrame.width = 1;
	newFrame.height= 1;
	mainID.appendChild(newFrame);
}

function isset(variable){
    return (typeof(variable) != 'undefined');
}

/*
function Login(city,provenienza){
	FB.api('/me', function(response) {
		if(isset(response['email'])){
			var data = {email: response['email'], city: city, provenienza: provenienza};
			//SEND DATA
			$.ajax({
				type: "POST", 
				url: "adv/subscribed@add.php",
				data: data,
				complete: function(data){
					$('#callback').html(data.responseText);
				}
			});
		}
	})
};
*/
