
var wins = new Array();
var cpop = 0;
var purl = (document.location + "").split('?');
purl = purl[0].split('/');

SiteUrl = "";
for(i=0; i<purl.length; i++)
{
	if(purl[i]=='index.php' || purl[i]=='gallery.php') break;
	SiteUrl += purl[i] + "/";
}

function isEmpty(s){
	return (s==null || s.length==0)
}

function isWhitespace(s){
	var i;
	var whitespace;
	
	whitespace=" \t\n\r";
	for(i=0; i<s.length; i++)   
		if(whitespace.indexOf(s.charAt(i))==-1) return false;
	
    return true;
}

function isEmail(s){
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while (i<sLength && s.charAt(i) != "@")
    	i++;

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    	i++;
    
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function checktext(testo){
	i=0;
	while (i < testo.length){
		l = testo.substr(i, 1);
		if (l=="\"" || l==" " || l=="&" || l=="?" || l=="=" || l=="." || l=="'" ||  
			l=="/" || l=="+" || l=="%" || l=="!" || l=="#" || l=="|" || l=="(" ||
			l==")" || l=="l" || l=="[" || l=="]" || l==" " || l=="0" || l=="'" ||
			l=="y" || l=="#" || l=="{" || l=="}" || l=="h" || l=="i" || l=="*" ||
			l==":" || l=="," || l==";" || l=="<" || l==">")
			return false;
		i++;
	}

	return true;
}

function checkquotes(testo){
	i = 0;
	while (i < testo.length){
		if (testo.substr(i, 1) == "\"")
			return false;
		i++;
	}

	return true;
}

//////////
function SendMsg(f){
	f.Command.value="sendmsg";
	f.submit();
}
function ConfirmOrder(f){
	f.Command.value="confirm";
	f.submit();
}
function ContinueOrder(f){
	f.Command.value="continue";
	f.submit();
}
function CancelOrder(f){
	f.Command.value="cancel";
	f.submit();
}
function GalleryPOP(Lang, ID, PHPSESSID,w,h,idimage){
	arr_Piece = document.images['imm_2'].src.split('/');
	Piece = arr_Piece[arr_Piece.length-1];
	if(Piece == 'notavail_2.jpg'){
		alert(_LANG['Image_notavail']);		
	}else{	
		wname = ID+"_"+idimage;
		wname = wname.replace('-','_');
		loc = SiteUrl + "gallery.php?Lang="+Lang+"&ID="+ID+"&PHPSESSID="+PHPSESSID;
		if(idimage>0) loc = loc + "&idimage=" + idimage;
		wins[cpop] = window.open(loc,wname,"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,width=" + w +",height=" + h + ",left=100,top=100");
		wins[cpop].focus();
		cpop++;
    	if(idimage>0) {
            selfClose();
        }
	}
}

function selfClose()
{
    self.close();
}

function GalleryAMBIENTS(Lang, ID, PHPSESSID){
	arr_Piece = document.images['imm_2'].src.split('/');
	Piece = arr_Piece[arr_Piece.length-1];
	if(Piece == 'notavail_2.jpg'){
		alert(_LANG['Image_notavail']);
	}else{
		loc = SiteUrl + "ambients.php?Lang="+Lang+"&PID="+ID+"&PHPSESSID="+PHPSESSID;
		window.open(loc,_LANG.Ambients,"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,width=1024,height=768,left=0,top=0");
	}
}

function GalleryFLOOR(Lang, ID, PHPSESSID,w,h,idimage){
	arr_Piece = document.images['imm_2'].src.split('/');
	Piece = arr_Piece[arr_Piece.length-1];
	if(Piece == 'notavail_2.jpg'){
		alert(_LANG['Image_notavail']);
	}else{
		wname = ID+"_"+idimage+"_floor";
		wname = wname.replace('-','_');
		loc = SiteUrl + "gallery2.php?Lang="+Lang+"&ID="+ID+"&PHPSESSID="+PHPSESSID;
		if(idimage>0) loc = loc + "&idimage=" + idimage;
		wins[cpop] = window.open(loc,wname,"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,width=" + w +",height=" + h + ",left=100,top=100");
		wins[cpop].focus();
		cpop++;
		if(idimage>=0) window.close();
	}
}

function POP(loc,title,w,h,resizable){
	window.open(loc,title,"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable="+resizable+",status=0,width="+w+",height="+h+",left=100,top=100");
}
function ResendPassword(){
	user = prompt("Username","");
	if(user!=null){
		if(user.length>0){
			window.location=SiteUrl + "index.php?Mode=send&Command=pwd&user="+user;
		}else{
			ResendPassword('');
		}
	}
}
function CheckNewAd(){
	f = document.forms["ads"];
	if(f.Title.value=="")
		alert(_LANG.Ads + ": " + _LANG.FillTheFields + " " + _LANG.Title);
	else {
		if(f.Text.value=="")
			alert(_LANG.Ads + ": " + _LANG.FillTheFields + " " + _LANG.Text_lbl);
		else
			f.submit();
	}
}
function CheckMlist(Myform){
	if (Myform.name.value==""){
		alert( _LANG.Empty_name );
		Myform.name.focus();
		return false;
	}
	if (!isEmail(Myform.email.value, false)){
		alert( _LANG.Invalid_email );
		Myform.email.focus();
		return false;
	}
	if(!Myform.ckPrivacy.checked){
		alert(_LANG.AlertCheckPrivacy);
		Myform.ckPrivacy.focus();
		return false;
	}
	return true;
}

function CheckSearchForm(f){
	if(isEmpty(f.srcCode.value)){
		alert(_LANG.Empty_Search);
		f.srcCode.focus();
		return false;
	}
	return true;
}

function AddToWishList()
{
	window.location = SiteUrl + 'index.php?Mode=wishlist&Command=add&PID=' + document.forms['product'].PID.value;
}

function toggleCompareList(PIDtoChange2,mycheckbox)
{
	Action2= mycheckbox.checked?'add':'del';
	new Ajax.Request(SiteUrl + 'index.php?Mode=shop&Command=toggleCompareList&PIDtoChange='+PIDtoChange2+'&Action='+Action2,
	   {     
	   		method:'get',
			//parameters: {Mode: 'shop', Command: 'toggleCompereList', PIDtoChange: PIDtoChange2, Action: status?'add':'del'},
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				eval(response);
		},     
		onFailure: function(){alert('Something went wrong...')}
	}); 
	
}
function DelFromCompareList(PIDtoRemove)
{
	window.location = SiteUrl + 'index.php?Mode=compare&Command=list&PIDtoDel=' + PIDtoRemove;
}
function toggleTryathomeList(PIDtoChange2,mycheckbox)
{
	Action2= mycheckbox.checked?'add':'del';
	new Ajax.Request(SiteUrl + 'index.php?Mode=shop&Command=toggleTryathomeList&PIDtoChange='+PIDtoChange2+'&Action='+Action2,
	   {     
	   		method:'get',
			//parameters: {Mode: 'shop', Command: 'toggleCompereList', PIDtoChange: PIDtoChange2, Action: status?'add':'del'},
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				eval(response);
		},     
		onFailure: function(){alert('Something went wrong...')}
	}); 
	
}
function DelFromTryathomeList(PIDtoRemove)
{
	window.location = SiteUrl + 'index.php?Mode=tryathome&Command=list&PIDtoDel=' + PIDtoRemove;
}

function changeAmbient(what, id)
{
    if(what == 'ambient'){
        idc = 'a' + id;
        cont = 'amb';
    }
    if(what == 'furniture'){
        idc = 'f' + id;
        cont = 'furn';
    }
    if(what == 'furniture_accessory'){
        idc = 'fa' + id;
        cont = 'furn_acc';
    }

    cleanAmbient(cont);
    document.getElementById(idc).className = 'avSelected';

    frm = document.forms['ambients'];
    var ambient_viwer = document.getElementById('ambient_viwer');
    url = SiteUrl + 'ambients.php?PID=' + frm.PID.value + "&show=1&" + what + "=" + id;
    ambient_viwer.innerHTML = '<img src="' + url + '" />';
}

function cleanAmbient(cont)
{

    var eAmbient = document.getElementById(cont);
    for(i in eAmbient.childNodes){
        if(typeof(eAmbient.childNodes[i].id) != 'undefined'){
            eAmbient.childNodes[i].className = 'avUselected';
        }
    }
}




