function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

function Email(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return false;
    else
        return true;
}

function Numero(string) {
    if (!string) return false;
    var Chars = "0123456789-";
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
} 

function AlphaNumeric(string) {
    if (!string) return false;
    var Chars = "0123456789abcdefghijklmnñopqrstuvwxyz";
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
} 

function checkcard() 
{
	if (document.precard.CardTitle.value== "")
	{document.precard.CardTitle.focus();
	 alert('You must write a title for the postcard');
	 return false;
	}
	
	if (document.precard.CardMessage.value== "")
	{document.precard.CardMessage.focus();
	 alert('You must write a message');
	 return false;
	}
	
	if ((document.precard.CardFromName.value== "") || (document.precard.CardFromName.value== "your name here"))
	{document.precard.CardFromName.focus();
	 alert('You must indicate the sender\'s name');
	 return false;
	}
	
	var posta=document.precard.CardFromEmail.value
	if ((document.precard.CardFromEmail.value== "") || (document.precard.CardFromEmail.value== "your e-mail here"))
	{document.precard.CardFromEmail.focus();
	 alert('You must indicate the senders\'s email');
	 return false;
	}
	
	if((((posta.match(/@/)) && (posta.match(/\./))) == null)||(Email(posta)))
	{document.precard.CardFromEmail.focus();
	 alert('You must write a correct email');
	 return false;
	}
	
	if ((document.precard.CardToName.value== "") || (document.precard.CardToName.value== "recipient's name"))
	{document.precard.CardToName.focus();
	 alert('You must indicate the receiver\'s name');
	 return false;
	}
	
	var posta=document.precard.CardToEmail.value
	if ((document.precard.CardToEmail.value== "") || (document.precard.CardToEmail.value== "recipient's e-mail"))
	{document.precard.CardToEmail.focus();
	 alert('You must indicate the receiver\'s email');
	 return false;
	}
	
	if((((posta.match(/@/)) && (posta.match(/\./))) == null)||(Email(posta)))
	{document.precard.CardToEmail.focus();
	 alert('You must write a correct email');
	 return false;
	}
	return true;
}


function checkreservation() 
{
	if (document.sendres.name.value== "")
	{document.sendres.name.focus();
	 alert('You must indicate a name');
	 return false;
	}
	
	if (document.sendres.lastname.value== "")
	{document.sendres.lastname.focus();
	 alert('You must indicate a last name');
	 return false;
	}
	
	if (document.sendres.address.value== "")
	{document.sendres.address.focus();
	 alert('You must indicate an address');
	 return false;
	}
	
	if (document.sendres.city.value== "")
	{document.sendres.city.focus();
	 alert('You must indicate a city');
	 return false;
	}
	
	if (document.sendres.address.value== "")
	{document.sendres.address.focus();
	 alert('You must indicate an address');
	 return false;
	}

	if ((document.sendres.country.selectedIndex == 0) || (document.sendres.country.selectedIndex == 1))
	{document.sendres.country.focus();
	 alert('You must indicate a country');
	 return false;
	}
	
	if (document.sendres.poc.value== "")
	{document.sendres.poc.focus();
	 alert('You must indicate a postal code');
	 return false;
	}
	
	if (document.sendres.phone.value== "")
	{document.sendres.phone.focus();
	 alert('You must indicate a phone');
	 return false;
	}
	
	var posta=document.sendres.email.value
	if (document.sendres.email.value== "")
	{document.sendres.email.focus();
	 alert('You must indicate an email');
	 return false;
	}
	
	if((((posta.match(/@/)) && (posta.match(/\./))) == null)||(Email(posta)))
	{document.sendres.email.focus();
	 alert('You must write a correct email');
	 return false;
	}
	
	if ((document.sendres.datearrive1.selectedIndex == 0) || (document.sendres.datearrive1.selectedIndex == 1))
	{document.sendres.datearrive1.focus();
	 alert('You must indicate a month');
	 return false;
	}
	
	if ((document.sendres.datearrive2.selectedIndex == 0) || (document.sendres.datearrive2.selectedIndex == 1))
	{document.sendres.datearrive2.focus();
	 alert('You must indicate a day');
	 return false;
	}
	
	if ((document.sendres.datearrive3.selectedIndex == 0) || (document.sendres.datearrive3.selectedIndex == 1))
	{document.sendres.datearrive3.focus();
	 alert('You must indicate a year');
	 return false;
	}
	
	if (document.sendres.adults.value== "")
	{document.sendres.adults.focus();
	 alert('You must indicate a quantity');
	 return false;
	}
	
	if ((document.sendres.contact.selectedIndex == 0) || (document.sendres.contact.selectedIndex == 1))
	{document.sendres.contact.focus();
	 alert('You must indicate a contact mode');
	 return false;
	}
	
	return true;
}


function newWindow(url,name,features){
var newWin = window.open(url,name,features);
}

function popcard(swf){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/postcards/makecard.php?file='+swf,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}


function popread(query){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/postcards/viewcard.php?'+query,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}

function popresad(query){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/reservation/index.php?'+query,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}

function yousure() { 
 if (confirm("Are you sure you want to delete this record?")) { 
return true; 
 } else { 
return false; 
 } 
}

