
function getObj(id)
{
	if (document.all) { return document.all[id]; } 
	else {	return document.getElementById(id);	}
}

function getOffsetPosition(oObj, inTYPE)
{
	var iVal = 0;
	var sType = 'oObj.offset' + inTYPE;
	while (oObj && oObj.tagName != 'BODY')
	{
		iVal += eval(sType);
		oObj = oObj.offsetParent;
	}
	return iVal;
}

function form_onsubmit(form)
{
	var buttons = form.getElementsByTagName("button"); 
	var lenght = buttons.length;
	
	for (var i = 0; i < lenght; i++)
	{
		if (buttons[i].className != 'button1')
		{
			buttons[i].innerHTML = postValueOnSubmit;
		}
		
    	buttons[i].disabled = 'disabled';
	}
}


function uploadProgress(sentence)
{
	var box = document.createElement('div');
	if (typeof(box.innerHTML) != 'string') { return; }
	
	var boxWidth = 200;
	var boxPadding = 20;
	
	var progress_img = 'icon/loading.gif';
	
	box.id = 'uploadProgressBox';
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.width = boxWidth + 'px';
	box.style.textAlign = 'center';
	box.style.backgroundColor = '#eeeeee';
	box.style.border = '1px #666666 solid';
	box.style.padding = boxPadding + 'px';
	box.innerHTML = '<img src="'+progress_img+'" id="progressAnimatedImage" width="16" height="16" alt="'+sentence+'" style="vertical-align:middle; margin-right:10px;" />';
	box.innerHTML += sentence;
	box.style.top = ((document.documentElement.clientHeight/2) - ((40+(boxPadding*2))/2)) + 'px';
	box.style.left = ((document.documentElement.clientWidth/2) - ((boxWidth+(boxPadding*2))/2)) + 'px';

	/*var xhr = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	
	xhr.open("GET", "404", true);
	
	xhr.send(null);*/
	
	document.body.appendChild(box);
	
	setTimeout('getObj("progressAnimatedImage").src="'+progress_img+'"', 200); 
}


function progressLoadImage(divId)
{
	var div = getObj(divId); 
    var tab = div.getElementsByTagName("img"); 
	var img = tab[0];
	
	if (img.complete)
	{
		img.style.display = 'block';
		div.style.background = 'none';
	}
	else
	{
		div.style.width = img.width+'px';
		div.style.height = img.height+'px';
		div.style.background = 'url(css/loading.gif) center no-repeat';
		img.style.display = 'none'; 
		
		window.setTimeout('progressLoadImage("'+divId+'");', 50);
	}
}


var PUI_CurrentNum = 0;

function pushUploadInput(pushId, maxInputsNb, alreadyDspRowsNb, textError)
{	
	if (PUI_CurrentNum < maxInputsNb)
	{		
		if (PUI_CurrentNum == 0)
		{
			getObj(pushId).innerHTML += '<div class="row"><span class="label">&nbsp;</span><div class="content" id="'+pushId+'2"></div></div>';
		}
		
		var pushElement = getObj(pushId+'2');
		
		var cName = (parseInt(alreadyDspRowsNb)+parseInt(PUI_CurrentNum)+1);
		
		/*getObj(pushId).innerHTML += '<div class="row">'+
		                              '<label class="label" for="ipt_file'+cName+'">n°'+cName+'</label>'+
		                              '<input type="file" name="image[]" id="ipt_file'+cName+'" />'+
		                            '</div>';*/
		if (PUI_CurrentNum != 0)
		{
			var br = document.createElement("br") ;
			pushElement.appendChild(br);
		}
		
		var up=document.createElement("input") ;
		up.setAttribute("type","file") ;
		up.setAttribute("id","ipt_file"+cName) ;
		up.setAttribute("name","image[]") ;
		pushElement.appendChild(up);

		PUI_CurrentNum++;
	}
	else
	{
		alert(textError);
	}
}

function chooseImageEffect(nSelect, nbEffects)
{
	for(i = 1; i <= nbEffects; i++)
	{
		var cDivName = 'divImageEffect'+i;
		
		if (i == nSelect)
		{
			getObj(cDivName).className = 'divImageEffect divImageEffectSelect';
			getObj('inputEffect'+nSelect).checked = true;
		}
		else
		{
			getObj(cDivName).className = 'divImageEffect';
		}
	}
}

function chooseTextEffect(nSelect, nbEffects)
{
	for(i = 1; i <= nbEffects; i++)
	{
		var cDivName = 'divTextEffect'+i;
		
		if (i == nSelect)
		{
			document.getElementById(cDivName).className='divTextEffect divTextEffectSelect';
			document.getElementById('inputEffect'+nSelect).checked=true;
		}
		else
		{
			document.getElementById(cDivName).className='divTextEffect';
		}
	}
}

function yourPubLabelBlink(divName, classNameColor)
{
	var div = getObj(divName);
	
	if (div.className == classNameColor)
	{
		div.className = '';
	}
	else
	{
		div.className = classNameColor;
	}

	setTimeout("yourPubLabelBlink('"+divName+"', '"+classNameColor+"')", 1000);
}

function is_numeric(num)
{
	var exp = new RegExp('^[0-9-.]+$','g');
	return exp.test(num);
}
	
function CDownloadUrl(method, url, func) {
   var httpObj;
   var browser = navigator.appName;
   if(browser.indexOf("Microsoft") > -1)
      httpObj = new ActiveXObject("Microsoft.XMLHTTP");
   else
      httpObj = new XMLHttpRequest();
 
   httpObj.open(method, url, true);
   httpObj.onreadystatechange = function() {
      if(httpObj.readyState == 4){
         if (httpObj.status == 200) {
            var contenttype = httpObj.getResponseHeader('Content-Type');
            if (contenttype.indexOf('xml')>-1) {
               func(httpObj.responseXML);
            } else {
               func(httpObj.responseText);
            }
         } else {
            func('Error: '+httpObj.status);
         }
      }
   };
   httpObj.send(null);
}

/*
function progressLoadImage()
{	
	var divId = 'resultGif';
	var imgId = 'resultGifImg';
	
	var div = getObj(divId);
	var img = getObj(imgId);

	if (img.complete)
	{
		div.style.background = 'url(' + img.src + ') top left no-repeat';
	}
	else
	{
		if (div.innerHTML == '')
		{
			div.style.background = 'url(css/loading.gif) center no-repeat';
		}
		
		window.setTimeout( "progressLoadImage()", '50' );
	}
}
*/

/*
function progressForImage(parentDivId)
{
    var img = document.getElementsByTagName("img"); 
	var lenght = img.length;
	var again = false;
	
    for(i = 0; i < lenght; i++)
	{
		var parentDiv = img[i].parentNode;
		
		if (parentDiv.className != 'animGif') continue;
		
		parentDiv.style.display = 'block';
		parentDiv.style.width = img[i].width+'px';
		parentDiv.style.height = img[i].height+'px';
		
		if (img[i].complete)
		{
			img[i].style.display="block"; 
			parentDiv.style.background = 'none';
		}
		else
		{
			parentDiv.style.background = 'url(css/loading.gif) center no-repeat';
			
			img[i].style.display="none"; 
			again = true;
		}
    }
	
	if (again)
	{
		window.setTimeout( "progressForImages()", '100' );
	}
}
*/
