/**
 * @author itmldata
 */
/**
 * this function show claim on "claimBox" layer only if layer exist
 * @param {String} claim
 */
function showClaim(claim){
	if(document.getElementById("claimBox"))document.getElementById("claimBox").innerHTML = claim;
	else(hideClaim());
}
/**
 * this function hide claim on "claimBox" layer only if layer exist
 */
function hideClaim(){
	if(document.getElementById("claimBox"))document.getElementById("claimBox").innerHTML = "";
}
function fillComboYears(){	
  	var combo_years=document.getElementById("combo_years");
	if(combo_years){
		var startI = new Date();
		startI = (startI.getFullYear())
		for(var i=startI;i>=1980;i--){
			var year = document.createElement('option');
			year.text=i;
 			year.value=i;
			try{
				combo_years.add(year,null); // standards compliant
			}catch(ex){
				combo_years.add(year); // IE only
			}
		}
	}
}
function fillComboMonths(){	
  	var combo_months=document.getElementById("combo_months");
	if(combo_months){
		for(var i=0;i<months_names.length;i++){
			var month = document.createElement('option');
			month.text=months_names[i];
			month.value=i+1;
			try{
				combo_months.add(month,null); // standards compliant
			}catch(ex){
				combo_months.add(month); // IE only
			}
		}
	}
}
/*
 
var originalOnLoad = window.onload
window.onload=function(){
	fillComboYears();
	fillComboMonths()
	if(originalOnLoad)originalOnLoad();
}
*/

	/**
 * Prodotti Ajax
 */
var numTotRows = 1;
var myRequest = null;
var isFire=(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1)?true:false;

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;  
	if (window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest()
	}else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			
	} 
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}

function myHandler() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
        document.getElementById("dettaglio").innerHTML=myRequest.responseText;
    }
}

function detailProduct(obj,pag,nRow,nCol,nRowScheda) {

    myRequest = CreateXmlHttpReq(myHandler);
    
    myRequest.open("GET",pag);
    myRequest.send(null);
 if(nRow){
    	posDiv(obj,nRow,nCol,nRowScheda)
    }
   
}


	/**
 * fine Prodotti Ajax
 */



function closeDetail(){
	document.getElementById("dettaglio").innerHTML="";
}
//---------------------------------------------------------------------------------
function posDiv(obj,nRow,nCol,nRowScheda){
 	var asse_x = getX(obj);
	var asse_y = getY(obj);
	var pixHeightDet = 359;
	if(isFire){
		pixHeightDet = 353;
	}

	if(nRow == 4){
		asse_x = asse_x - obj.offsetWidth;
	}
	//alert(document.getElementById("dettaglio").offsetHeight)
	if (nRowScheda == "tre"){		
		if ((numTotRows-nCol)<1){
			asse_y = asse_y - (obj.offsetHeight*2);
		}else if((numTotRows-nCol)<2){
			asse_y = asse_y - (obj.offsetHeight);
		}
	}else{
		if ((numTotRows-nCol)<1){
			asse_y = asse_y - obj.offsetHeight;
		}	
	}
	
	document.getElementById("dettaglio").style.left = (asse_x + 2)+ "px";
  document.getElementById("dettaglio").style.top = asse_y + "px";
}

function getY(oElement){
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX(oElement){
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
//---------------------------------------------------------------------------------


var sChangeClass;
function changeClass(obj){
 if(!obj && sChangeClass){
	sChangeClass.className= "";
 }else{
	if(sChangeClass){
		sChangeClass.className= "";
	}
	obj.className = "selected";
	sChangeClass = obj;
 }
}


function changeImgCal(value){
		document.getElementById("imgCal").src= value;
}

function changeInfo(value,idDiv){
		document.getElementById("imgFoto").src= value;
		document.getElementById("divdesc").innerHTML= document.getElementById(idDiv).innerHTML;
}

function changeTD(idTd){
	var ctrlInp = true;
	
	for(i=0;i<3;i++){
		if (document.getElementById('inp_'+ i + "_" + idTd).value == ""){
			ctrlInp = false;
		}
	}
	if (ctrlInp){
		document.getElementById(idTd).className="cellSel";
		document.getElementById("th"+idTd).className="cellSel";
		document.getElementById("ctrl_"+idTd).value="true";
	}else{
		document.getElementById(idTd).className="";
		document.getElementById("th"+idTd).className="";
		document.getElementById("ctrl_"+idTd).value="false";
	}
}

function swapF(obj){
	var to,setF=false;
	if(obj.type=="password"){
		to=obj.form.holder;
	}
	else {
		to=obj.form.password;
		setF=true;
	}
	if(setF || obj.value==""){
		to.style.display="block";
		obj.style.display="none";
	}
	if(setF) to.focus();
}

function changeInputUser(obj){
	if(obj.value==''){
		obj.value= "Username";
	}else if (obj.value=="Username"){
		obj.value= "";
	}
}

var stringMsg

function viewMessage(idDiv){
	var isIE=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)?true:false;
	document.body.style.overflow="hidden";
	stringMsg = document.getElementById(idDiv).innerHTML;
	document.getElementById("divBoxMessage").innerHTML = stringMsg;
	document.getElementById(idDiv).innerHTML = "";
	document.getElementById("divTrasp").style.filter="alpha(opacity=70)";
	document.getElementById("divTrasp").style.display="block";
	document.getElementById("divContBoxMessage").style.display="block";		
	if(isIE){
		document.getElementById("divTrasp").style.height=parseInt(document.body.offsetHeight) + "px";
		document.getElementById("divTrasp").style.width=parseInt(document.body.offsetWidth) + "px";
		document.getElementById("divContBoxMessage").style.width=parseInt(document.body.offsetWidth) + "px";
	}
}

var stringMsgPopUp
function openPopUp(idDiv){
	var isIE=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)?true:false;
	document.body.style.overflow="hidden";
	stringMsgPopUp = document.getElementById(idDiv).innerHTML;
	document.getElementById("divBoxMessage").innerHTML = stringMsgPopUp;
        document.getElementById("divBoxMessage").style.width="450px";
	document.getElementById("divBoxMessage").style.height="300px";
	document.getElementById(idDiv).innerHTML = "";
	document.getElementById("divTrasp").style.filter="alpha(opacity=70)";
	document.getElementById("divTrasp").style.display="block";
	document.getElementById("divContBoxMessage").style.display="block";
		
	if(isIE){
		document.getElementById("divTrasp").style.height=parseInt(document.body.offsetHeight) + "px";
		document.getElementById("divTrasp").style.width=parseInt(document.body.offsetWidth) + "px";
		document.getElementById("divContBoxMessage").style.width=parseInt(document.body.offsetWidth) + "px";
	}
}

function closePopUp(idDiv){
	document.body.style.overflow="auto";
	document.getElementById("divTrasp").style.display="none";
	document.getElementById("divContBoxMessage").style.display="none";
	document.getElementById(idDiv).innerHTML = stringMsgPopUp;
	stringMsgPopUp = "";

}
	
function prepareJTarget(link) {
	var isIE=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)?true:false;
         
        stringI = '<input type="hidden" name="j_target" value="' +link + '"/>'; 
	document.getElementById('divinputhidden').innerHTML=stringI;
         
}

function closeMessage(idDiv){
	document.body.style.overflow="auto";
	document.getElementById("divTrasp").style.display="none";
	document.getElementById("divContBoxMessage").style.display="none";
	document.getElementById(idDiv).innerHTML = stringMsg;
	stringMsg = "";

}

function viewRmbPwd(view){
	if(view){
	document.getElementById("rmbPw").style.display="block";
	document.getElementById("insPwd").style.display="none";
	}else{
	document.getElementById("rmbPw").style.display="none";
	document.getElementById("insPwd").style.display="block";
	}
}

function createBookmarkLink() {

	title = document.title;
	url = location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,'');
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}

/*
 if (window.external) {
  document.write('<a href = "javascript:createBookmarkLink()");">' + label + '</a>'); 
  } else  if (window.sidebar) {
  document.write('<a href = "javascript:createBookmarkLink()");">' + label + '</a>'); 
 } else if (window.opera && window.print) {	
   document.write('<a href = "javascript:CreateBookmarkLink()");">' + label + '</a>');
 } */

 }

function WrongEmail(mail) {
	if (mail.indexOf("@") < 0) return true;
	if (mail.indexOf(".") < 0) return true;
	return false;
}

