function changeIndicative(val) {
	document.getElementById('phoneIndicative').value = val; 
}

/* Function JS used for carousel in widgets homepage */
function carousel1(cycleTimeFeaturedWidgets,nbWidgets){
	var carousel1;
    
	document.getElementById('carousel1').style.visibility="hidden";
    
    YAHOO.util.Event.onDOMReady(function (ev) {
        var carousel1    = new YAHOO.widget.Carousel("containerFeaturedWidgets", {
        			isCircular: true,
        			numVisible: 1,
        			autoPlayInterval:cycleTimeFeaturedWidgets,
                    animation: { speed: 0.5 }
            });
                     
        carousel1.render(); // get ready for rendering the widget
        var container = document.getElementById("containerFeaturedWidgets");
        var paginationNode = container.children[0];
        paginationNode.style.width = 35 + nbWidgets * 20 + "px";
        var pagesNode = paginationNode.children[0];
        var firstButtonNode = paginationNode.children[1];
        paginationNode.insertBefore(firstButtonNode,pagesNode);
        
        var contentNode = container.children[1];
        container.insertBefore(contentNode,paginationNode);
        
        document.getElementById('carousel1').style.visibility="visible";
        
        carousel1.show();   // display the widget
        carousel1.startAutoPlay();
        document.getElementById('carousel1').style.height="202px;";
    });
}

function validateForm(locale,popupIdName) {
	var url = 'partner/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','BusinessAction');
	XHR.appendDataWithEscapeValue('action','sendMessage');
	XHR.appendDataWithEscapeValue('name',document.getElementById('name').value);
	XHR.appendDataWithEscapeValue('email',document.getElementById('email').value);
	XHR.appendDataWithEscapeValue('phoneIndicative',document.getElementById('phoneIndicative').value);
	XHR.appendDataWithEscapeValue('phoneNumber',document.getElementById('phoneNumber').value);
	XHR.appendDataWithEscapeValue('company',document.getElementById('company').value);
	XHR.appendDataWithEscapeValue('message',document.getElementById('message').value);
	
	if (document.getElementById('partnership').checked)
		XHR.appendDataWithEscapeValue('partnership',"1");
	
	if (document.getElementById('sponsoredWidgets').checked)
		XHR.appendDataWithEscapeValue('sponsoredWidgets',"1");
	
	if (document.getElementById('publishers').checked)
		XHR.appendDataWithEscapeValue('publishers',"1");
	
	if (document.getElementById('licensing').checked)
		XHR.appendDataWithEscapeValue('licensing',"1");
	
	if (document.getElementById('others').checked)
		XHR.appendDataWithEscapeValue('others',"1");
	
	XHR.sendAndLoad(url, "POST",displayPartnerContactAnswer);
}

function displayPartnerContactAnswer(conn) {
	var synchroStatusDiv=document.getElementById("partnerPopUp");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}

	displayPopUp("partnerPopUp");
}

function validateContactUsForm(locale,popupIdName) {
	var url = 'partner/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','BusinessAction');
	XHR.appendDataWithEscapeValue('action','contactUs');
	XHR.appendDataWithEscapeValue('name',document.getElementById('name').value);
	XHR.appendDataWithEscapeValue('email',document.getElementById('email').value);
	XHR.appendDataWithEscapeValue('phoneIndicative',document.getElementById('phoneIndicative').value);
	XHR.appendDataWithEscapeValue('phoneNumber',document.getElementById('phoneNumber').value);
	XHR.appendDataWithEscapeValue('company',document.getElementById('company').value);
	XHR.appendDataWithEscapeValue('message',document.getElementById('message').value);
	
	if (document.getElementById('bugs').checked)
		XHR.appendDataWithEscapeValue('bugs',"1");
	
	if (document.getElementById('suggestions').checked)
		XHR.appendDataWithEscapeValue('suggestions',"1");
	
	if (document.getElementById('information').checked)
		XHR.appendDataWithEscapeValue('information',"1");
	
	if (document.getElementById('programming').checked)
		XHR.appendDataWithEscapeValue('programming',"1");
	
	if (document.getElementById('others').checked)
		XHR.appendDataWithEscapeValue('others',"1");
	
	XHR.sendAndLoad(url, "POST",displayContactUsAnswer);
}

function displayContactUsAnswer(conn) {
	var synchroStatusDiv=document.getElementById("contactusPopUp");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}

	displayPopUp("contactusPopUp");
}

function carousel2(cycleTimeSponsoredWidgets,nbWidgets){
	var carousel2;
    
	document.getElementById('carousel2').style.visibility="hidden";
	
    YAHOO.util.Event.onDOMReady(function (ev) {
        var carousel2    = new YAHOO.widget.Carousel("containerSponsoredWidgets", {
        			isCircular: true,
        			numVisible: 1,
        			autoPlayInterval:cycleTimeSponsoredWidgets,
                    animation: { speed: 0.5 }
            });
          
        carousel2.render(); // get ready for rendering the widget
        var container = carousel2.get('navigation');  
        var container = document.getElementById("containerSponsoredWidgets");
        var paginationNode = container.children[0];
        paginationNode.style.width = 35 + nbWidgets * 20 + "px";
        var pagesNode = paginationNode.children[0];
        var firstButtonNode = paginationNode.children[1];
        paginationNode.insertBefore(firstButtonNode,pagesNode);
        
        var contentNode = container.children[1];
        container.insertBefore(contentNode,paginationNode);        
        
        document.getElementById('carousel2').style.visibility="visible";
        
        carousel2.show();   // display the widget
        carousel2.startAutoPlay();
        document.getElementById('carousel2').style.height="202px;";
    });
}

/* To know if a picture has been correctly loaded */
function isImgComplete(image){
	if(image != null){
		ok = false;
		if (image.complete) ok = true;
		if(ok = true){ 	
			return true;
		}else imgComplete(image);
	}else return false;
}

/* JS Method to scale image */
var imageMaxHeight = 150;
var imageMaxWidth = 110;

function scaleImage (image, showImage, maxHeight, maxWidth) {

	if (typeof showImage == "undefined") {
		showImage = true;
	  }
	if (typeof maxHeight != "undefined") {
		imageMaxHeight = maxHeight;
	}
	if (typeof maxWidth != "undefined") {
		imageMaxWidth = maxWidth;
	}
	  
	if(image != null){
		image.style.display="";
		if(image.width<=imageMaxWidth && image.height<=imageMaxWidth){
			if(showImage) image.style.visibility="visible";
			return;
		}
		else if (image.height > imageMaxHeight && image.width < imageMaxWidth) {
	 		image.height = imageMaxHeight;
	 	}
	 	else if(image.width < imageMaxWidth){
     		image.width = imageMaxWidth;
     		image.height = imageMaxWidth / image.width * image.height;
     		if(image.height>imageMaxHeight){
     			image.height=imageMaxHeight;
     			image.width = imageMaxHeight / image.height * image.width;
     		}
     	}
	 	else if (image.height > image.width) {
	 		image.height = imageMaxHeight;
	 		image.width = imageMaxHeight / image.height * image.width;
	 		if(image.width>imageMaxWidth){
	 			image.width = imageMaxWidth;
	 			image.height = imageMaxWidth / image.width * image.height;
	 		}
	 	}
	 	else if (image.height < image.width) {
	 		image.height = imageMaxWidth / image.width * image.height;
	 		image.width = imageMaxWidth;
	 	}
	 	else if(image.height == image.width && (image.height > imageMaxHeight || image.width > imageMaxWidth)){
	 		image.height = imageMaxHeight;
	 		image.width = imageMaxWidth;
	 	}
	 	if(showImage) image.style.visibility="visible";
	}
}

/************************************************************************************/
/* Developer */
/*********************************************************/
function submitHandleWidgetTypeChangement() {
	var widgetType = document.getElementById("typeId").value;
	if(widgetType == 4 ) {
		document.getElementById("fileTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = 'none';
		document.getElementById("mobileLinkCheckbox").className = "submitCheckboxDesactivate";
		submitRefreshCheckboxes("mobileLinkCheckbox");
		return;
	}
	if(widgetType == 8 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("urlTr").style.display = '';
		document.getElementById("filewidgetTr").style.display = 'none';
		document.getElementById("mobileLinkCheckbox").className = "submitCheckboxDesactivate";
		submitRefreshCheckboxes("mobileLinkCheckbox");
		return;
	}

	if(widgetType == 7 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		document.getElementById("airLinkCheckbox").className = "submitCheckboxDesactivate";
		submitRefreshCheckboxes("airLinkCheckbox");
		return;
	}
	if(widgetType == 6 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		document.getElementById("dashboardLinkCheckbox").className = "submitCheckboxDesactivate";
		submitRefreshCheckboxes("dashboardLinkCheckbox");
		return;
	}
	if(widgetType == 5 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		document.getElementById("vistaLinkCheckbox").className = "submitCheckboxDesactivate";
		submitRefreshCheckboxes("vistaLinkCheckbox");
		return;
	}
	
	if(widgetType == 22 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
	if(widgetType == 23) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
	if(widgetType == 24 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
	if(widgetType == 25 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
	if(widgetType == 26 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
	if(widgetType == 27 ) {
		document.getElementById("fileTr").style.display = 'none';
		document.getElementById("filewidgetTr").style.display = '';
		document.getElementById("urlTr").style.display = 'none';
		return;
	}
}

function clickOnLinksCheckbox(checkboxId,selectListId) {
	var oldStyleName = document.getElementById(checkboxId).className;
	
	if(oldStyleName=="submitCheckboxDesactivate") 
		return;
	
	if(oldStyleName == "submitCheckboxInactive") {
		document.getElementById(checkboxId).className = "submitCheckboxActive";
		document.getElementById(selectListId).disabled = false;
	
	} else {
		document.getElementById(checkboxId).className = "submitCheckboxInactive";
		document.getElementById(selectListId).disabled = true;
	}
}

function submitRefreshCheckboxes(currentCheckboxId) {
	if(currentCheckboxId != "mobileLinkCheckbox") {
		if(document.getElementById("mobileLinkCheckbox").className == "submitCheckboxDesactivate") {
			document.getElementById("mobileLinkCheckbox").className = "submitCheckboxInactive";
		}
	} else {
		document.getElementById("mobileLinkWidgetList").disabled = true;
	}
	
	if(currentCheckboxId != "vistaLinkCheckbox") {
		if(document.getElementById("vistaLinkCheckbox").className == "submitCheckboxDesactivate") {
			document.getElementById("vistaLinkCheckbox").className = "submitCheckboxInactive";
		} 
	} else {
		document.getElementById("mobileLinkWidgetList").disabled = true;
	}
	
	if(currentCheckboxId != "airLinkCheckbox") {
		if(document.getElementById("airLinkCheckbox").className == "submitCheckboxDesactivate") {
			document.getElementById("airLinkCheckbox").className = "submitCheckboxInactive";
		} 
	} else {
		document.getElementById("airLinkWidgetList").disabled = true;
	}
	
	if(currentCheckboxId != "dashboardLinkCheckbox") {
		if(document.getElementById("dashboardLinkCheckbox").className == "submitCheckboxDesactivate") {
			document.getElementById("dashboardLinkCheckbox").className = "submitCheckboxInactive";
		} 
	} else {
		document.getElementById("dashboardLinkWidgetList").disabled = true;
	}
}

function displayFaviconHelp() {
	document.getElementById("faviconHelp").style.visibility = 'visible';
}

function hideFaviconHelp() {
	document.getElementById("faviconHelp").style.visibility = 'hidden';
}

function displayScreenshot1Help() {
	document.getElementById("screenshot1Help").style.visibility = 'visible';
}

function hideScreenshot1Help() {
	document.getElementById("screenshot1Help").style.visibility = 'hidden';
}

function displayScreenshot2Help() {
	document.getElementById("screenshot2Help").style.visibility = 'visible';
}

function hideScreenshot2Help() {
	document.getElementById("screenshot2Help").style.visibility = 'hidden';
}


function getWidgetDetailResponseCallback(conn){
	var response = fromHTML(conn.responseText);
	var contentTabNode=document.getElementById("widgetDetailsPcMacContentTab");
	if(typeof(contentTabNode.firstChild.data) == "undefined"){
		//IE
		contentTabNode.replaceChild( response ,contentTabNode.firstChild ); 
		
	}else{
		//FF
		contentTabNode.removeChild(contentTabNode.firstChild);
		contentTabNode.replaceChild( response ,contentTabNode.firstChild );
	}	
	InitPbSrc();InitPbPopBar();	
	
	var image = document.getElementById('screenshot1'); 
	if(image!=null && isImgComplete(image)){
		setTimeout("scaleImage(document.getElementById('screenshot1'))",1000);
	}
	
	image = document.getElementById('screenshot2');
	if(image!=null && isImgComplete(image)){
		setTimeout("scaleImage(document.getElementById('screenshot2'))",1000);
	}
	document.getElementById("permalink").value = location.href;
	document.getElementById("embed").value = "<a href='"+location.href+"'><img style='border:0;' alt='"+document.getElementById('getIt').value+"' title='"+document.getElementById('getIt').value+"' src='"+document.getElementById('djinngourl').value+"'></a>";
	/*if (FB) {
		FB.Share._onFirst();
		//"FB.SharePro" ]);
	}*/
}

function getWidgetDetail(id){
	var url = 'index.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','WidgetAction');
	XHR.appendDataWithEscapeValue('action','getWidgetDetailTab');
	XHR.appendDataWithEscapeValue('id',id);
	XHR.sendAndLoad(url, "POST",getWidgetDetailResponseCallback);
}

/* widget detail tab management */
function selectTabDetail(nbTabs, indexSelectedTab){
	document.getElementById('widgetDetailsPcMacTabs').className = "wPcMacDetailsTabs wPcMacDetails"+nbTabs+"Tabs_Tab"+indexSelectedTab+"Selected";
	for(i=1;i<=nbTabs;i++){
		elt = document.getElementById("tab"+i);
		if(elt != null){
			if(elt.id == "tab"+indexSelectedTab) elt.className = "wPcMacDetailTab";
			else elt.className = "wPcMacDetailHiddenTab";
		}
	}
}

/* customized select management */
function initStyledSelect(){
	var inputs = document.getElementsByTagName("select"),spanSelect = Array(), funcArrayA = Array(),funcArrayB = Array();
	var textnode, option, active;
	var selectOnChangeEventArray = Array();
	for(a = 0; a < inputs.length; a++) {
		var nameA = inputs[a].name;
		var idA = inputs[a].id;		
		selectOnChangeEventArray[a] = (inputs[a].onchange) ? inputs[a].onchange : function () {};
		
		if(inputs[a].className == "styledSelect") {
			option = inputs[a].getElementsByTagName("option");
			active = option[0].childNodes[0].nodeValue;
			if(option[0].label == "node"){
				if(idA == "flag"){
					active=active.replace("22x14","20x18");
					textnode = fromHTML(active);
					textnode.removeChild(textnode.lastChild);
				}else{
					if(idA == "s"){
						var n = document.getElementById(idA).options[document.getElementById(idA).selectedIndex];
						var nodeContent;
						if(n.text!="node") nodeContent = n.text;
						else nodeContent = n.textContent;
						textnode = fromHTML(nodeContent);
						if(textnode.lastChild != null)	textnode = textnode.lastChild;
						textnode.style.color = "#FFFFFF";
						textnode.style.display = "block";
						textnode.style.width = "140px";
						textnode.style.textAlign = "center";
					}else{	
						textnode = null;
					}
				}
			}else{
				textnode = document.createTextNode(active);
			}
			var divOptions = document.createElement("div");
			divOptions.className = "divOptionsHidden";
			divOptions.id = "div_"+nameA;
			for(b = 0; b < option.length; b++) {
				if(option[b].selected == true) {
					var nodeValue="";
					if(option[b].label == "node"){
						if(option[b].childNodes[0] != null) selectedNode=fromHTML(option[b].childNodes[0].nodeValue);
						if(idA == "flag"){
							textnode = selectedNode.cloneNode(true);
							textnode.firstChild.src=textnode.firstChild.src.replace("22x14","20x18");
							textnode.removeChild(textnode.lastChild);
						}
					}else{						
						if(option[b].childNodes[0] != null) nodeValue=option[b].childNodes[0].nodeValue;
						textnode = document.createTextNode(nodeValue);
					}
				}
				optionElt = document.createElement("div");
				optionElt.id = nameA+"_"+b;
				optionElt.className = "customOption "+idA+"_customOption";
				var optionLabel = "";
				var optionType = "";
				if(option[b].label == "node"){
					if(option[b].childNodes[0] != null) optionLabel = fromHTML(option[b].childNodes[0].nodeValue); 
					optionElt.appendChild(optionLabel);
					optionType = "node";
				}else{					
					if(option[b].childNodes[0] != null) optionLabel = option[b].childNodes[0].nodeValue; 
					optionElt.appendChild(document.createTextNode(optionLabel));
				}
				
				optionElt.onclick = (function(optionId,optionLabel,onSelectIndex, optionType) {
											return function(){ optionSelected(optionId,optionLabel, optionType); (selectOnChangeEventArray[onSelectIndex])();};
										})(optionElt.id,optionLabel,a, optionType);
				
				divOptions.appendChild(optionElt);
			}
			spanSelect[a] = document.createElement("span");
			spanSelect[a].className = "customSelect "+idA+"_customSelect";
			spanSelect[a].id = "select_" + nameA;
			if(textnode != null) spanSelect[a].appendChild(textnode);
			inputs[a].parentNode.insertBefore(spanSelect[a], inputs[a]);
			spanSelect[a].appendChild(divOptions);
			spanSelect[a].onclick = (function(divOptionsId) {
								return function(){ showHideOptions(divOptionsId); };
							})(divOptions.id);
		}
	}
}

function showHideOptions(divOptionsId){
	var elts = YAHOO.util.Dom.getElementsByClassName('divOptionsVisible');
	for(i=0;i<elts.length;i++){
		if(elts[i].id != divOptionsId) elts[i].className = "divOptionsHidden";
	}
	
	elt = document.getElementById(divOptionsId);
	elt.className == "divOptionsHidden"?elt.className="divOptionsVisible":elt.className="divOptionsHidden";	
	
	divFlash = document.getElementById("advertiseDivFlash");
	if( divFlash != null && divOptionsId == "div_c"){
		if(elt.className == "divOptionsVisible") divFlash.style.visibility = 'hidden';
		else divFlash.style.visibility = 'visible';		
	}
}

function optionSelected(optionId,optionLabel, optionType){
	var tmp = optionId.split("_");
	if(optionType == "node"){
		if(tmp[0] == "flag"){
			clone = optionLabel.cloneNode(true);
			clone.firstChild.src=clone.firstChild.src.replace("22x14","20x18");
			clone.removeChild(clone.lastChild);
			document.getElementById("select_"+tmp[0]).replaceChild(clone, document.getElementById("select_"+tmp[0]).firstChild);
		}
		if(tmp[0] == "exactPlatform"){
			var nbOptions = document.getElementById("exactPlatform").options.length;
			for(i=0;i<nbOptions;i++){
				document.getElementById("img_platform_"+i).src="img/flag/not_selected.png";
			}
			document.getElementById("img_platform_"+tmp[1]).src="img/flag/selected.png";
			x = document.getElementById("plateform");
			if(x != null){
				x.parentNode.removeChild(x);
			}
		}
		if(tmp[0] == "s"){
			var nbOptions = document.getElementById("s").options.length;
			for(i=0;i<nbOptions;i++){
				document.getElementById("img_sort_"+i).src="img/flag/not_selected.png";
			}
			document.getElementById("img_sort_"+tmp[1]).src="img/flag/selected.png";
			if(tmp[1]=="3"){
				document.getElementById("sortOrder").value = 1;
			}else{
				document.getElementById("sortOrder").value = 0;
			}
			clone = optionLabel.lastChild.cloneNode(true);
			clone.style.color = "#FFFFFF";
			clone.style.display = "block";
			clone.style.width = "140px";
			clone.style.textAlign = "center";
			document.getElementById("select_"+tmp[0]).replaceChild(clone, document.getElementById("select_"+tmp[0]).firstChild);
		}
	}else{
		document.getElementById("select_"+tmp[0]).firstChild.nodeValue = optionLabel;
	}
	document.getElementById(tmp[0]).selectedIndex=tmp[1];
}

/*RUBICS*/
function gallerySignin() {
	if(document.getElementById('advertiseDivFlash') != null) { 
		document.getElementById('advertiseDivFlash').style.visibility='hidden';
	}
	if(document.getElementById('airPlugin') != null) { 
		document.getElementById('airPlugin').style.visibility='hidden';
	}
	
	
		
	if((elt = document.getElementById('close')) != null){
		var oldEvent = (elt.onclick) ? elt.onclick : function () {};
		elt.onclick = function(){
			oldEvent();
		    if(document.getElementById('advertiseDivFlash') != null) {
		    	document.getElementById('advertiseDivFlash').style.visibility='visible';
		    }
		    if(document.getElementById('airPlugin') != null) { 
				document.getElementById('airPlugin').style.visibility='visible';
			}
		};
	}
	
	window.location = "authent_signin.html";
}

function gallerySignup(){
	if(document.getElementById('advertiseDivFlash') != null) { 
		document.getElementById('advertiseDivFlash').style.visibility='hidden';
	}
	if(document.getElementById('airPlugin') != null) { 
		document.getElementById('airPlugin').style.visibility='hidden';
	}
	
	if((elt = document.getElementById('close')) != null){
		var oldEvent = (elt.onclick) ? elt.onclick : function () {};
		elt.onclick = function(){
			oldEvent();
		    if(document.getElementById('advertiseDivFlash') != null) {
		    	document.getElementById('advertiseDivFlash').style.visibility='visible';
		    }
		    if(document.getElementById('airPlugin') != null) { 
				document.getElementById('airPlugin').style.visibility='visible';
			}
		};
	}
	
	window.location = "authent_signup.html";
}



/************************** POPUP FUNCTIONS *************************************/
function displayPopUp(popupIdName) {
	document.getElementById('blackout').style.visibility = 'visible';
	document.getElementById(popupIdName).style.visibility = 'visible';
	document.getElementById('blackout').style.display = 'block';
	document.getElementById(popupIdName).style.display = 'block';
}

function hidePopUp(popupIdName) {
	document.getElementById('blackout').style.visibility = 'hidden';
	document.getElementById(popupIdName).style.visibility = 'hidden';
	document.getElementById('blackout').style.display = 'none';
	document.getElementById(popupIdName).style.display = 'none';
}

/************************ FAST WIDGET FUNCTIONS ********************************/
var feedDivHeight = 70; 
var maxFeeds = 5; 

function addToIFrameDivHeight(){
	var px = arguments[0];
	var iframeWizard = document.getElementById("iframeWizard");
	try{
		var documentObj = iframeWizard.contentWindow.document;
	}catch(e){
		var documentObj = iframeObj.contentDocument.document;
	}
	for(var i = 1; i < arguments.length; i++) {
		var height = documentObj.getElementById(arguments[i]).style.height;
		var newHeight = parseInt(height.replace("px","")) + px;
		documentObj.getElementById(arguments[i]).style.height =  newHeight+"px";
	}
}

function minusToIFrameDivHeight(){
	var px = arguments[0];
	var iframeWizard = document.getElementById("iframeWizard");
	try{
		var documentObj = iframeWizard.contentWindow.document;
	}catch(e){
		var documentObj = iframeObj.contentDocument.document;
	}
	for(var i = 1; i < arguments.length; i++) {
		var height = documentObj.getElementById(arguments[i]).style.height;
		var newHeight = parseInt(height.replace("px","")) - px;
		documentObj.getElementById(arguments[i]).style.height =  newHeight+"px";
	}
}

function setAction(action, parent) {
	if(parent){
		var docParent = window.parent.document;
		docParent.getElementById("action").value = action;
		if((elt = document.getElementById("locale")) != null)
			docParent.getElementById("locale").value = elt.value;
		if((elt = document.getElementById("category")) != null)
			docParent.getElementById("category").value = elt.value;
		if((elt = document.getElementById("country")) != null)
			docParent.getElementById("country").value = elt.value;
		if((elt = document.getElementById("description")) != null)
			docParent.getElementById("description").value = elt.value;
		if((elt = document.getElementById("url")) != null)
			docParent.getElementById("url").value = elt.value;
		if((elt = document.getElementById("sendEmails")) != null){
			docParent.getElementById("sendEmails").value = "on";
			if((elt = document.getElementById("emailsInput")) != null)
				docParent.getElementById("emails").value = elt.value;
		}		
		docParent.getElementById("form").submit();
	}else{
		document.getElementById("action").value = action;
		document.getElementById("form").submit();
	}
}

function enabledDisabled(el, enabled, idModification, keepValue) {
	try {			
		el.disabled = enabled;
		if (idModification != -1) {
			var eltId = el.id;
			if(eltId.match(/multifeed_/)){
				el.id = "multifeed_"+idModification;
				el.name = "multifeed_"+idModification;
			}else if(eltId.match(/nameFeed_/)){
				el.id = "nameFeed_"+idModification;
				el.name = "nameFeed_"+idModification;
				el.onkeyup = function(){addNewTab(idModification,this.value,el.id);};
				if(!keepValue) el.value="";				
			}else if(eltId.match(/urlFeed_/)){
				el.id = "urlFeed_"+idModification;
				el.name = "urlFeed_"+idModification;
				if(!keepValue) el.value="";				
			}else if(eltId.match(/deleteFeed_/)){
				el.id = "deleteFeed_"+idModification;
				el.name = "deleteFeed_"+idModification;
			}else if(eltId.match(/imgDelete_/)){
				el.id = "imgDelete_"+idModification;
				el.name = "imgDelete_"+idModification;
				el.onclick = function(){deleteFeed(idModification);removeTab(idModification);};
			}else if(eltId.match(/validFeed_/)){
				el.id = "validFeed_"+idModification;
				el.name = "validFeed_"+idModification;
			}else if(eltId.match(/imgValid_/)){
				el.id = "imgValid_"+idModification;
				el.name = "imgValid_"+idModification;		
			}else if(eltId.match(/linkImgValid_/)){
				el.id = "linkImgValid_"+idModification;
				el.name = "linkImgValid_"+idModification;
				el.onclick = function(){addNewFeed(idModification,'urlFeed_'+idModification);};
			}
		}
	} catch (E) {		
	}
	if (el.childNodes && el.childNodes.length > 0) {
		for ( var x = 0; x < el.childNodes.length; x++) {
			enabledDisabled(el.childNodes[x], enabled, idModification, keepValue);
		}
	}
}

function show(eltId) {
	var elt = document.getElementById(eltId);
	if (elt) {
		elt.style.visibility = "visible";
		elt.style.display = "block";
	}
}

function hide(eltId) {
	var elt = document.getElementById(eltId);
	if (elt) {
		elt.style.visibility = "hidden";
		elt.style.display = "none";
	}
}

function startFW() {
	document.getElementById('addFeedMultiInactive').style.display = 'none';
}

function backToggleToMultiFeed(){
	hide('oneFeedWidget');
	enabledDisabled(document.getElementById('multiFeedWidget'), false, -1, false);	
	enabledDisabled(document.getElementById('oneFeedWidget'), true, -1, false);	
	show('multiFeedWidget');
}

function toggleToMultiFeed(){
	hide('oneFeedWidget');
	enabledDisabled(document.getElementById('multiFeedWidget'), false, -1, false);
	document.getElementById("widgetNameMultiFeed").value = document.getElementById("widgetNameOneFeed").value;
	document.getElementById("urlFeed_1MultiFeed").value = document.getElementById("urlFeed_1OneFeed").value;
	enabledDisabled(document.getElementById('oneFeedWidget'), true, -1, false);	
	show('multiFeedWidget');
}

function toggleToMultiFeedAndAddOneFeed() {
	document.getElementById("addFeedMultiActive").style.display='none';
	document.getElementById("addFeedMultiInactive").style.display='block';
	document.getElementById("wizardNextActive").style.display='none';
	document.getElementById("wizardNextInactive").style.display='block';
	toggleToMultiFeed();		
	var nextNbFeeds = parseInt(document.getElementById("nbFeeds").value) + 1;
	document.getElementById("nbFeeds").value = nextNbFeeds;
}

function toggleToOneFeed() {
	hide('multiFeedWidget');
	enabledDisabled(document.getElementById('oneFeedWidget'), false, -1, false);
	document.getElementById("widgetNameOneFeed").value = document.getElementById("widgetNameMultiFeed").value;
	document.getElementById("urlFeed_1OneFeed").value = document.getElementById("urlFeed_1MultiFeed").value;
	document.getElementById("nameFeed_1").value = "";
	document.getElementById("nameFeed_2").value = "";
	document.getElementById("urlFeed_2").value = "";
	enabledDisabled(document.getElementById('multiFeedWidget'), true, -1, false);
	show('oneFeedWidget');	
	document.getElementById("nbFeeds").value = 1;
}

function addFeed() {
	document.getElementById("wizardNextActive").style.display='none';
	document.getElementById("wizardNextInactive").style.display='block';
	document.getElementById("addFeedMultiActive").style.display='none';
	document.getElementById("addFeedMultiInactive").style.display='block';
	
	var multiFeedsNode = document.getElementById("multiFeeds");		
	var currentNbFeeds =  parseInt(document.getElementById("nbFeeds").value);
	var nextFeedId = parseInt(document.getElementById("nextFeedId").value);
	var feedNode = multiFeedsNode.children[1];
	
	/*if(currentNbFeeds == 2){
		var clone = feedNode.cloneNode(true);
		enabledDisabled(clone, false, 2, true);
		multiFeedsNode.appendChild(clone);
		multiFeedsNode.removeChild(feedNode);
	}*/
		
	/*clone = feedNode.cloneNode(true);*/
	/*enabledDisabled(clone, false, nextFeedId, false);*/
	
	if(currentNbFeeds == 2) {
		document.getElementById('multifeed_3').style.display ='block';
	}
	
	if(currentNbFeeds == 3) {
		document.getElementById('multifeed_4').style.display ='block';
	}
	
	if(currentNbFeeds == 4) {
		document.getElementById('multifeed_5').style.display ='block';
	}
	
	document.getElementById("nbFeeds").value = currentNbFeeds + 1;
	document.getElementById("nextFeedId").value = nextFeedId + 1;
	/*multiFeedsNode.appendChild(clone);*/
	if(parseInt(document.getElementById("nbFeeds").value) == maxFeeds){
		document.getElementById("addFeedMultiInactive").style.display="none";
	}
}

function deleteFeed(id){
	if(document.getElementById("nbFeeds").value == 2){
		var eltFeed = document.getElementById("urlFeed_"+id);
		if(eltFeed.value == "" || eltFeed.style.borderColor == "#FF0000"){
			document.getElementById("addFeedMultiActive").style.display='block';
			document.getElementById("addFeedMultiInactive").style.display='none';
			document.getElementById("wizardNextActive").style.display='block';
			document.getElementById("wizardNextInactive").style.display='none';
			document.getElementById("urlFeed_"+id).style.borderColor = '#808080';
		}else{
			document.getElementById("addFeedMultiActive").style.display='none';
			document.getElementById("addFeedMultiInactive").style.display='block';
			document.getElementById("wizardNextActive").style.display='block';
			document.getElementById("wizardNextInactive").style.display='none';
		}
		
//		document.getElementById("multifeed_2").style.display="none";
		document.getElementById("nbFeeds").value = 1;
		
		document.getElementById("urlFeed_2").value = "";
		document.getElementById("nameFeed_2").value ="";
		
		hide('multiFeedWidget');
		enabledDisabled(document.getElementById('oneFeedWidget'), false, -1, false);
		document.getElementById('addFeedMultiInactive').style.display = "none";
		document.getElementById('desc2Inactive').style.display = "none";
		document.getElementById('urlFeed_1OneFeed').disabled = false;
		document.getElementById('widgetNameOneFeed').disabled = false;
		enabledDisabled(document.getElementById('multiFeedWidget'), true, -1, false);
		show('oneFeedWidget');	
		
	}else{
		var eltFeed = document.getElementById("urlFeed_"+id);
		if(eltFeed.value == "" || eltFeed.style.borderColor == "#FF0000"){
			document.getElementById("addFeedMultiActive").style.display='block';
			document.getElementById("addFeedMultiInactive").style.display='none';
			document.getElementById("wizardNextActive").style.display='block';
			document.getElementById("wizardNextInactive").style.display='none';
			document.getElementById("urlFeed_"+id).style.borderColor = '#808080';
		}
		eltFeed.value = "";
		document.getElementById("nameFeed_"+id).style.value ='';
		
		if(id == 2) {
			document.getElementById("urlFeed_"+id).value = document.getElementById("urlFeed_"+(id+1)).value;
			document.getElementById("nameFeed_"+id).value = document.getElementById("nameFeed_"+(id+1)).value;
			document.getElementById("urlFeed_"+(id+1)).value = document.getElementById("urlFeed_"+(id+2)).value;
			document.getElementById("nameFeed_"+(id+1)).value = document.getElementById("nameFeed_"+(id+2)).value;
			document.getElementById("urlFeed_"+(id+2)).value = document.getElementById("urlFeed_"+(id+3)).value;
			document.getElementById("nameFeed_"+(id+2)).value = document.getElementById("nameFeed_"+(id+3)).value;
		} else if(id == 3) {
			document.getElementById("urlFeed_"+id).value = document.getElementById("urlFeed_"+(id+1)).value;
			document.getElementById("nameFeed_"+id).value = document.getElementById("nameFeed_"+(id+1)).value;
			document.getElementById("urlFeed_"+(id+1)).value = document.getElementById("urlFeed_"+(id+2)).value;
			document.getElementById("nameFeed_"+(id+1)).value = document.getElementById("nameFeed_"+(id+2)).value;
		} else if(id == 4) {
			document.getElementById("urlFeed_"+id).value = document.getElementById("urlFeed_"+(id+1)).value;
			document.getElementById("nameFeed_"+id).value = document.getElementById("nameFeed_"+(id+1)).value;
		} 
			
		if(document.getElementById("multifeed_5").style.display=="block") {
			document.getElementById("multifeed_5").style.display="none";
			document.getElementById("urlFeed_5").value = "";
			document.getElementById("nameFeed_5").value ="";
		} else if(document.getElementById("multifeed_4").style.display=="block") {
			document.getElementById("multifeed_4").style.display="none";
			document.getElementById("urlFeed_4").value = "";
			document.getElementById("nameFeed_4").value ="";
		} else if(document.getElementById("multifeed_3").style.display=="block") {
			document.getElementById("multifeed_3").style.display="none";
			document.getElementById("urlFeed_3").value = "";
			document.getElementById("nameFeed_3").value ="";
		}
		
		var nextNbFeeds = parseInt(document.getElementById("nbFeeds").value) - 1;
		document.getElementById("nbFeeds").value = nextNbFeeds;
		if(parseInt(document.getElementById("nbFeeds").value) < maxFeeds){
			if(id == (parseInt(document.getElementById("nextFeedId").value)-1)){
				document.getElementById("wizardNextActive").style.display ="block";
				document.getElementById("wizardNextInactive").style.display ="none";				
				document.getElementById("addFeedMultiActive").style.display="block";
				document.getElementById("addFeedMultiInactive").style.display="none";
			}else{
				if(document.getElementById("wizardNextInactive").style.display == "block"){
					document.getElementById("addFeedMultiActive").style.display="none";
					document.getElementById("addFeedMultiInactive").style.display="block";
				}else{
					document.getElementById("addFeedMultiActive").style.display="block";
					document.getElementById("addFeedMultiInactive").style.display="none";				
				}
			}
		}
	}
}



function initCheckBox(){
	var labels = document.getElementsByTagName("label");
	var onclick = new Array();
	for(var i=0;i<labels.length;i++){
		if(labels[i].className == 'modifiedCheckbox' || labels[i].className == 'modifiedRadio' || labels[i].className == 'modifiedCheckboxUnavailable'){
			var labelFor = labels[i].getAttributeNode('for').nodeValue; 
			if ( labelFor != null && labelFor.value != '') {
				var elt = document.getElementById(labelFor);
				 onclick[i] = (elt.onclick) ? elt.onclick : function () {};
				 
				 elt.onclick = function(){
					 var labelsSearch = document.getElementsByTagName("label");
					 for(var j=0;j<labelsSearch.length;j++){
						 var labelForSearch = labelsSearch[j].getAttributeNode('for').nodeValue;
						 var el = document.getElementById(labelForSearch);
						 if(labelForSearch == this.id){						 
							 (onclick[j])();
							 if(this.checked && labelsSearch[j].className == 'checkbox_unchecked') {								 
								 labelsSearch[j].className = "checkbox_checked";								 
							 }else if(labelsSearch[j].className == 'checkbox_checked'){
								 labelsSearch[j].className = "checkbox_unchecked";								 
							 }else{//radio button
								 for(k=0;k<labelsSearch.length;k++){
									 if(labelsSearch[k].className == "radio_selected" || labelsSearch[k].className == "radio_unselected"){
										 labelsSearch[k].className = "radio_unselected";
									 } 
								 }
							 	if(this.checked) labelsSearch[j].className = "radio_selected";
							 }

							 break;
						 }
					 }
				};
				 
				if(elt.checked){
					if(labels[i].className == 'modifiedCheckbox') labels[i].className = "checkbox_checked";
					else if(labels[i].className == 'modifiedCheckboxUnavailable') labels[i].className = "checkbox_unavailable";
					else if(labels[i].className == 'modifiedRadio') labels[i].className = "radio_selected";
				}else{
					if(labels[i].className == 'modifiedCheckbox') labels[i].className = "checkbox_unchecked";
					else if(labels[i].className == 'modifiedCheckboxUnavailable') labels[i].className = "checkbox_unavailable";
					else if(labels[i].className == 'modifiedRadio') labels[i].className = "radio_unselected";
				}
			}
		}
	}
}

function uncheckDisplay(){
	var elt = document.getElementById("displayMode");
	if(!elt.checked){
		document.getElementById("displayModePhoto").checked=false;		
		document.getElementById("displayModePhotoWithoutText").checked=false;
		document.getElementById("displayModeFastDetails").checked=false;
		
		var labelsSearch = document.getElementsByTagName("label");
		for(var j=0;j<labelsSearch.length;j++){
			var labelForSearch = labelsSearch[j].getAttributeNode('for').nodeValue;
			if( labelForSearch == "displayModePhoto" || labelForSearch == "displayModePhotoWithoutText" || labelForSearch == "displayModeFastDetails"){
				labelsSearch[j].className = "checkbox_unavailable";
				document.getElementById(labelForSearch).disabled = true;
			}
		}		
	}else{
		var labelsSearch = document.getElementsByTagName("label");
		for(var j=0;j<labelsSearch.length;j++){
			var labelForSearch = labelsSearch[j].getAttributeNode('for').nodeValue;
			if( labelForSearch == "displayModePhoto" || labelForSearch == "displayModePhotoWithoutText" || labelForSearch == "displayModeFastDetails"){
				labelsSearch[j].className = "checkbox_unchecked";
				document.getElementById(labelForSearch).disabled = false;
			}
		}
	}
}

function uncheckShare(){
	var elt = document.getElementById("share");
	if(!elt.checked){
		document.getElementById("shareTheWidget").checked=false;
		document.getElementById("shareTheArticle").checked=false;
		
		var labelsSearch = document.getElementsByTagName("label");
		for(var j=0;j<labelsSearch.length;j++){
			var labelForSearch = labelsSearch[j].getAttributeNode('for').nodeValue;
			if( labelForSearch == "shareTheWidget" || labelForSearch == "shareTheArticle"){
				labelsSearch[j].className = "checkbox_unavailable";
				document.getElementById(labelForSearch).disabled = true;
			}
		}		
	}else{
		var labelsSearch = document.getElementsByTagName("label");
		for(var j=0;j<labelsSearch.length;j++){
			var labelForSearch = labelsSearch[j].getAttributeNode('for').nodeValue;
			if( labelForSearch == "shareTheWidget" || labelForSearch == "shareTheArticle"){
				labelsSearch[j].className = "checkbox_unchecked";
				document.getElementById(labelForSearch).disabled = false;
			}
		}
	}
}

function showHideEmailBox(){
	var elt = document.getElementById('emailBox');
	elt.style.display = (elt.style.display=='none')?'block':'none';
}

function showHideHelp(helpBoxName,helpImg){	
	if(helpBoxName == 'feedWidgetHelp'){
		offsetX = 27;
		offsetY = -678;
	}else{
		offsetX = 27;
		offsetY = -638;
	}
	if(helpImg != null){
		var eltimg = document.getElementById(helpImg);
		posX = getPositionLeft(eltimg)+offsetX;
		posY = getPositionTop(eltimg)+offsetY;
	}
	var docParent = window.parent.document;
	var eltbox = docParent.getElementById(helpBoxName);
	
	if(helpImg != null){
		eltbox.style.left = posX+"px";
		eltbox.style.top = posY+"px";
	}
	eltbox.style.display = (eltbox.style.display=='none')?'block':'none';
}

function getPositionLeft (obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		while (obj = obj.offsetParent) {curleft += obj.offsetLeft;}
	}
	return curleft;
}



function getPositionTop (obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {curtop += obj.offsetTop;}
	}
	return curtop;
}

function hideHelp(helpBoxName){
	var docParent = window.parent.document;
	var eltbox = docParent.getElementById(helpBoxName);
	eltbox.style.display = 'none';
}

function getApplicationReference(){
	return	window.parent.document.getElementById('mobileEmulator');
}

function getDesktopApplicationReference() {
	return	window.parent.document.getElementById('pcmacEmulator');
}

function snapshotApplication(jobid) {
	try {
		getApplicationReference().snapshotApplication(jobid);
		getDesktopApplicationReference().snapshotApplication(jobid);
	} catch(err) {
	}
}

function showErrorBox(documentObj,msg){
	documentObj.getElementById('blackout').style.visibility = 'visible';
	documentObj.getElementById('popup').style.visibility = 'visible';
	documentObj.getElementById('blackout').style.display = 'block';
	documentObj.getElementById('popup').style.display = 'block';
	documentObj.getElementById('msgError').innerHTML = msg; 
}

function hideErrorBox(documentObj,eltId){	
	documentObj.getElementById(eltId).style.borderColor = '#808080';
}

function feedValidation(eltId, status){
	var iframeWizard = document.getElementById("iframeWizard");
	try{
		var documentObj = iframeWizard.contentWindow.document;
	}catch(e){
		var documentObj = iframeObj.contentDocument.document;
	}
	popupDocument = window.document;
	var nbFeeds = parseInt(documentObj.getElementById("nbFeeds").value);
	if(!status){				
		showErrorBox(popupDocument,addFeedErrorMsg);
		documentObj.getElementById(eltId).style.borderColor = '#FF0000';
		if(nbFeeds == 1) {
			documentObj.getElementById("desc2Active").style.display='none';
			documentObj.getElementById("desc2Inactive").style.display='block';
		}else{
			if(parseInt(documentObj.getElementById("nbFeeds").value) == maxFeeds){
				documentObj.getElementById("addFeedMultiActive").style.display='none';
				documentObj.getElementById("addFeedMultiInactive").style.display='none';
			}else{
				documentObj.getElementById("addFeedMultiActive").style.display='none';
				documentObj.getElementById("addFeedMultiInactive").style.display='block';
			}
		}		
		documentObj.getElementById("wizardNextActive").style.display='none';
		documentObj.getElementById("wizardNextInactive").style.display='block';	
		documentObj.getElementById("feedValidationStatus").value = "ko";
		documentObj.getElementById("breadcrumbImg").useMap="";
	}else{			
		hideErrorBox(documentObj,eltId);
		if(nbFeeds == 1) {
			documentObj.getElementById("desc2Active").style.display='block';
			documentObj.getElementById("desc2Inactive").style.display='none';
		}else{
			if(parseInt(documentObj.getElementById("nbFeeds").value) == maxFeeds){
				documentObj.getElementById("addFeedMultiActive").style.display='none';
				documentObj.getElementById("addFeedMultiInactive").style.display='none';
			}else{
				documentObj.getElementById("addFeedMultiActive").style.display='block';
				documentObj.getElementById("addFeedMultiInactive").style.display='none';
			}
		}
		if(nbFeeds>0){
			documentObj.getElementById("wizardReset").style.visibility='visible';
		}
		documentObj.getElementById("wizardNextActive").style.display='block';
		documentObj.getElementById("wizardNextInactive").style.display='none';
		documentObj.getElementById("feedValidationStatus").value = "ok";
		documentObj.getElementById("breadcrumbImg").useMap="#breadscrumbMap";
	}
}

function resetFeeds() {
	try {
		getApplicationReference().resetFeeds();
		getDesktopApplicationReference().resetFeeds();
	} catch(err) {
	}
}

function setBackgroundTabColor(value) {
	try {
		getApplicationReference().setBackgroundTabColor(value);
	} catch(err) {
	}
}

function setUnselectedTabFontColor(value) {
	try {
		getApplicationReference().setUnselectedTabFontColor(value);
		getDesktopApplicationReference().setUnselectedTabFontColor(value);
	} catch(err) {
		alert('setUnselectedTabFontColor ' +err);
	}
}

function setUnselectedTabZoneColor(value) {
	try {
		getApplicationReference().setUnselectedTabZoneColor(value);
		getDesktopApplicationReference().setUnselectedTabZoneColor(value);
	} catch(err) {
	}
}

function setSelectedTabFontColor(value) {
	try {
		getApplicationReference().setSelectedTabFontColor(value);
		getDesktopApplicationReference().setSelectedTabFontColor(value);
	} catch(err) {
	}
}

function setSelectedTabZoneColor(value) {
	try {
		getApplicationReference().setSelectedTabZoneColor(value);
		getDesktopApplicationReference().setSelectedTabZoneColor(value);
	} catch(err) {
	}
}

function setWidgetName(value) {
	try {
		getApplicationReference().setWidgetName(value);
		getDesktopApplicationReference().setWidgetName(value);
	} catch(err) {
	}
}

function setDisplayMode(value) {
	try {
		getApplicationReference().setDisplayMode(value);
		getDesktopApplicationReference().setDisplayMode(value);
	} catch(err) {
	}
}

function addNewTab(id,value,eltId) {
	try {
		getApplicationReference().addNewTab(id,value, eltId);
		getDesktopApplicationReference().addNewTab(id,value, eltId);
	} catch(err) {
		alert('addNewTab ' +err);
	}
}

function addNewFeed(id,eltId) {
	try {
		val = document.getElementById(eltId).value;
		getApplicationReference().addNewFeed(id,val,eltId);	
		getDesktopApplicationReference().addNewFeed(id,val,eltId);
	} catch(err) {
	}
}

function removeTab(id) {
	try {
		getApplicationReference().removeTab(id);
		getDesktopApplicationReference().removeTab(id);
	} catch(err) {
	}
}

function setNbItemsToDisplay(value) {
	try {
		getApplicationReference().setNbItemsToDisplay(value);
	} catch(err) {
	}
}

function setBannerBackgroundColor(color) {
	try {
		getApplicationReference().setBannerBackgroundColor(color);
		getDesktopApplicationReference().setBannerBackgroundColor(color);
	} catch(err) {
		alert('setBannerBackgroundColor ' +err);
	}
}

function setFooterBackgroundColor(color) {
	try {
		getApplicationReference().setFooterBackgroundColor(color);
	} catch(err) {
	}
}

function setFooterFontColor(color) {
	try {
		getApplicationReference().setFooterFontColor(color);
	} catch(err) {
	}
}

function setSelectedFeedZoneColor(color) {
	try {
		getApplicationReference().setSelectedFeedZoneColor(color);
		getDesktopApplicationReference().setSelectedFeedZoneColor(color);
	} catch(err) {
	}
}

function setSelectedFeedFontColor(color) {
	try {
		getApplicationReference().setSelectedFeedFontColor(color);
		getDesktopApplicationReference().setSelectedFeedFontColor(color);
	} catch(err) {
	}
}


function setUnselectedFeedZoneColor(color) {
	try {
		getApplicationReference().setUnselectedFeedZoneColor(color);
		getDesktopApplicationReference().setUnselectedFeedZoneColor(color);
	} catch(err) {
		alert('setUnselectedFeedZoneColor ' +err);
	}
}


function setUnselectedFeedFontColor(color) {
	try {
		getApplicationReference().setUnselectedFeedFontColor(color);
		getDesktopApplicationReference().setUnselectedFeedFontColor(color);
	} catch(err) {
	}
}

function setLogo() {
	try {
		getApplicationReference().setUrlLogo(document.getElementById("logoImg").src);
		getDesktopApplicationReference().setUrlLogo(document.getElementById("logoImg").src);
	} catch(err) {
	}
}

function setLogoUrl(url) {
	try {		
		getApplicationReference().setUrlLogo(url);
		getDesktopApplicationReference().setUrlLogo(url);
	} catch(err) {
	}
}


function handleChangeColorEvent(caller) {
	
	if(caller.idCaller == "titleBannerBackgroundColorShowSelected") {	//BackgroundColor
		setBannerBackgroundColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "optionsBackBackgroundColorShowSelected") {
		setFooterBackgroundColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "optionsBackFontColorShowSelected") {
		setFooterFontColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedContentSelectedAreaColorShowSelected") {
		setSelectedFeedZoneColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedContentSelectedFontColorShowSelected") {
		setSelectedFeedFontColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedContentNotSelectedAreaColorShowSelected") {
		setUnselectedFeedZoneColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedContentNotSelectedFontColorShowSelected") {
		setUnselectedFeedFontColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedsSelectedAreaColorShowSelected") {
		setSelectedTabZoneColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedsSelectedFontColorShowSelected") {
		setSelectedTabFontColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedsNotSelectedAreaColorShowSelected") {
		setUnselectedTabZoneColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedsNotSelectedFontColorShowSelected") {
		setUnselectedTabFontColor("#"+caller.picker.get('hex'));
	} else if(caller.idCaller == "feedsNotSelectedBackgroundColorShowSelected") {
		setBackgroundTabColor("#"+caller.picker.get('hex'));
	} 
}

function refreshFlash(){
	var iframeWizard = document.getElementById("iframeWizard");
	try{
		var content = iframeWizard.contentWindow;
	}catch(e){
		var content = iframeWizard.contentDocument;
	}
	content.refreshFlash();
}

function removeUrlLogo() {
	try {
		getApplicationReference().removeUrlLogo();
		getDesktopApplicationReference().removeUrlLogo();
	} catch(err) {
	}
}


function showAdobeAirBadge(){
	displayPopUp('popup2');
}

function closePopup(){	
	var firstNode=document.getElementById("firstNode");
	firstNode.removeChild(firstNode.firstChild);
	hidePopUp('popup');
}

function closePopup2(){	
	var firstNode=document.getElementById("firstNode");
	firstNode.removeChild(firstNode.firstChild);
	hidePopUp('popup2');
}

function closeErrorPopup(){	
	var errorMsgNode=document.getElementById("errorMsg");
	errorMsgNode.removeChild(errorMsgNode.firstChild);
}

function closePopupBadgeAir(){	
	hidePopUp('popup2');
}


//+ --------------------------------------------------------------------------------------
//+ XHRConnection
//+ V1.3
//+ Thanh Nguyen, http://www.sutekidane.net
//+ 20.10.2005
//+ http://creativecommons.org/licenses/by-sa/2.0/fr/deed.fr
//+ --------------------------------------------------------------------------------------
function XHRConnection() {
	
	// + ----------------------------------------------------------------------------------
	var conn = false;
	var debug = false;
	var datas = new String();
	var areaId = new String();
	// Objet XML
	var xmlObj;
	// Type de comportement au chargement du XML
	var xmlLoad;
	
	// + ----------------------------------------------------------------------------------
	try {
		conn = new XMLHttpRequest();
	}
	catch (error) {
		if (debug) { alert('Erreur lors de la tentative de cr�ation de l\'objet \nnew XMLHttpRequest()\n\n' + error); }
		try {
			conn = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (error) {
			if (debug) { alert('Erreur lors de la tentative de cr�ation de l\'objet \nnew ActiveXObject("Microsoft.XMLHTTP")\n\n' + error); }
			try {
				conn = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (error) {
				if (debug) { alert('Erreur lors de la tentative de cr�ation de l\'objet \nnew ActiveXObject("Msxml2.XMLHTTP")\n\n' + error); }
				conn = false;
			}
		}
	}

	// + ----------------------------------------------------------------------------------
	// + setDebugOff
	// + D�sactive l'affichage des exceptions
	// + ----------------------------------------------------------------------------------
	this.setDebugOff = function() {
		debug = false;
	};

	// + ----------------------------------------------------------------------------------
	// + setDebugOn
	// + Active l'affichage des exceptions
	// + ----------------------------------------------------------------------------------
	this.setDebugOn = function() {
		debug = true;
	};
	
	// + ----------------------------------------------------------------------------------
	// + resetData
	// + Permet de vider la pile des donn�es
	// + ----------------------------------------------------------------------------------
	this.resetData = function() {
		datas = new String();
		datas = '';
	};
	
	// + ----------------------------------------------------------------------------------
	// + appendData
	// + Permet d'empiler des donn�es afin de les envoyer
	// + ----------------------------------------------------------------------------------
	this.appendDataWithEscapeValue = function(pfield, pvalue) {
		datas += (datas.length == 0) ? pfield+ "=" + escape(pvalue) : "&" + pfield + "=" + encodeURIComponent(pvalue);
	};
	
	this.appendData = function(pfield, pvalue) {
		datas += (datas.length == 0) ? pfield+ "=" + pvalue : "&" + pfield + "=" + pvalue;
	};
	
	// + ----------------------------------------------------------------------------------
	// + setRefreshArea
	// + Indique quel elment identifi� par id est valoris lorsque l'objet XHR reoit une r�ponse
	// + ----------------------------------------------------------------------------------
	this.setRefreshArea = function(id) {
		areaId = id;
	};
	
	// + ----------------------------------------------------------------------------------
	// + createXMLObject
	// + M�thode permettant de cr�er un objet DOM, retourne la r�frence
	// + Inspir� de: http://www.quirksmode.org/dom/importxml.html
	// + ----------------------------------------------------------------------------------
	this.createXMLObject = function() {
		try {
			 	xmlDoc = document.implementation.createDocument("", "", null);
				xmlLoad = 'onload';
		}
		catch (error) {
			try {
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlLoad = 'onreadystatechange ';
			}
			catch (error) {
				if (debug) { alert('Erreur lors de la tentative de cr�ation de l\'objet XML\n\n'); }
				return false;
			}
		}
		return xmlDoc;
	};
	
	// + ----------------------------------------------------------------------------------
	// + Permet de d�finir l'objet XML qui doit �tre valoris� lorsque l'objet XHR reoit une r�ponse
	// + ----------------------------------------------------------------------------------
	this.setXMLObject = function(obj) {
		if (obj == undefined) {
				if (debug) { alert('Param�tre manquant lors de l\'appel de la m�thode setXMLObject'); }
				return false;
		}
		try {
			//xmlObj = this.createXMLObject();
			xmlObj = obj;
		}
		catch (error) {
				if (debug) { alert('Erreur lors de l\'affectation de l\'objet XML dans la m�thode setXMLObject'); }
		}
	};
	
	// + ----------------------------------------------------------------------------------
	// + loadXML
	// + Charge un fichier XML
	// + Entr�es
	// + 	xml			String		Le fichier XML � charger
	// + ----------------------------------------------------------------------------------
	this.loadXML = function(xml, callBack) {
		if (!conn) return false;
		// Chargement pour alimenter un objet DOM
		if (xmlObj && xml) {
			if (typeof callBack == "function") {
				if (xmlLoad == 'onload') {
					xmlObj.onload = function() {
						callBack(xmlObj);
					};
				}
				else {
					xmlObj.onreadystatechange = function() {
						if (xmlObj.readyState == 4) callBack(xmlObj);
					};
				}
			}
			xmlObj.load(xml);
			return;
		}		
	};

	// + ----------------------------------------------------------------------------------
	// + sendAndLoad
	// + Connexion � la page d�sir�e avec envoie des donn�es, puis mise en attente de la r�ponse
	// + Entr�es
	// + 	Url			String		L'url de la page � laquelle l'objet doit se connecter
	// + 	httpMode		String		La m�thode de communication HTTP : GET, HEAD ou POST
	// + 	callBack		Objet		Le nom de la fonction de callback
	// + ----------------------------------------------------------------------------------
	this.sendAndLoad = function(Url, httpMode, callBack) {
		httpMode = httpMode.toUpperCase();
		conn.onreadystatechange = function() {
			if (conn.readyState == 4 && conn.status == 200) {
				// Si une fonction de callBack a �t� d�finie
				if (typeof callBack == "function") {
					callBack(conn);
					return;
				}
				// Si une zone destin�e � r�cup�rer le r�sultat a �t� d�finie
				else if (areaId.length > 0){
					try {
						document.getElementById(areaId).innerHTML = conn.responseText;
					}
					catch(error) {
						if (debug) { alert('Echec, ' + areaId + ' n\'est pas un objet valide'); }
					}
					return;
				}
			}
		};
		switch(httpMode) {
			case "GET":
				try {
					Url = (datas.length > 0) ? Url + "?" + datas : Url;
					conn.open("GET", Url);
					conn.send(null);
				}
				catch(error) {
					if (debug) { alert('Echec lors de la transaction avec ' + Url + ' via la m�thode GET'); }
					return false;
				}
			break;
			case "POST":
				try {
					conn.open("POST", Url); 
					conn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					conn.send(datas);
				}
				catch(error) {
					if (debug) { alert('Echec lors de la transaction avec ' + Url + ' via la mthode POST'); }
					return false;
				}
			break;
			default :
				return false;
			break;
		}
		return true;
	};
	return this;
}

/*fromHTML()*/
function fromHTML(html) {
  var root = document.createElement('div');
  root.innerHTML = html;
  return root.firstChild;
}


/* Add To mobile */

function popupResponseCallback(conn){
	var popup=document.getElementById("popup");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup');
}

function popup2ResponseCallback(conn){
	var popup=document.getElementById("popup2");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup2');
}

function addToMobile(id,step,from){
	var XHR = new XHRConnection();
	var url = 'index.html';
	var uri = document.getElementById('uri').value;
	XHR.appendData('module','MobileAction');
	XHR.appendData('action','popupAddToMobile');
	XHR.appendData('uri',uri);
	XHR.appendData('id',id);
	XHR.appendData('step',step);
	XHR.appendData('from',from);
	
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function addWidgetToRepository(id,step,from){
	var XHR = new XHRConnection();
	var url = 'index.html';
	var uri = document.getElementById('uri').value;
	XHR.appendData('module','MobileAction');
	XHR.appendData('action','addWidgetToRepository');
	XHR.appendData('uri',uri);
	XHR.appendData('id',id);
	XHR.appendData('step',step);
	XHR.appendData('from',from);
	
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function installDjinngoMobile(){
	var XHR = new XHRConnection();
	var url = 'index.html';
	XHR.appendData('module','BusinessAction');
	XHR.appendData('action','installDjinngoMobile');
	XHR.sendAndLoad(url, "POST",popup2ResponseCallback);
}

function popupConfirmAddToMyMobileResponseCallback(conn){
	var popup=document.getElementById("popup");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup');
}

function sendAddToMyMobileConfirmation(){	
	document.getElementById('content').style.display='none';
	document.getElementById('addToMyMobileWait').style.display='block';
	
	var phoneNumber = document.getElementById('phoneNumber').value;
	var phoneIndicative = document.getElementById('phoneIndicative').value;
	var uri = document.getElementById('uri').value;	
	var captcha = document.getElementById('captcha').value;
	var hl = document.getElementById('hl').value;
	var id = document.getElementById('id').value;
	var step = document.getElementById('step').value;
	var from = document.getElementById('from').value;
	var url = 'index.html';
	
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.appendDataWithEscapeValue('module','MobileAction');
	XHR.appendDataWithEscapeValue('action','addToMobile');
	XHR.appendDataWithEscapeValue('phoneNumber',phoneNumber);
	XHR.appendDataWithEscapeValue('phoneIndicative',phoneIndicative);
	XHR.appendDataWithEscapeValue('uri',uri);
	XHR.appendDataWithEscapeValue('captcha',captcha);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('step',step);
	XHR.appendDataWithEscapeValue('from',from);
	XHR.sendAndLoad(url, "POST",popupConfirmAddToMyMobileResponseCallback);
}

function installDjinngoMobileConfirmation(){	
	document.getElementById('content').style.display='none';
	document.getElementById('addToMyMobileWait').style.display='block';
	
	var phoneNumber = document.getElementById('phoneNumber').value;
	var phoneIndicative = document.getElementById('phoneIndicative').value;
	var uri = document.getElementById('uri').value;	
	var captcha = document.getElementById('captcha').value;
	var hl = document.getElementById('hl').value;
	var id = document.getElementById('id').value;
	var step = document.getElementById('step').value;
	var from = document.getElementById('from').value;
	var url = 'index.html';
	
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.appendDataWithEscapeValue('module','BusinessAction');
	XHR.appendDataWithEscapeValue('action','installDjinngoMobileConfirmation');
	XHR.appendDataWithEscapeValue('phoneNumber',phoneNumber);
	XHR.appendDataWithEscapeValue('phoneIndicative',phoneIndicative);
	XHR.appendDataWithEscapeValue('uri',uri);
	XHR.appendDataWithEscapeValue('captcha',captcha);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('step',step);
	XHR.appendDataWithEscapeValue('from',from);
	XHR.sendAndLoad(url, "POST",popupInstallDjinngoMobileResponseCallback);
}

function popupInstallDjinngoMobileResponseCallback(conn){
	var popup=document.getElementById("popup2");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup2');
}

function toggleCommentArea(){
	var eltComments = document.getElementById('idComments');
	var eltTextArea = document.getElementById('commentTextarea');
	var eltCommentButton = document.getElementById('commentButton');
	var eltValidateCancelButtons = document.getElementById('validateCancelButtons');
	eltComments.style.display = (eltComments.style.display=='block')?'none':'block';
	eltTextArea.style.display = (eltTextArea.style.display=='block')?'none':'block';
	eltCommentButton.style.display = (eltCommentButton.style.display=='block')?'none':'block';
	eltValidateCancelButtons.style.display = (eltValidateCancelButtons.style.display=='block')?'none':'block';
}


function validateCommentsResponseCallback(conn){
	//si erreur, pas de destruction de la box
	var response = fromHTML(conn.responseText);
	var commentsNode=document.getElementById("commentsTable");
	if(typeof(commentsNode.firstChild.data) == "undefined"){
		//IE
		commentsNode.replaceChild( response ,commentsNode.firstChild ); 
		
	}else{
		//FF
		commentsNode.removeChild(commentsNode.firstChild);
		commentsNode.replaceChild( response ,commentsNode.firstChild );
	}	
	document.getElementById('commentTxt').value = '';
	document.getElementById('btCancel').style.display = 'inline';
	toggleCommentArea();
	listCommentsJS1();
}

function sendValidateComment(id,hl){
	var comment = document.getElementById('commentTxt').value;	
	var url = 'index.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','CommentAction');
	XHR.appendDataWithEscapeValue('action','addComment');
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('comment',comment);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.sendAndLoad(url, "POST",validateCommentsResponseCallback);
}

function sendCancelComment(){
	document.getElementById('commentTxt').value = '';
	toggleCommentArea();
}

function sendAbuse(widgetId,userId,step){
	var url = 'index.html';
	var XHR = new XHRConnection();
	XHR.appendDataWithEscapeValue('module','WidgetAction');
	XHR.appendDataWithEscapeValue('action','popUpAbuse');
	XHR.appendDataWithEscapeValue('step',step);
	XHR.appendDataWithEscapeValue('id',widgetId);
	if(userId!='') {
		XHR.appendDataWithEscapeValue('userid',userId);
	}
	XHR.sendAndLoad(url, "POST" ,popupResponseCallback);
}

function recommend(widgetId,userId,step,hl){
	var url = 'index.html';
	var XHR = new XHRConnection();
	XHR.appendDataWithEscapeValue('module','WidgetAction');
	XHR.appendDataWithEscapeValue('action','popUpRecommend');
	XHR.appendDataWithEscapeValue('step',step);
	XHR.appendDataWithEscapeValue('id',widgetId);
	XHR.appendDataWithEscapeValue('hl',hl);
	if(step==2){
		XHR.appendDataWithEscapeValue('from',document.getElementById("from").value);
		XHR.appendDataWithEscapeValue('to',document.getElementById("to").value);
		XHR.appendDataWithEscapeValue('message',document.getElementById("message").value);
	}
	if(userId!='') {
		XHR.appendDataWithEscapeValue('userid',userId);
	}
	XHR.sendAndLoad(url, "POST" ,popupResponseCallbackRecommend);
}

function popupResponseCallbackRecommend(conn)
{
	var popup=document.getElementById("popup");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup');
	limit(document.getElementById("message"));
}


function popupResponseCallback(conn)
{
	var popup=document.getElementById("popup");
	var response = fromHTML(conn.responseText);
	if(typeof(popup.firstChild.data) == "undefined"){
		//IE
		popup.replaceChild( response ,popup.firstChild );
		
	}else{
		//FF
		popup.removeChild(popup.firstChild);
		popup.replaceChild( response ,popup.firstChild );
	}
	displayPopUp('popup');
}

function sendManageWidget(id, hl, title, shortTitle, exactPlatform){
	var url = 'admin_PopupManageWidget.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.appendData('title',title);
	XHR.appendDataWithEscapeValue('shortTitle',shortTitle);
	XHR.appendDataWithEscapeValue('exactPlatform',exactPlatform);
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function manageFeaturedDatePickerDisplay(){
	if(document.getElementById('featured').checked){
		document.getElementById('featuredDate').style.visibility = "visible";
	}
	else {
		document.getElementById('featuredDate').style.visibility = "hidden";
	}
}

function manageSponsoredDatePickerDisplay(){
	if(document.getElementById('sponsored').checked){
		document.getElementById('sponsoredDate').style.visibility = "visible";
	}
	else {
		document.getElementById('sponsoredDate').style.visibility = "hidden";
	}
}

function manageOtherDatePickerDisplay(){
	if(document.getElementById('other').checked){
		document.getElementById('otherDate').style.visibility = "visible";
	}
	else {
		document.getElementById('otherDate').style.visibility = "hidden";
	}
}


function transformDate(date,hl) {
	if(hl == 'fr') {
		var dateArrayFr = date.split("/");
		var dateIntFr = "";
		if(dateArrayFr.length != 3 || isNaN(parseInt(dateArrayFr[2])) || isNaN(parseInt(dateArrayFr[1])) || isNaN(parseInt(dateArrayFr[0]))) {
			return "false";
		}
		dateIntFr = dateArrayFr[2] + dateArrayFr[1] + dateArrayFr[0]; 
		
		return dateIntFr;
		
	} else {
		var dateArray = date.split("/");
		var dateInt = "";
		if(dateArray.length != 3 || isNaN(parseInt(dateArray[2])) || isNaN(parseInt(dateArray[1])) || isNaN(parseInt(dateArray[0]))) {
			return "false";
		}
		dateInt = dateArray[2] + dateArray[0] + dateArray[1]; 
		return dateInt;
	}
}



function sendWidgetConfiguration(id)
{
	var isFeaturedOffer = document.getElementById('featured').checked;
	var isSponsoredOffer = document.getElementById('sponsored').checked;
	var isOtherOffer = document.getElementById('other').checked;
	
	var featuredBeginDate = document.getElementById('startDateFeatured').value;
	var featuredEndDate = document.getElementById('stopDateFeatured').value;
	var sponsoredBeginDate = document.getElementById('startDateSponsored').value;
	var sponsoredEndDate = document.getElementById('stopDateSponsored').value;
	var otherBeginDate = document.getElementById('startDateOther').value;
	var otherEndDate = document.getElementById('stopDateOther').value;
	
	var start = "";
	var stop = "";
	var hl = document.getElementById('hl').value;
	
	if(isSponsoredOffer) {
		if(sponsoredBeginDate.length != 0) {
			start = transformDate (sponsoredBeginDate,hl);
			if(start == "false") {
				alert("Sponsored widget offer : wrong start date format");
				return;
			}
		} else {
			alert("Sponsored widget offer : " + missingStartDate);
			return;
		}
		
		if(sponsoredEndDate.length != 0) {
			stop = transformDate (sponsoredEndDate,hl);
			if(stop == "false") {
				alert("Sponsored widget offer : wrong stop date format");
				return;
			}
			if (parseInt(stop, 10) < parseInt(start, 10)) {
				alert("Sponsored widget offer : " + startDateAfterStopDate);
				return;
			}
		}
	}
	
	start = "";
	stop = "";
	
	if(isFeaturedOffer) {
		if(featuredBeginDate.length != 0) {
			start = transformDate (featuredBeginDate,hl);
			if(start == "false") {
				alert("Featured widget offer : wrong start date format");
				return;
			}
		} else {
			alert("Featured widget offer : " + missingStartDate);
			return;
		}
		
		if(featuredEndDate.length != 0) {
			stop = transformDate (featuredEndDate,hl);
			if(stop == "false") {
				alert("Featured widget offer : wrong stop date format");
				return;
			}
			if (parseInt(stop, 10) < parseInt(start, 10)) {
				alert("Featured widget offer : " + startDateAfterStopDate);
				return;
			}
		}
	}

	start = "";
	stop = "";
	
	if(isOtherOffer) {
		if(otherBeginDate.length != 0) {
			start = transformDate (otherBeginDate,hl);
			if(start == "false") {
				alert("Other offer : wrong start date format");
				return;
			}
		} else {
			alert("Other offer : " + missingStartDate);
			return;
		}
		
		if(otherEndDate.length != 0) {
			stop = transformDate (otherEndDate,hl);
			if(stop == "false") {
				alert("Other offer : wrong stop date format");
				return;
			}
			if (parseInt(stop, 10) < parseInt(start, 10)) {
				alert("Other offer : " + startDateAfterStopDate);
				return;
			}
		}
	}

	var url = 'admin_popupManageWidget.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module', 'AdminWidgetAction');
	XHR.appendDataWithEscapeValue('featured', isFeaturedOffer);
	XHR.appendDataWithEscapeValue('sponsored', isSponsoredOffer);
	XHR.appendDataWithEscapeValue('other', isOtherOffer);
	XHR.appendDataWithEscapeValue('featuredStartDate', featuredBeginDate);
	XHR.appendDataWithEscapeValue('featuredStopDate', featuredEndDate);
	XHR.appendDataWithEscapeValue('sponsoredStartDate', sponsoredBeginDate);
	XHR.appendDataWithEscapeValue('sponsoredStopDate', sponsoredEndDate);
	XHR.appendDataWithEscapeValue('otherStartDate', otherBeginDate);
	XHR.appendDataWithEscapeValue('otherStopDate', otherEndDate);
	XHR.appendDataWithEscapeValue('hl', hl);
	XHR.appendDataWithEscapeValue('action', 'configureWidgetOffer');
	XHR.appendDataWithEscapeValue('id', id);
	XHR.sendAndLoad(url, "POST", refreshPage);
	closePopup();
}

var refreshPage = function (obj) {
	window.location.reload(true);
};


function drawRating(pos, img){
	for(i=1; i<=pos; i++){
		document.getElementById('rate' + i).src = 'img/rating/' + img + '.png';
	}
}

function drawCurrentRatedPanel(ratingAverage, ratingCount) {
	if (ratingCount != 0) {
		var htmlCode = '';
		htmlCode = drawBar(parseFloat(ratingAverage,10));
		htmlCode += '(' + ratingCount + ')';
		document.getElementById("currentRatedPanel").innerHTML = htmlCode;
	}
}

function manageRatingDisplay(r) {
	var rating = parseFloat(r,10);
	if (rating  == -1) { // non rated case
	}
	else {
		elt = document.getElementById("ratingPanel");
		if( elt != null)elt.innerHTML = drawBar(rating);
	}
}

function drawBar(r) {
	var nbFullStars = Math.round(parseFloat(r,10));
	var nbEmptyStars = 5-nbFullStars;
	var imgFullStar = '<img alt="star" src="img/rating/LargeStarFull.png">';
	var imgEmptyStar = '<img alt="star" src="img/rating/LargeStarEmpty.png">';
	
	var htmlCode = "<span>";
	if (nbFullStars>=1){
		for (i=1; i<=nbFullStars; i++) {
			htmlCode+=imgFullStar;
		}
	}
	if (nbEmptyStars>=1){
		for (i=1; i<=nbEmptyStars; i++) {
			htmlCode+=imgEmptyStar;
		}
	}
	htmlCode += "</span>";
	return htmlCode;
}


function rateIt(rating, widgetId, ratingAverage, ratingCount) {
	url = 'index.html';
	var XHR = new XHRConnection();
	XHR.appendDataWithEscapeValue('module', 'ManageWidgetRatingAction');
	XHR.appendDataWithEscapeValue('action', 'rateWidget');
	XHR.appendDataWithEscapeValue('rating', rating);
	XHR.appendDataWithEscapeValue('id',widgetId);
	XHR.sendAndLoad(url, "POST");
	var newRating = (parseFloat(ratingAverage,10) * parseFloat(ratingCount,10) + parseFloat(rating,10)) / (parseFloat(ratingCount,10) + 1);
	drawCurrentRatedPanel(newRating, parseFloat(ratingCount,10) + 1);
	manageRatingDisplay(rating);
	return true;
}


function sendResetAbuseCount(id, hl, iswidgetabuse){
	var url = 'admin_PopupResetAbuseCount.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.appendDataWithEscapeValue('iswidgetabuse',iswidgetabuse);
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}


function sendResetWidgetAbusecountConfirmation(id,hl,iswidgetabuse){
	var url = 'admin_adminAbuse.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.appendDataWithEscapeValue('module','AdminWidgetAction');
	XHR.appendDataWithEscapeValue('action','resetAbuseCount');
	XHR.appendDataWithEscapeValue('id',id);
	XHR.appendDataWithEscapeValue('hl',hl);
	XHR.appendDataWithEscapeValue('iswidgetabuse', iswidgetabuse);
	XHR.sendAndLoad(url, "POST" ,refreshPage);
	closePopup();
	return true;
}

function sendDeleteCommentListConfirmation(cid){
	var url = 'admin_PopupDeleteCommentList.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('commentId',cid);
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function searchComment()
{
	document.getElementById('form').submit();
}

function sendDeletePartner(pid){
	var url = 'admin_PopupDeletePartner.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('partnerId',pid);
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function sendAddPartner(){
	var url = 'admin_PopupAddPartner.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}

function sendPartnerAdd(){
	var partnerName = document.getElementById('partnerNameNew').value;
	var partnerUrl = document.getElementById('partnerUrlNew').value;
	var hl = document.getElementById('hl').value;
	
	if ( ( partnerName == null ) || ( trim(partnerName) == "" ) )
	{
		alert('The name of the partner must not be empty');
		return;
	}
	
	if ( ( partnerUrl == null ) || ( trim(partnerUrl) == "" ) )
	{
		alert('The url of the partner must not be empty');
		return;
	}
	
	partnerName = trim( partnerName );
	partnerUrl = trim( partnerUrl );
	
	if ( partnerName.length > 255 )
	{
		alert('The name of the partner cannot exceed 255 characters');
		return;
	}
	
	var url = 'admin_PopupAddPartner.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module', 'AdminPartnerAction');
	XHR.appendDataWithEscapeValue('partnerName', partnerName);
	XHR.appendDataWithEscapeValue('partnerUrl', partnerUrl);
	XHR.appendDataWithEscapeValue('hl', hl);
	XHR.appendDataWithEscapeValue('action', 'addPartner');
	XHR.sendAndLoad(url, "POST", refreshPage);
	closePopup();
}

function sendModifPartner(id, name, purl){
	var url = 'admin_PopupModifPartner.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('partnerId',id);
	XHR.appendDataWithEscapeValue('partnerName',name);
	XHR.appendDataWithEscapeValue('partnerUrl',purl);
	XHR.appendDataWithEscapeValue('confirm','ok');
	XHR.sendAndLoad(url, "POST",popupResponseCallback);
}


function sendPartnerModif(id){
	var partnerName = document.getElementById('partnerNameNew').value;
	var partnerUrl = document.getElementById('partnerUrlNew').value;
	var hl = document.getElementById('hl').value;
	
	
	if ( ( partnerName == null ) || ( trim(partnerName) == "" ) )
	{
		alert('The name of the partner must not be empty');
		return;
	}
	
	if ( ( partnerUrl == null ) || ( trim(partnerUrl) == "" ) )
	{
		alert('The url of the partner must not be empty');
		return;
	}
	
	partnerName = trim( partnerName );
	partnerUrl = trim( partnerUrl );
	
	if ( partnerName.length > 255 )
	{
		alert('The name of the partner cannot exceed 255 characters');
		return;
	}
	
	var url = 'admin_PopupModifPartner.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module', 'AdminPartnerAction');
	XHR.appendDataWithEscapeValue('partnerName', partnerName);
	XHR.appendDataWithEscapeValue('partnerUrl', partnerUrl);
	XHR.appendDataWithEscapeValue('hl', hl);
	XHR.appendDataWithEscapeValue('action', 'updatePartner');
	XHR.appendDataWithEscapeValue('id', id);
	XHR.sendAndLoad(url, "POST", refreshPage);
}

function trim(aString) 
{
	var regExpBeginning = /^\s+/;
	var regExpEnd = /\s+$/;  
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}


function resetOtherTitleItems(idName) {
	if(idName != "nameTitle") {
		document.getElementById("nameTitle").className = "purchaseHistoryTableHeader";
		document.getElementById("nameImg").style.display = "none";
	} 
	if(idName != "categoryTitle") {
		document.getElementById("categoryTitle").className = "purchaseHistoryTableHeader";
		document.getElementById("categoryImg").style.display = "none";
	} 
	if(idName != "typeTitle") {
		document.getElementById("typeTitle").className = "purchaseHistoryTableHeader";
		document.getElementById("typeImg").style.display = "none";
	}
	if(idName != "dateTitle") {
		document.getElementById("dateTitle").className = "purchaseHistoryTableHeader";
		document.getElementById("dateImg").style.display = "none";
	}
	if(idName != "priceTitle") {
		document.getElementById("priceTitle").className = "purchaseHistoryTableHeader";
		document.getElementById("priceImg").style.display = "none";
	}
}

function sortSelect(selectedValue){	
	var elt = document.getElementById('o');
	if(selectedValue == '4') elt.value = 1;
	else elt.value = 0;	
}

function getIndexUrl (p_url) {
	var regex = new RegExp("(.*)/.*");
	var qs = regex.exec(p_url);	
	return qs[1]+'/';
}



function compatibleBrandsModelsForBrand(elt) {	
	var value = elt.options[elt.selectedIndex].value;
	var url = 'partner/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','BusinessAction');
	XHR.appendDataWithEscapeValue('action','getMobileModelsForBrand');
	XHR.appendDataWithEscapeValue('brandId',value);
	
	XHR.sendAndLoad(url, "POST",compatibleBrandsModelsForBrandCallback);
}

function compatibleBrandsModelsForBrandCallback(conn) {
	
	var synchroStatusDiv=document.getElementById("modelListId");
	
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	document.getElementById('generic').style.display='block';
	document.getElementById('versionOk').style.display='none';
}

function modelFound(elt) {
	
	var value = elt.options[elt.selectedIndex].value;
	
	if(value != ""){	
		document.getElementById('generic').style.display='none';
		document.getElementById('versionOk').style.display='block';
	}else{
		document.getElementById('generic').style.display='block';
		document.getElementById('versionOk').style.display='none';
	}
}

function showPreviewType(viewtype) {
	if(viewtype == "mobile") {
		document.getElementById('mobileTab').style.display = "block";
		document.getElementById('pcmacTab').style.display = "none";
		document.getElementById('mobileEmulator').width = "190";
		document.getElementById('mobileEmulator').height = "322";
		document.getElementById('pcmacEmulator').width = "1";
		document.getElementById('pcmacEmulator').height = "1";
	} else {
		document.getElementById('pcmacTab').style.display = "block";
		document.getElementById('mobileTab').style.display = "none";
		document.getElementById('mobileEmulator').width = "1";
		document.getElementById('mobileEmulator').height = "1";
		document.getElementById('pcmacEmulator').width = "261";
		document.getElementById('pcmacEmulator').height = "395";
			
	}
}

function limiter()
{
	var textareas = document.getElementsByTagName('textarea');
 
	for(var i = 0; i < textareas.length; i++)
	{
		var textarea = textareas.item(i);
		limit(textarea);
	}
}
 
function limit(sender)
{
	var maxlength = sender.getAttribute('maxlength');
	if (maxlength != null)
	{
		// limit input values
		sender.onkeypress = function(e)
		{					
			// Crossbrowser Issue 
			if (e == null)
				e = window.event;
 
			// exclude certain keys from our limiter
			if ((e.keyCode == 8) || 
				(e.keyCode > 36) && 
				(e.keyCode < 41)) return true;
 
			return (sender.value.length < maxlength);
		};
 
		// limit pasted values
		sender.onpaste = function()
		{
			// onAfterPaste
			setTimeout(function()
			{
				if(sender.value.length > maxlength) {
					sender.value = sender.value.substring(0, maxlength);
				}							
			}, 1);
		};
	}
}
 
// Only Attach events needed for limiting the textareas once the page finished loading
if (window.addEventListener) { // FF etc
	window.addEventListener('load', limiter, false);
}
else{ // IE
	window.attachEvent('onload', limiter);
}

function changeSortOrder(){
	var order = document.getElementById("sortOrder").value;
	if(order == "1"){
		document.getElementById("sortOrder").value = 0;
	}else{
		document.getElementById("sortOrder").value = 1;
	}
	globalSearch();
}


function reloadCaptcha(imageId){
	var now = new Date();
	document.getElementById(imageId).src = document.getElementById(imageId).src+'?'+now.getTime();
}

function showCalendar(cal,divName,inputName,anchorName) {
	cal = new CalendarPopup(divName);
	cal.showYearNavigation();
	cal.setCssPrefix('CAL');
	
	if(document.getElementById('hl').value=="fr"){
	 	cal.setWeekStartDay(1);
	 	cal.setTodayText("Aujourd'hui");
		cal.select(document.getElementById(inputName),anchorName,'MM/dd/yyyy');
		cal.monthNames = new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre");
		cal.monthAbbreviations = new Array("Jan","Fév","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Déc");
		cal.dayHeaders = new Array("D","L","M","M","J","V","S");
		cal.select(document.getElementById(inputName),anchorName,'dd/MM/yyyy');
	}else{
		cal.select(document.getElementById(inputName),anchorName,'MM/dd/yyyy');
	}
	
	document.getElementById(divName).style.top="";
	document.getElementById(divName).style.left="";
	
	return false;
}

function galleryConfirmNSRU(confirm){
	if(document.getElementById('advertiseDivFlash') != null) { 
		document.getElementById('advertiseDivFlash').style.visibility='hidden';
	}
	
	confirmNSRU(confirm);
	
	if((elt = document.getElementById('close')) != null){
		var oldEvent = (elt.onclick) ? elt.onclick : function () {};
		elt.onclick = function(){
			oldEvent();
		    if(document.getElementById('advertiseDivFlash') != null) {
		    	document.getElementById('advertiseDivFlash').style.visibility='visible';
		    }
		}
	}
}	

function galleryConfirm(){
	if(document.getElementById('advertiseDivFlash') != null) { 
		document.getElementById('advertiseDivFlash').style.visibility='hidden';
	}

	if((elt = document.getElementById('close')) != null){
		var oldEvent = (elt.onclick) ? elt.onclick : function () {};
		elt.onclick = function(){
			oldEvent();
		    if(document.getElementById('advertiseDivFlash') != null) {
		    	document.getElementById('advertiseDivFlash').style.visibility='visible';
		    }
		}
	}
}

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

/************************ SETUP FUNCTIONS *******************************************/

function refreshPurchaseHistoryList(conn) {
	var synchroStatusDiv=document.getElementById("purchaseHistoryTableContent");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
}

function repositoryTopMenuChangePlatform(idName,idImg) {	
	if(document.getElementById('setupWidgetDetail') == null && document.getElementById(idName).className == "widgetRepositoryTopMenuSelectedItem") return; 
	document.getElementById(idName).style.cursor=null;
	repositoryResetTopMenuItems(idName);
	
	document.getElementById(idName).className = "widgetRepositoryTopMenuSelectedItem";
	var imgSrc;
	if(idName == "mobileTopMenuItem") {
		imgSrc = "img/setup/platformIcons/mobileSelect.png";
		document.getElementById("containerType").value="mobile";
		showMobileList();
	} else if(idName == "pcmacTopMenuItem") {
		imgSrc = "img/setup/platformIcons/pcmacSelect.png";
		document.getElementById("containerType").value="pcmac";
		showPcMacContent();
	} else if(idName == "tvTopMenuItem") {
		imgSrc = "img/setup/platformIcons/tvSelect.png";
	} else if(idName == "trashTopMenuItem") {
		imgSrc = "img/setup/platformIcons/trashSelect.png";
		document.getElementById("containerType").value="trash";
		showTrashContent();
	}
	
	document.getElementById(idImg).src = imgSrc;
}

function repositoryResetTopMenuItems(idName) {
	if(idName != "mobileTopMenuItem") {
		document.getElementById("mobileTopMenuItem").className = "widgetRepositoryTopMenuUnselectedItem";
		document.getElementById("mobileImg").src = "img/setup/platformIcons/mobileUnselect.png";
	} 
	if(idName != "pcmacTopMenuItem") {
		document.getElementById("pcmacTopMenuItem").className = "widgetRepositoryTopMenuUnselectedItem";
		document.getElementById("pcmacImg").src = "img/setup/platformIcons/pcmacUnselect.png";
	} 
	/*if(idName != "tvTopMenuItem") {
		document.getElementById("tvTopMenuItem").className = "widgetRepositoryTopMenuUnselectedItem";
		document.getElementById("tvImg").src = "img/setup/platformIcons/tvInactive.png";
	}*/
	if(idName != "trashTopMenuItem") {
		document.getElementById("trashTopMenuItem").className = "widgetRepositoryTopMenuUnselectedItem";
		document.getElementById("trashImg").src = "img/setup/platformIcons/trashUnselect.png";
	}
}

function showPcMacContent() {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showPcMacContent');
	elt = document.getElementById("sortByInput");	
	XHR.appendDataWithEscapeValue('sortBy',elt.options[elt.selectedIndex].value);	
	XHR.sendAndLoad(url, "POST",showPcMacContentCallback);
}

function showPcMacContentCallback(conn) {
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	myRepositoryLargescroller = new jsScroller(document.getElementById("myRepositoryLarge"), 20, 130,"myRepositoryLargeScroller-Container");
	myRepositoryLargescrollbar = new jsScrollbar (document.getElementById("myRepositoryLargeScrollbar-Container"), myRepositoryLargescroller, true, scrollbarEvent,"myRepositoryLargeScrollbar-Up","myRepositoryLargeScrollbar-Down","myRepositoryLargeScrollbar-Track","myRepositoryLargeScrollbar-Handle"); 
}

function showMobileList() {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showMobileContent');
	elt = document.getElementById("sortByInput");	
	XHR.appendDataWithEscapeValue('sortBy',elt.options[elt.selectedIndex].value);
	XHR.sendAndLoad(url, "POST",showMobileContentCallback);
}

function showMobileContentCallback(conn) {
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	myRepositoryscroller = new jsScroller(document.getElementById("myRepository"), 20, 130,"myRepositoryScroller-Container");
	myRepositoryscrollbar = new jsScrollbar (document.getElementById("myRepositoryScrollbar-Container"), myRepositoryscroller, true, scrollbarEvent,"myRepositoryScrollbar-Up","myRepositoryScrollbar-Down","myRepositoryScrollbar-Track","myRepositoryScrollbar-Handle");
	purchaseHistoryJS1PostProcess(); 
}

function showTrashContent() {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showTrashContent');
	elt = document.getElementById("sortByInput");	
	XHR.appendDataWithEscapeValue('sortBy',elt.options[elt.selectedIndex].value);
	XHR.sendAndLoad(url, "POST",showTrashContentCallback);
}

function showTrashContentCallback(conn) {
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	
	myRepositoryLargescroller = new jsScroller(document.getElementById("myRepositoryLarge"), 20, 130,"myRepositoryLargeScroller-Container");
	myRepositoryLargescrollbar = new jsScrollbar (document.getElementById("myRepositoryLargeScrollbar-Container"), myRepositoryLargescroller, true, scrollbarEvent,"myRepositoryLargeScrollbar-Up","myRepositoryLargeScrollbar-Down","myRepositoryLargeScrollbar-Track","myRepositoryLargeScrollbar-Handle"); 
}

function showDeleteWidgetPopUp(containerid,widgetInstanceId,widgettype) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showDeleteWidget');
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.appendDataWithEscapeValue('widgettype',widgettype);
	XHR.appendDataWithEscapeValue('containerid',containerid);
	XHR.sendAndLoad(url, "POST",displayDeleteWidgetPopUp);
}

function displayDeleteWidgetPopUp(conn) {
	var synchroStatusDiv=document.getElementById("setupPopUp");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	displayPopUp("setupPopUp");
}

function deleteWidgetMobileCallback(conn) {
	hidePopUp("setupPopUp");

	var synchroStatusDiv=document.getElementById("myRepositoryWidgetList");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}	
}

function deleteWidgetPcMacCallback(conn) {
	hidePopUp("setupPopUp");

	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}	
}

function deleteWidget(containerid,widgetInstanceId,widgettype) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','deleteWidget');
	XHR.appendDataWithEscapeValue('containerid',containerid);
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.appendDataWithEscapeValue('widgettype',widgettype);
	
	if(widgettype=="mobile") {
		XHR.sendAndLoad(url, "POST",deleteWidgetMobileCallback);
	} else {
		XHR.sendAndLoad(url, "POST",deleteWidgetPcMacCallback);
	}
}

function showDeleteWidgetDefinitelyPopUp(containerid,widgetInstanceId) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showDeleteWidgetDefinitely');
	XHR.appendDataWithEscapeValue('containerid',containerid);
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.sendAndLoad(url, "POST",showDeleteWidgetDefinitelyCallBack);
}

function showDeleteWidgetDefinitelyCallBack(conn) {
	var synchroStatusDiv=document.getElementById("setupPopUp");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	displayPopUp("setupPopUp");
}

function deleteDefinitelyWidget(containerid,widgetInstanceId) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','deleteWidgetDefinitely');
	XHR.appendDataWithEscapeValue('containerid',containerid);
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.sendAndLoad(url, "POST",deleteDefinitelyWidgetCallBack);
}

function deleteDefinitelyWidgetCallBack(conn) {
	hidePopUp("setupPopUp");
	
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
}

function showRestoreWidgetPopUp(containerId,widgetInstanceId,widgetType) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showRestoreWidget');
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.appendDataWithEscapeValue('containerid',containerId);
	XHR.appendDataWithEscapeValue('widgettype',widgetType);
	XHR.sendAndLoad(url, "POST",displayRestoreWidgetPopUp);
}

function displayRestoreWidgetPopUp(conn) {
	var synchroStatusDiv=document.getElementById("setupPopUp");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	displayPopUp("setupPopUp");
}

function restoreWidget(containerId,widgetInstanceId,widgetType) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','restoreWidget');
	XHR.appendDataWithEscapeValue('widgetinstanceid',widgetInstanceId);
	XHR.appendDataWithEscapeValue('containerid',containerId);
	XHR.appendDataWithEscapeValue('widgettype',widgetType);
	XHR.sendAndLoad(url, "POST",restoreWidgetCallback);
}

function restoreWidgetCallback(conn) {
	hidePopUp('setupPopUp');
	
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}else{
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
}

function showWidgetDetails(widgetClassId,isMobileWidget,hl) {
	var url = 'setup/action.html';
	var XHR = new XHRConnection();	
	XHR.appendDataWithEscapeValue('module','Setup');
	XHR.appendDataWithEscapeValue('action','showWidgetDetails');
	XHR.appendDataWithEscapeValue('widgetclassid',widgetClassId);
	XHR.appendDataWithEscapeValue('ismobilewidget',isMobileWidget);
	XHR.appendDataWithEscapeValue('hl',hl);
	if(isMobileWidget == true) {
		XHR.sendAndLoad(url, "POST",showMobileWidgetDetailsCallback);
	} else {
		XHR.sendAndLoad(url, "POST",showWidgetDetailsCallback);
	}
	document.getElementById('mobileTopMenuItem').style.cursor='pointer';
	document.getElementById('pcmacTopMenuItem').style.cursor='pointer';
	document.getElementById('trashTopMenuItem').style.cursor='pointer';
}

function showWidgetDetailsCallback(conn) {
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	} else {
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	
	var setupScreenshot1 = document.getElementById('setupScreenshot1');	
	if(setupScreenshot1 != null  && isImgComplete(setupScreenshot1)) {
		setTimeout("scaleImage(document.getElementById('setupScreenshot1'),true,300,230)",1000);
	}
	
	var setupScreenshot2 = document.getElementById('setupScreenshot2');
	if(setupScreenshot2 != null && isImgComplete(setupScreenshot2)) {
		setTimeout("scaleImage(document.getElementById('setupScreenshot2'),true,300,200)",1000);	
	}
	
	setupWidgetCommentsscroller = new jsScroller(document.getElementById("setupWidgetComments"), 0, 40,"setupWidgetCommentsScroller-Container");
	setupWidgetCommentsscrollbar = new jsScrollbar (document.getElementById("setupWidgetCommentsScrollbar-Container"), setupWidgetCommentsscroller, true, scrollbarEvent,"setupWidgetCommentsScrollbar-Up","setupWidgetCommentsScrollbar-Down","setupWidgetCommentsScrollbar-Track","setupWidgetCommentsScrollbar-Handle");
}

function showMobileWidgetDetailsCallback(conn) {
	var synchroStatusDiv=document.getElementById("myRepositoryWidgetAjax");
	var response = fromHTML(conn.responseText);
	if(typeof(synchroStatusDiv.firstChild.data) == "undefined"){
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	} else {
		synchroStatusDiv.removeChild(synchroStatusDiv.firstChild);
		synchroStatusDiv.replaceChild( response ,synchroStatusDiv.firstChild );
	}
	
	var setupScreenshot1 = document.getElementById('setupScreenshot1');	
	if(setupScreenshot1 != null  && isImgComplete(setupScreenshot1)) {
		setTimeout("scaleImage(document.getElementById('setupScreenshot1'),true,300,230)",1000);
	}
	
	var setupScreenshot2 = document.getElementById('setupScreenshot2');
	if(setupScreenshot2 != null && isImgComplete(setupScreenshot2)) {
		setTimeout("scaleImage(document.getElementById('setupScreenshot2'),true,300,200)",1000);	
	}
	
	setupWidgetCommentsscroller = new jsScroller(document.getElementById("setupWidgetComments"), 0, 40,"setupWidgetCommentsScroller-Container");
	setupWidgetCommentsscrollbar = new jsScrollbar (document.getElementById("setupWidgetCommentsScrollbar-Container"), setupWidgetCommentsscroller, true, scrollbarEvent,"setupWidgetCommentsScrollbar-Up","setupWidgetCommentsScrollbar-Down","setupWidgetCommentsScrollbar-Track","setupWidgetCommentsScrollbar-Handle");
}

function widgetDetailsBackAction() {
	if(document.getElementById("mobileTopMenuItem").className == "widgetRepositoryTopMenuSelectedItem") {
		document.getElementById("mobileTopMenuItem").style.cursor=null;
		showMobileList();
	} else if(document.getElementById("pcmacTopMenuItem").className == "widgetRepositoryTopMenuSelectedItem") {
		document.getElementById("pcmacTopMenuItem").style.cursor=null;
		showPcMacContent();
	} else if(document.getElementById("trashTopMenuItem").className == "widgetRepositoryTopMenuSelectedItem") {
		document.getElementById("trashTopMenuItem").style.cursor=null;
		showTrashContent();
	} else if(document.getElementById("tvTopMenuItem").className == "widgetRepositoryTopMenuSelectedItem") {
//		document.getElementById("tvTopMenuItem").style=null;
	}
}

function setupWidgetDetailChangeImage() {
	if(document.getElementById('screenshotSpan2').style.display == 'none') {
		document.getElementById('screenshotSpan1').style.display = 'none';
		document.getElementById('screenshotSpan2').style.display = 'block';
	} else {
		document.getElementById('screenshotSpan2').style.display = 'none';
		document.getElementById('screenshotSpan1').style.display = 'block';
	}
}

function setupWidgetDetailChangeImage(){
	if (document.getElementById('screenshotSpan2').style.display == 'none') {
		document.getElementById('screenshotSpan1').style.display = 'none';
		document.getElementById('screenshotSpan2').style.display = 'block';
	}
	else {
		document.getElementById('screenshotSpan2').style.display = 'none';
		document.getElementById('screenshotSpan1').style.display = 'block';
	}
}

function purchaseHistoryJS1PostProcess(){
	document.getElementById("widgetListTable").style.display="block";
}

function setupSortBy(){
	var containerType = document.getElementById("containerType").value;
	if(containerType == "mobile") showMobileList();
	else if(containerType == "pcmac") showPcMacContent();
	else if(containerType == "trash") showTrashContent();
}
