
function myReplace(sRemove,sAdd){var a = this.split(sRemove); return a.join(sAdd);}
String.prototype.replaceAll = myReplace;

////////////////////
var myFunction = new FFunction();
function FFunction(pLang){
	
	this.language			= "";
	this.PageCurentName		= "";
	this.PageCurentHref		= "";
	
	this.ActionSave			= "SAVE";
	this.ActionGenerate		= "GENERATE";
	this.ActionCut			= "MOVE";
	this.ActionDelete		= "DELETE";
	this.ActionCopy			= "COPY";
	this.ActionSelectAll	= "SELECTALL";
	this.ActionDeselectAll	= "DESELECTALL";
	this.ActionTargetDefine	= "TARGETDEFINE";
	this.ActionMoveToTarget	= "MOVETOTARGET";
	this.ActionCopyToTarget	= "COPYTOTARGET";
	this.ActionBack			= "JUMPTOTARGET";
	this.ActionCancel		= "CANCEL";
	this.FormActionDefault	= "";
	this.FormName			= "cmsFormControl";
	
	//method
	this.sendToFriend			= FF_sendToFriend;
	this.PageCurrentSet			= FF_PageCurrentSet;
	this.FormSubmit				= FF_FormSubmit;
	this.FormActionDefaultSet	= FF_FormActionDefaultSet;
	this.LanguageSet			= FF_LanguageSet;
	this.checkAll				= FF_checkAll;
	this.uncheckAll				= FF_uncheckAll;
	
}
function FF_checkAll(p_FormName,pChkName) {
	var strFormName = p_FormName || this.FormName;
	var strChkName = pChkName || "ItemID";
	
	FF_checked(true,strFormName,strChkName)
}

function FF_uncheckAll(p_FormName,pChkName) {
	var strFormName = p_FormName || this.FormName;
	var strChkName = pChkName || "ItemID";
	
	FF_checked(false,strFormName,strChkName)
}

function FF_checked(Check,pFormName,pChkName) {

	var len = document.forms[pFormName].length;
	for(var i=0 ; i<len ; i++)
		if (document.forms[pFormName].elements[i].name==pChkName)
			document.forms[pFormName].elements[i].checked=Check;
	bCheck = !Check
}

function FF_FormActionDefaultSet(pAction) {
	this.FormActionDefault = pAction;
}
function FF_LanguageSet(pAction) {
	this.language = pAction;
}

function FF_sendToFriend(p_strName, p_strHref) {
	var strName = p_strName || this.PageCurentName;
	var strHref = p_strHref || this.PageCurentHref;
	
	var imgUrlValidate = new Image();
	imgUrlValidate.src = strHref;
    popupMail('','','',strName,imgUrlValidate.src)
}

function FF_PageCurrentSet(p_strName, p_strHref){this.PageCurentName=p_strName; this.PageCurentHref=p_strHref;}

function FF_FormSubmit(pCMSAction,pFormAction,pFormTarget,pFormChange){
	var strCMSAction	= pCMSAction || "";
	var strFormAction	= pFormAction || "";
	var strFormTarget	= pFormTarget || "";
	var bFormChange	= pFormChange || false;
	
	var bPerform	= true;
	var strFormName	= this.FormName;
	
	if(bFormChange!=""){
		if(document.forms.length > 1){
			strFormName = document.forms[1].name;
			document.forms[strFormName].action = this.FormActionDefault;
		}
	}
	
	
	strCMSAction = strCMSAction.toUpperCase();
	switch(strCMSAction){
		case this.ActionDelete:
			bPerform = confirm(CLanguage(this.language).MsgEditDelete);
			break;
		case this.ActionDeselectAll:
			this.uncheckAll(strFormName);
			bPerform = false;
			break;
		case this.ActionSelectAll:
			this.checkAll(strFormName);
			bPerform = false;
			break;
		case this.ActionGenerate:
			if(!confirm(CLanguage(this.language).MsgEditGenerate)){
				strCMSAction = this.ActionSave;
			}
			break;
	}
	
	if(bPerform){
		if(strCMSAction!=""){
			if(strFormAction=="") strFormAction = document.forms[strFormName].action || "";
			
			if(strFormAction=="") strFormAction = this.FormActionDefault;
			
			var aFormAction = strFormAction.split("?");
			strFormAction = aFormAction[0] + "?" + "Action=" + strCMSAction + "&" + aFormAction[1];
		}
		if(document.forms[strFormName].onsubmit > "")
			document.forms[strFormName].onsubmit();
		
		if(strFormTarget!="") document.forms[strFormName].target = strFormTarget;
		if(strFormAction!="") document.forms[strFormName].action = strFormAction;
		
		document.forms[strFormName].submit();
	}
}
//////////////////////////

/*function inFrame(Href){
	parent.frames["frmContent"].location.href = Href;
}
		
function inFrameMulti(Href){
	parent.frames["frmContent"].location.href = "cmsContent.aspx" + Href;;
	parent.frames["frmNavigator"].location.href = "cmsNavigator.aspx" + Href;
}*/



function popupMail(p_strTo, p_strCc, p_strBcc, p_strSubject, p_strBody) {

    // BUILD MAIL MESSAGE COMPONENTS 
    var s = "?";
    var doc = "mailto:"
    if(p_strTo!="")	doc+= p_strTo;
    
    if(p_strCc!=""){
		doc+= s + "cc=" + p_strCc;
		s = "&";}
    if(p_strBcc!=""){
		doc+= s + "cc=" + p_strBcc;
		s = "&";}
	if(p_strSubject!=""){
		doc+= s + "subject=" + escape(p_strSubject);
		s = "&";}
	if(p_strBody!=""){
		doc+= s + "body=" + escape(p_strBody);
		s = "&";}

    // POP UP EMAIL MESSAGE WINDOW
    window.location = doc;
} 


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function encode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}

function decode(str) {
	return unescape(str.replace(/\+/g, " "));
}



var icoImg = new Array(0);
var icoImgKey = new Array(0);

function ImgCacheAdd(key,src){
	var i;
	for(i=0;i<icoImgKey.length;i++){
		if(icoImgKey[i] == key){
			return;
		}
	}
	
	icoImgKey[i] = key
	icoImg[i] = new Image();
	icoImg[i].src = src;
}

function over(name, key){
	var ImgKey;
	
	for(i=0;i<icoImgKey.length;i++){
		if(icoImgKey[i] == key){
			ImgKey = i;
		}
	}
	eval('document.images[name].src = icoImg[ImgKey].src')
}
function out(name, key){	
	var ImgKey;
	for(i=0;i<icoImgKey.length;i++){
		if(icoImgKey[i] == key){
			ImgKey = i;
		}
	}
	eval('document.images[name].src = icoImg[ImgKey].src')
}


function checkAll(p_sFormName,p_sChkName) {
	bCheck = true;
	SetChecked(p_sFormName,p_sChkName)
}
function uncheckAll(p_sFormName,p_sChkName) {
	bCheck = false;
	SetChecked(p_sFormName,p_sChkName)
}


var bCheck = true;
function SetChecked(p_sFormName,p_sChkName) {

	var len = document.forms[p_sFormName].length;
	for(var i=0 ; i<len ; i++)
		if (document.forms[p_sFormName].elements[i].name==p_sChkName)
			document.forms[p_sFormName].elements[i].checked=bCheck;
	bCheck = !bCheck
}

function ViewSort(p_sFormName, p_sInputName_SortFieldName, p_sSortFieldName, p_sInputName_Sort , p_sSort){
	document.forms[p_sFormName].elements[p_sInputName_SortFieldName].value = p_sSortFieldName;
	document.forms[p_sFormName].elements[p_sInputName_Sort].value = p_sSort;
	document.forms[p_sFormName].submit();
}

function Sort(p_sFormName, p_sInputName_SortFieldName, p_sSortFieldName, p_sInputName_Sort , p_sSort){
	ViewSort(p_sFormName, p_sInputName_SortFieldName, p_sSortFieldName, p_sInputName_Sort , p_sSort);
}

function FileManagement(ParentID,ID,Action,Option){
	var bSubmit = true;
	var sTarget = "_self";
	var sAction  = "cmsFileManagement.aspx?Action=" + Action + "&" + document.forms["LIST_" + ParentID].elements["cmsParameters"].value

	if(Action == "VIEWINBROWSER" || Action == "VIEWHISTORY") sTarget = "_new"
	
	if(Action == "DELETE")
		bSubmit = confirm("Voulez-vous vraiment detruire ce fichier?");
		
	if(Action == "NAVIGATE")
		document.forms["LIST_" + ParentID].elements["cmsFirst"].value = Option;
	
	if(Action == "GETVERSION")
		document.forms["LIST_" + ParentID].elements["cmsFileVersion"].value = Option;
	
	if(bSubmit){
		document.forms["LIST_" + ParentID].action = sAction
		document.forms["LIST_" + ParentID].target = sTarget
		document.forms["LIST_" + ParentID].elements["hidItemID"].value = ID;
		document.forms["LIST_" + ParentID].submit();
	}
}

function FormManage(ListID,First){
	document.forms["cmsFormControl"].elements["cmsListID"].value = ListID;
	document.forms["cmsFormControl"].elements["cmsFirst"].value = First;
	document.forms["cmsFormControl"].submit();
}

function FormControlManage(pPageAction,Action,pPageTarget){
	var strPageAction = pPageAction || "";
	var strPageTarget = pPageTarget || "";
	var  strFormName = "cmsFormControl";
	
	if(strPageTarget!="") document.forms[strFormName].action = strPageTarget;
	if(strPageTarget!="") document.forms[strFormName].target = strPageTarget;
	
	FormSubmit(strFormName,Action);
}



function WindowOpen(p_sAction, p_iWidth, p_iHeight,p_sParameters){
	var iWidth = Width || "450";
	var iHeight = Height || "550";
	
	//var sParameters = "";
	//if(p_sParameters!="") sParameters =  p_sParameters + ",Width=" + iWidth +  ",Height=" + iHeight;
	//if(sParameters=="") sParameters = "resizable=yes,toolbar=no,scrollbars=yes,status=no,Width=" + iWidth +  ",Height=" + iHeight;
	
	var sParameters =  "Width=" + iWidth +  ",Height=" + iHeight;
	
	var sWinName = "myNewWindow";
	var win = window.open(p_sAction, sWinName,sParameters);
	
	//win.moveTo((screen.availWidth - iWidth) / 2,(screen.availHeight - iHeight) / 2);
}

//get div
function F_DivGet(Key){
	if(is.ns) return document.layers[Key];
	else return document.all[Key].style;
}

// show and hide div
//function F_DivShow(Key){
//	if (is.ns) F_DivGet(Key).visibility = "show";
//	else if (is.ie) F_getDiv(Key).visibility = "visible";
//}
//
//function F_DivHide(Key){
//	if (is.ns) F_DivGet(Key).visibility = "hide"
//	else if (is.ie) F_getDiv(Key).visibility = "hidden"
//}

// show and hide div
//.offsetWidth
var iHeight = -1;
var iTop = -1;
var iLeft = -1;
var iRight = -1;
var iBottom = -1;
function update(Div){
	if (iTop = -1){
	iTop = Div.offsetTop;
	iLeft = Div.offsetLeft;
	iRight = iLeft + Div.offsetWidth;
	iBottom = iTop + Div.offsetHeight;
	}
}
function F_DivShow(Div){
	update(Div);
	
	if (is.ns) Div.visibility = "show";
	else if (is.ie) Div.style.visibility = "visible";
	
	F_clipTo(Div,iTop,iRight,iBottom,iLeft)
}

function F_DivHide(Div){
	update(Div);
	
	F_clipTo(Div,iTop,iRight,iTop + 1 ,iLeft)
	if (is.ns) Div.visibility = "hide"
	else if (is.ie)	Div.style.visibility = "hidden"
}

// BrowserCheck Object
function BrowserCheck() {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;
	this.version = navigator.appVersion;
	this.v = parseInt(this.version);
	this.ns = (this.b=="ns" && this.v>=4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns5 = (this.b=="ns" && this.v==5);
	this.ie = (this.b=="ie" && this.v>=4);
	this.ie4 = (this.version.indexOf('MSIE 4')>0);
	this.ie5 = (this.version.indexOf('MSIE 5')>0);
	this.min = (this.ns||this.ie);
}
is = new BrowserCheck();

function F_clipTo(Div,p_iTop,p_iRight,p_iBottom,p_iLeft)
{
	var oObject = Div.clip;
	
	if(is.ie)	//clip:rect(top,right,bottom,left)
		oObject = "rect(" + p_iTop + "px "+ p_iRight +"px " + p_iBottom + "px " + p_iLeft + "px)";
	else{
		oObject.top = p_iTop;
		oObject.right = p_iRight;
		oObject.bottom = p_iBottom;
		oObject.left = p_iLeft;
	}
}