function customWindowOpen(strUrl, strWindow, strParams, iWidth, iHeight)
{
	var
		iLeft, iTop;
	iLeft = (window.screen.width - iWidth) / 2;
	iTop = (window.screen.height - iHeight) / 2;
	strParams = strParams + ",width=" + iWidth.toString() + ",height=" + iHeight.toString() + ",left=" + iLeft.toString() + ",top=" + iTop.toString();
	window.open(strUrl, strWindow, strParams);
}

function CheckCookie (CookieName) {
	  var lf = "\n";
    var CookieString = document.cookie;
    var CookieSet = CookieString.split (';');
    var SetSize = CookieSet.length;
    var CookiePieces
    var ReturnValue = "";
    var x = 0;
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
      CookiePieces = CookieSet[x].split ('=');
      if (CookiePieces[0].substring (0,1) == ' ') {
        CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
      }
      if (CookiePieces[0] == CookieName) {
        ReturnValue = CookiePieces[1];
      }
     }
     //if(ReturnValue=="")
     //    alert('A cookie was not set. '+lf+'Please ensure that your browser is accepting cookies.');
     return ReturnValue;
 }


function ShowUserDetails(InPreFixPath){
		window.location= "/" + InPreFixPath + "/aspx_dir/UserDetails.aspx"
	}
	
function ChangePict(PicPath)
{
		PicId = window.event.srcElement.id
		window.document.all(PicId).src = PicPath
}

function GetStringLength(oString){
				var sTemp;
					//sTemp = stringTrim(oString);
					sTemp = oString;
					sTemp = sTemp.replace(/<p>/gi,"");
					sTemp = sTemp.replace(/<\/p>/gi,"");
					sTemp = sTemp.replace(/<P>/gi,"");
					sTemp = sTemp.replace(/<\/P>/gi,"");
					sTemp = sTemp.replace(/&nbsp;/gi,"");
					sTemp = sTemp.replace(/&NBSP;/gi,"");
					sTemp = sTemp.replace(/<br>/gi,"");
					sTemp = sTemp.replace(/<BR>/gi,"");
					sTemp = sTemp.replace(/ /gi,"");
					sTemp = sTemp.replace(/\/n/gi,""); 
					sTemp = sTemp.replace(/\s+/gi,"");
					
					sTemp = sTemp.replace(/"/gi,"");
					sTemp = sTemp.replace(/<FONTstyle=BACKGROUND-COLOR:#cecf9c>/gi,"");
					sTemp = sTemp.replace(/<\/FONT>/gi,"");
				return sTemp;
			}
			
			
		function stringLeftTrim(s) {
	       return (typeof(s) != "string") ? null : s.replace(/^ +/, "");
	    }

	    // remove trailing spaces
	    function stringRightTrim(s) {
	       return (typeof(s) != "string") ? null : s.replace(/ +$/, "");
	    }

	    // remove leading and trailing spaces
	    function stringTrim(s) {
	       return stringRightTrim(stringLeftTrim(s));
	    }
	    // Select how to open the window
	    function openWin ( pUrl, pType){
				var iWindowHeight = 500 ;
				var iWindowWidth = 700 ;
				var iWidth = window.screen.width ;
				var iHeight = window.screen.height ;
				iWidth = (iWidth -iWindowWidth) / 2 ;
				iHeight = (iHeight - iWindowHeight ) / 2  ;
			if (pType == "Media"){
			
					eval("window.open(pUrl,'','left=" + iWidth + ",top=" + iHeight + ",width=" + iWindowWidth + ",height=" + iWindowHeight + ",scrollbars=yes,resizable=no,modal=yes');");
					return;
			}
			else{
				return;
			}
	    }//end
	    
	    function EnlargeImageWindow(imageURL,doReturn){
				//window.open(imageURL);
				//return false;
				//alert('imageURL=' + imageURL);
				var iWindowHeight = 500 ;
				var iWindowWidth = 500 ;
				var iWidth = window.screen.width ;
				var iHeight = window.screen.height ;
				iWidth = (iWidth -iWindowWidth) / 2 ;
				iHeight = (iHeight - iWindowHeight ) / 2  ;
				eval("window.open(imageURL,'Image','left=" + iWidth + ",top=" + iHeight + ",width=" + iWindowWidth + ",height=" + iWindowHeight + ",scrollbars=yes,resizable=yes,modal=yes,toolbar=no');");
				if (doReturn)
					return false;
			}
			
	    // Open the Credit Page

	  function SelectLink(strOBJ){
	
		obj = document.getElementById(strOBJ);
	
		var strHref
		var strTitle=''; 
		var strTarget='';
		var strName='';
		
		if (obj.value!=""){
			var LinkAttributesArray = obj.value.split(';');
			strHref = LinkAttributesArray[0];
			strTitle=LinkAttributesArray[1];
			strTarget=LinkAttributesArray[2];
			strName=LinkAttributesArray[3];
		}
		else
			strHref = "http:\/\/";		
		
		
		var args = strHref + ";" + strTitle + ";" + strTarget + ";" + strName;
		var strDlgRet = window.showModalDialog("/MFA/CMS/WebAuthor/Dialogs/HLink/Hlink.aspx",args,"dialogWidth:700px;dialogHeight:365px;status:no;help:no");	

		if (typeof(strDlgRet) == "undefined")
					return false;
				if (strDlgRet == "Cancel")
					return false;
				if ( strDlgRet != "")
					obj.value=strDlgRet;
	}  
	
//*******************************************************************************
//		Place Holder's Validations functions
//
//      if param named PH_DoValidation=false - the validation won't work !!!
//
//*******************************************************************************
var PH_DoValidation=false;
var WindowPrint=false;

var intArrayLength=7;
var oVldSum;
var oArray=new Array(intArrayLength)
BuildErrorDescriptionArray()
			
function BuildErrorDescriptionArray(){

		for (i=0; i <= intArrayLength; i++) {   
			oArray[i] = new Array(2)
		}

		//elements in page
		oArray[0][0]=["NCPHRICH_PH_REQ_TITLE"];
		oArray[0][1]=["You must fill a title marked as required"];
		oArray[1][0]=["NCPHRICH_PH_REQ_TEXT"];
		oArray[1][1]=["You must fill text marked as required"];
		oArray[2][0]=["NCPH_PH_REQ_IMAGE"];
		oArray[2][1]=["You must fill image marked as required"];
		oArray[3][0]=["PH_REQ_DATE_AuthoringModeControlsContainer__ctl0_cal_date"];
		oArray[3][1]=["You must fill date marked as required"];
		//elements in HP
		oArray[4][0]=["NCPHRICH_PH_REQ_HP_TITLE"];
		oArray[4][1]=["You must fill home page title marked as required"];
		oArray[5][0]=["NCPHRICH_PH_REQ_HP_TEXT"];
		oArray[5][1]=["You must fill home page text marked as required"];
		oArray[6][0]=["NCPH_PH_REQ_HP_IMAGE"];
		oArray[6][1]=["You must fill home page image marked as required"];
		oArray[7][0]=["PH_REQ_HP_DATE_AuthoringModeControlsContainer__ctl0_cal_date"];
		oArray[7][1]=["You must fill homepage date marked as required"];
}

function GetErrorDesctiption(strKey){
	for (i=0; i <= intArrayLength; i++) {   
			if (oArray[i][0]==strKey){
				return ((oArray[i][1]).toString());
			}
		}
}
			
function doValidate(){
	var formIsValid=true;
	var ostr;
	var strHTML='a';
	var strID='';
	var obj;
	
	
	if(PH_DoValidation){
		if(oVldSum!=null)
			oVldSum.innerHTML="Please correct the following errors:<br>"

		for(i=0;i<=intArrayLength;++i){
			strID=(oArray[i][0]).toString()

			//checking text placeholders
			if (strID.indexOf('IMAGE')==-1 && strID.indexOf('DATE')==-1){
				obj = eval('document.'+strID);
				if(obj!=null)
					strHTML = obj.HTML;
			}
			
			else{//checking IMAGES placeholders			
				if (strID.indexOf('IMAGE')>0 || strID.indexOf('DATE')>0){
					obj = eval('document.all.'+strID);
					if(obj!=null)
						strHTML = obj.value;
				}
			}
				
					
			//checking the lenght of the return HTML or SRC
			if (strHTML.length>0){
				ostr=GetStringLength(strHTML);					
			}
			else{
				ostr='';	
			}
						
			//checking if the field should be checked for requird
			if (strID.indexOf('_REQ_HP_')>-1){
					if (IncludeInHomePage_ISChecked()){
						formIsValid=(!ostr.length==0)
					}	
			}
			else{
					formIsValid=(!ostr.length==0)
			}
			//getting out of the loop if the page is not valid
			if (!formIsValid){break;}
		}

		if (!formIsValid){
			var strErrorString = GetErrorDesctiption(strID);
			oVldSum.style.display='inline';
			//Build error string
			oVldSum.innerHTML=oVldSum.innerHTML + '<li>'+strErrorString+'</li>';
			alert(strErrorString);
		}
	}
	return formIsValid;
}


function IncludeInHomePage_ISChecked(){
	var retVal=false;
	var oObj = document.getElementById('IncludeInHomePagePH1_AuthoringModeControlsContainer__ctl0');
	if (oObj){
		retVal=oObj.checked;
	}
	return retVal;
}

function init(){
	oVldSum = document.getElementById('vldSum');
	if(WindowPrint){
		window.print();		
		if(oVldSum!=null)
			oVldSum.style.display='none';
	}
}

function ShowChannels(TrId)
	{
			Alert(1);
			//oTrId = document.getElementById(TrId.toString());
		//	oTrId.style.display='inline';
	}




//*******************************************************************************
//		End Place Holder's Validations functions
//*******************************************************************************