/**
 * general.js
 *
 * Copyright (c) 2000-2008 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * Site-wide common JavaScript functions. 
 *
 * $Id: general.js,v 1.7 2008/04/04 17:06:48 asmecher Exp $
 */

/**
 * Prompt user for confirmation prior to loading a URL.
 */
function confirmAction(url, msg) {
	if (confirm(msg)) {
		if (url) {
			document.location.href=url;
		}
		return true;
	}
	return false;
}

/**
 * Open window displaying help.
 */
function openHelp(url) {
	window.open(url, 'Help', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,scrollbars=1');
}

/**
 * Open window displaying comments.
 */
function openComments(url) {
	window.open(url, 'Comments', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for preview.
 */
function openWindow(url) {
	window.open(url, 'Window', 'width=600,height=550,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for reading tools.
 */
function openRTWindow(url) {
	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}
function openRTWindowWithToolbar(url) {
	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=1,resizable=1,scrollbars=1');
}

/**
 * browser object availability detection
 * @param objectId string of object needed
 * @param style int (0 or 1) if style object is needed
 * @return javascript object specific to current browser
 */
function getBrowserObject(objectId, style) {
	var isNE4 = 0;
	var currObject;

	// browser object for ie5+ and ns6+
	if (document.getElementById) {
		currObject = document.getElementById(objectId);
	// browser object for ie4+
	} else if (document.all) {
		currObject = document.all[objectId];
	// browser object for ne4
	} else if (document.layers) {
		currObject = document.layers[objectId];
		isNE4 = 1;
	} else {
		// do nothing
	}
	
	// check if style is needed
	if (style && !isNE4) {
		currObject = currObject.style;
	}
	
	return currObject;
}

/**
 * Load a URL.
 */
function loadUrl(url) {
	document.location.href=url;	
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
 * Asynchronous request functions
 */
function makeAsyncRequest(){
	var req=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
	return req;
}

function sendAsyncRequest(req, url, data, method) {
	var header = 'Content-Type:text/html; Charset=utf-8';
	req.open(method, url, true);
	req.setRequestHeader(header.split(':')[0],header.split(':')[1]);
	req.send(data);
}

/**
 * Change the form action
 * @param formName string
 * @param action string 
 */
function changeFormAction(formName, action) {
	document.forms[formName].action = action;
	document.forms[formName].submit();
}

/**
*Take values of special events in registration and put in special request area
**/
function writeRegistrationEvent(regform,rad,str){
	
	if(rad == 'ev1'){
		
		if(regform.ev1[0].checked){

			var request = regform.ev1[0].value;
		}
		else{
			var request = regform.ev1[1].value;

		}
	}else{
                if(regform.ev2[0].checked){

                        var request = regform.ev2[0].value;
                }
                else{
                        var request = regform.ev2[1].value;

                }

	}

	regform.specialRequests.value+= (str +', ' +request+'\n');
}
/**
*
**/
function controlDayPartecipants(regform,rad,str){
	if(!(regform.giorno1.checked) && !(regform.giorno3.checked) && !(regform.giorno3.checked))  {
		alert("devi inserire i giorni di partecipazione");
	}else{
		writeRegistrationEvent(regform,rad,str);
	}
}


/**
*
*/

function writeDayPartecipants(regform,day,str){
var pippo = regform.specialRequests.value;
	if(pippo.indexOf(str)!=-1){
	     	regform.specialRequests.value =pippo.replace(str,'');}
	else{
		regform.specialRequests.value += (str+'\n');
	}
		
/*	}else{
		if(regform.specialRequests.value.indexOf(str)!=-1){
			regform.specialRequests.value.replace(str,'');
		}
	}
}else if(day == 'giorno2'){
	if(regform.giorno2.checked){
                regform.specialRequests.value += (str+'\n');
        }else{
                if(regform.specialRequests.value.indexOf(str)!=-1){
                        regform.specialRequests.value.replace(str,'');
                }
        }

}else{
        if(regform.giorno3.checked){
                regform.specialRequests.value += (str+'\n');
        }else{
                if(regform.specialRequests.value.indexOf(str)!=-1){
                        regform.specialRequests.value.replace(str,'');
                }
        }
}*/

}

function musicaOn(){
var browser=navigator.appName;
	if(browser.match("Explorer"))
	{
		//document.write("<bgsound id=\"sottofondo\" src=\"http://bib03.caspur.it/ocs/files/conferences/1/images/K285.mp3\">");
		//bgsound.src="http://bib03.caspur.it/ocs/index.php/ciber/index/manager/files/images/K285.mp3";
		var so =document.createElement('embed');
		//so[0].src="http://bib03.caspur.it/ocs/index.php/ciber/index/manager/files/images/K285.mp3";
		so.setAttribute('src', 'http://bib03.caspur.it/ocs/index.php/ciber/index/manager/files/images/K285.mp3');
		so.setAttribute('id','sottemb');
		so.setAttribute('autostart','true');
		so.setAttribute('hidden','true');
		so.setAttribute('enablejavascript','true');
		document.body.appendChild(so);
	}else{
		var emb=  document.getElementById('sottemb');

		emb.src="http://bib03.caspur.it/ocs/files/conferences/1/images/K285.mp3";
	}
}

function musicaOff(){
var browser=navigator.appName;
        if(browser.match("Explorer"))
        {
		var so=  document.getElementById('sottemb');
		so.parentNode.removeChild(so);
		//so.removeAttribute('src');
		
		//document.embeds['sottemb'].src="";
		

        }else{
		var emb=  document.getElementById('sottemb');
		emb.src="";
	}
}




function slideit(){
       img = Array(); 
       img[0]= "http://bib03.caspur.it/ocs/files/conferences/1/schedConfs/3/images/rome1.jpg";
       img[1]= "http://bib03.caspur.it/ocs/files/conferences/1/schedConfs/3/images/rome2.jpg";
       img[2]= "http://bib03.caspur.it/ocs/files/conferences/1/schedConfs/3/images/rome3.jpg";
       img[3]= "http://bib03.caspur.it/ocs/files/conferences/1/schedConfs/3/images/rome4.jpg";
	var foto = document.getElementById("slide").src;
	var step = foto.charAt( foto.length-5 );
		//if(foto.charAt(40)){
	document.getElementById("slide").src=img[eval(step%4)];
	document.getElementById("slide1").src=img[eval((step+1)%4)];
	document.getElementById("slide2").src=img[eval((step+2)%4)];
	document.getElementById("slide3").src=img[eval((step+3)%4)];
	
	var t = setTimeout("slideit()",5000);
			
		//}
		
		/*document.getElementById("slide2").style.display="none";
		document.getElementById("slide3").style.display="none";
		document.getElementById("slide4").style.display="none";
		*/

		//document.getElementById("slide"+step).style.display="block";            
		    
	//}
}

/**
 * Drag and drop functions
**/

