/* //TEST CON JSONP\\ */
var risp = '';

function getDoc(params) { 

	var head = document.getElementsByTagName('head')[0]; 
	
	if (!document.all) { // Mozilla, Safari,...
		var script = document.createElement("SCRIPT");
		script.setAttribute("type","text/javascript");
		if (params.length > 0){
			script.setAttribute("src","http://docmaster.elsevier.it/dm_admin/ajax/getDoc.asp?t=" + (new Date().getTime()) +"&"+ params);
		} else {
			script.setAttribute("src","http://docmaster.elsevier.it/dm_admin/ajax/getDoc.asp?t=" + (new Date().getTime()));
		}
		
	} else if (document.all) { // IE
		var strElm = '';
		if (params.length > 0){
			strElm = '<SCRIPT id="quiz_script" type="text/javascript" src="http://docmaster.elsevier.it/dm_admin/ajax/getDoc.asp?t=' + (new Date().getTime()) +'&'+ params +'" ></SCRIPT>';
		} else {
			strElm = '<SCRIPT id="quiz_script" type="text/javascript" src="http://docmaster.elsevier.it/dm_admin/ajax/getDoc.asp?t=' + (new Date().getTime()) +'" ></SCRIPT>';
		}
		var script = document.createElement(strElm);		
	}
	
	//alert(document.getElementById('QuizMaster').offsetWidth);

/*	
	for (var i = 0; i< head.childNodes.length; i++){
		if (head.childNodes[i].id == 'quiz_script'){
			alert(head.childNodes[i].id);
	//		head.removeChild(head.childNodes[i]);
		}
	}
*/

	head.appendChild(script);
} 
/* \\TEST CON JSONP// */


function URLEncode(CODE){

	var plaintext = CODE;
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					
	var HEX = "0123456789ABCDEF";
	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	// VALORE CODIFICATO
	return encoded;
};



function popDMImage(imageURL,imageTitle){
//really not important (the first two should be small for Opera's sake)
PositionX = 200;
PositionY = 200;
defaultWidth  = 200;
defaultHeight = 100;

//kinda important
var AutoClose = true;

	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() { \n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n  '+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight;}\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		//'var scW = 500;\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		//'if( !window.opera) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }alert(scW );\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/200)+30,Math.round((scH-oH)/200)+40); };\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' ':'')+' bgcolor="black">'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		//'<img src="/cont/resizeimg.aspx?i='+imageURL+'&e=jpg&w=190" alt="Loading image ..." title="" onload="resizeWinTo();">'+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}

function popDMDown(url,w,h,s,f){
	LeftPosition =(screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	window.open(url,'new','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+s+',fullscreen='+f+',resizable=1')
}

/* //TEST CON OBJ-AJAX\\ */
DMPin = {
	DM_pin_cripted : 'dmp='
	, DM_pin_url : '/cm/ajax/DMsendPinCripted.asp'
	, DM_http_request : false
	, Send : function(DM_pin){
		this.Clean();
		this.DM_pin_cripted += DM_pin;		
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			this.DM_http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			try {
				this.DM_http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.DM_http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					this.Clean();
				}
			}
		}
		if (!this.DM_http_request) {
			window.parent.status('Impossibile creare una istanza XMLHTTP');
			this.Clean();
		} else {
			window.parent.status="Elaborazione...";
			this.DM_http_request.open('POST', this.DM_pin_url, true);
			this.DM_http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.DM_http_request.setRequestHeader("Content-length", this.DM_pin_cripted.length);
			this.DM_http_request.onreadystatechange = this.MngRequest;
			this.DM_http_request.send(this.DM_pin_cripted);
		}		
	}
	, MngRequest : function(){
		if (DMPin.DM_http_request.readyState == 4) {
			if (DMPin.DM_http_request.status == 200) {
				if (DMPin.DM_http_request.responseText!='') {
					getDoc(DMPin.DM_http_request.responseText);
				} else {
					alert('Impossibile procedere col download!')
				}				
				window.status='Eseguito...';
			} else {
				window.parent.status="Problemi con la richiesta al server"
			}
			DMPin.Clean();
		}	
	}
	, Clean : function(){
		DMPin.DM_pin_cripted = 'dmp=';
		DMPin.DM_pin_url = '/cm/ajax/DMsendPinCripted.asp'
		DMPin.DM_http_request = false;
	}
}
/* \\TEST CON OBJ-AJAX// */
