// JavaScript Document

function InStr(String1, String2)
{
    var a = 0;
    
    if (String1 == null || String2 == null)
        return (false);
    
    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();
    
    a = String1.indexOf(String2);
    if (a == -1)
        return 0;
    else
        return a + 1;
}

function dimenwin() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + myWidth );
  return myHeight-200;
}

function confcanc(url,testo) {
	if (confirm('Confermi l\'Eliminazione?'))
	{
	document.location.href=url;
	};
	return void(0);
}
function rimuovi(idcampo) {
	$('#'+idcampo).val('');
}

function carica(pulsante,campoval,parametri) {
	// parametri = es. &nome=Stefano&cognome=tolomelli
	if(!parametri) {
		var parametri = '';
	}
	var campo = $(campoval), interval;
	var myUpload = $(pulsante).upload({
	        name: 'filen',
			action: 'upload2.asp?folder=/cv' + parametri,
			onSubmit: function() {
					campo.val('Caricamento');
					interval = window.setInterval(function(){
						var text = campo.val();
						if (text.length < 20){
							campo.val(text + '.');					
						} else {
							campo.val('Caricamento');				
						}
					}, 200);
			},
			onComplete: function(risposta){
				window.clearInterval(interval);
				$(campoval).val(risposta);
			}
	});
}

function BloccaJS(id,flag) {
	$("#" + id).find("input").each(function() {
		if (flag==0) {
			return void(0);
		} else if ($(this).val()=='' && flag==1) {
			return void(0);
		} else if ($(this).val()!='' && flag==1) {
			$(this).attr("readonly", true).addClass('bloccato');
			if ($(this).attr('type')=='radio') $(this).attr("disabled", true);
			if ($(this).attr('type')=='checkbox') $(this).attr("disabled", true);
		}
	});
	$("#" + id).find("select").each(function() {
		if (flag==0) {
			return void(0);
		} else if ($(this).val()=='' && flag==1) {
			return void(0);
		} else if ($(this).val()!='' && flag==1) {
			$(this).attr("disabled", true);
		}
	});
	$("#" + id).find("textarea").each(function() {
		if (flag==0) {
			return void(0);
		} else if ($(this).val()=='' && flag==1) {
			return void(0);
		} else if ($(this).val()!='' && flag==1) {
			$(this).attr("readonly", true).addClass('bloccato');
		}
	});
}

function BloccaJSTUTTO(id,flag) {
	$('#' + id + ' input:checkbox').attr("disabled", true);
	$('#' + id + ' input:radio').attr("disabled", true);
	$("#" + id).find("input").each(function() {
		if (flag==0) {
			return void(0);
		} else {
			$(this).attr("readonly", true).addClass('bloccato');
		}
	});
	$("#" + id).find("select").each(function() {
		if (flag==0) {
			return void(0);
		} else {
			$(this).attr("disabled", true);
		}
	});
	$("#" + id).find("textarea").each(function() {
		if (flag==0) {
			return void(0);
		} else {
			$(this).attr("readonly", true).addClass('bloccato');
		}
	});
}

function SbloccaJS(id) {
	$('#' + id).find("select").each(function() {
			$(this).removeAttr('disabled');
	});
	$('#' + id + ' input:checkbox').removeAttr('disabled');
	$('#' + id + ' input:radio').removeAttr('disabled');
	$('#' + id).find("input").each(function() {
			$(this).removeAttr('disabled');
	});
}

function conferma(url,testo) {
	if (confirm(testo))
	{
	document.location.href=url;
	};
	return void(0);
}

