/*
---------------------------------------------------------------------------------
AJAX - Funzione generale 
---------------------------------------------------------------------------------
fun -> funzione da eseguire al ritorno dalla pagina asp
url -> pagina asp da eseguire completa di parametri
*/
function getAjaxObj(fun,url) {
	http_request = false;
	if (window.XMLHttpRequest) {
		// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
			http_request.overrideMimeType('text/xml');
	} else if (window.ActiveXObject) {
		// IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) 
			{}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = eval(fun);
	http_request.open('GET',url, true);
	http_request.send(null);
}
/*
---------------------------------------------------------------------------------
FINE AJAX 
---------------------------------------------------------------------------------
*/

/*
---------------------------------------------------------------------------------
UTILITA'
---------------------------------------------------------------------------------
*/

function trim(stringa) {    
  while (stringa.substring(0,1) == ' ') {        
      stringa = stringa.substring(1, stringa.length);    
  }
  while (stringa.substring(stringa.length-1, stringa.length) == ' ') {        
      stringa = stringa.substring(0,stringa.length-1);    
  }    
  return stringa;  
 }


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/*
---------------------------------------------------------------------------------
FINE UTILITA'
---------------------------------------------------------------------------------
*/

var global_id_user="";
function refreshLightBoxPrice(iduser,lang) {
	global_id_user=iduser;
	var _rand=Math.random()*123456;
	getAjaxObj('refreshLightBox','ajax.cfm?act=reflight&idu='+iduser+'&lang='+lang+'&ran='+_rand);	
}

function refreshLightBox() {
	if (http_request.readyState == 4){
    	if (http_request.status == 200) {
	    	if (http_request.responseText.length>0) {        				
    	    	 document.getElementById('lightbox_'+global_id_user).innerHTML=http_request.responseText;
    	  	}
	    }
  	}		
}

//funzione per il login fotografi
function valida(){		
	vUser 	= document.LoginForm.UserLogin.value;
	vPwd	= document.LoginForm.UserPassword.value;
	getAjaxObj('LoginFotografi', 'ajax.cfm?act=loginFoto&campoUser=' + vUser + '&campoPwd=' + vPwd);
}
function LoginFotografi(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (http_request.responseText.length>0) {
				vTestoRest = trim(http_request.responseText);
				
				if (vTestoRest == "No") {
					document.getElementById("errore").innerHTML = "Hai inserito valori non corretti!";
				} else if (vTestoRest == "50") {
					document.location = "http://www.porphirius.it/author_account.cfm?TYPE=ACCOUNT";
				} else {
					document.location = "http://www.porphirius.it/index.cfm?LANG=IT&SEZ_ID=6"
				}
			}
		}
	}
}

//funzione per il cambio dei campi obbligatorio nel form dei fotografi
function cambiaCampi(){
	vSoggetto 	= document.Update.SG_ID.value;
	document.location = "http://www.porphirius.it/author_account.cfm?TYPE=PROFILE&soggetto=" + vSoggetto;
}