
function changefontsize(num) {
       var e=document.getElementsByClassName('contentObjectTextArea');
       
       for(var j=0; j<e.length; j++){
       
		 var children =e[j].getElementsByTagName('*');

         for(var i=0;i<children.length;i++){

            if(children[i].href != null && (children[i].href).replace(/^\s+|\s+$/g, '') != 'undefined'){
            	changefontsize2(children[i],num);
	 	 	}
	  	 	else if(children[i].className != ''){
                changefontsize2(children[i],num);
         	}
         	else if(children[i].size != null && (children[i].size).replace(/^\s+|\s+$/g, '') != ''){
                changefontsize2(children[i],num);
         	}
         }
     }
    }
    
function changefontsize3(fontsize){
	var conversion = new Array();
	conversion[0] = 0;
	conversion[1] = 10;
	conversion[2] = 13;
	conversion[3] = 16;
	conversion[4] = 19;
	conversion[5] = 23;
	conversion[6] = 30;
	
	return conversion[fontsize];
}

function changefontsize2(elementId,num) {
      function calculateFSize(obj,defsize,change,minsize,maxsize) {
            var fontsize = getSize ( obj,defsize)+change;
            fontsize = Math.max(minsize,fontsize);
            fontsize = Math.min(maxsize,fontsize);
            obj.style.fontSize = fontsize + 'px';
      }
      calculateFSize(elementId,15,num,10,26);
}


function getSize(el,defsize) {
      var value;
      if (document.defaultView && document.defaultView.getComputedStyle) {
            value = document.defaultView.getComputedStyle(el, null)["fontSize"];
      } else if (el.currentStyle) {
            value = el.currentStyle["fontSize"];
      } else {
            value =  el.style["fontSize"];
      }
      if (value.indexOf("px")!= -1){
            return parseInt(value.substring(0,value.indexOf("px")));
      }
      value = parseInt(el.style.fontSize);
      if (!isNaN(value)){
            return value;
      }
      value = parseInt(el.size);
      if (!isNaN(value)){
      		return changefontsize3(value);
      }
      return parseInt(defsize);
}
//function changefontsize2(elementId,num) {
		
//	function calculateFSize(obj,defsize,change,minsize,maxsize) {
//		var fontsize = parseInt(obj.style.fontSize)
//		var fontsize2 = parseInt(obj.size)
//		fontsize = change + (isNaN(fontsize) ? (isNaN(fontsize2) ? defsize : fontsize2) : fontsize)
//		fontsize = Math.max(minsize,fontsize)
//		fontsize = Math.min(maxsize,fontsize)
//		obj.style.fontSize = fontsize + 'px'
//	}
//	calculateFSize(elementId,15,num,10,26)
//}

/****************************************************************************************************/
/* Eitan */

// dislays Alert or Confirm popup
function msg(str, isConfirm, dir)
{
	var sFeatures = "dialogHeight:120px;dialogWidth:250px;status:0;scroll:0;help:0;edge:sunken;";	
	if(!isConfirm)
	   OpenPopUp("Include/Alert.jsp?dialogArguments="+str+"&dir="+dir, 130, 300)
	   //window.showModalDialog("Include/Alert.jsp", str,sFeatures)
	//else 
	//  return window.showModalDialog("Include/Confirm.jsp?dir="+dir, str,sFeatures)
}

function openTree(){
	var sFeatures = "dialogHeight:400px;dialogWidth:300px;status:0;scroll:0;help:0;edge:sunken;";	
    return window.showModalDialog("treeView.html", '',sFeatures);
}

/****************************************************************************************************/

var gbChangesMade = false;

var sSaveMsg = 'Saving...';
var sDeleteMsg = 'Deleting ...';
var sFinishMsg = 'Saving ...';
var sCancelMsg = 'Exiting ...';

// opens a calendar popup
function OpenCalendar(sFieldName,bIsClear)
{	
	var h = 210;
	var w = 280;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	var calWin = window.open('Include/CalendarPopUp.jsp?sFieldName='+sFieldName+'&bIsClear='+bIsClear,'cal','dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

/* checks the validation of email address
	
	Input: sEmail - the email
		   bEmptyValid - TRUE if empty string is a valid email, FALSE if not
		   
    Output:
    	   TRUE - email valid
    	   FALSE - email invalid
*/
function EmailCheck (sEmail, bEmptyValid)
 {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=sEmail.match(emailPat)

	if ( (sEmail == '') && bEmptyValid ) {
		return true;
	}	

	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	//if (user.match(userPat)==null) {
	    // user is not valid
	    //alert("The username doesn't seem to be valid.")
	 //   return false
	//}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}


// opens media item preview
function PreviewMediaItem(sFileName)
{
	var h = 500;
	var w = 500;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	var rxImageFile = "^\\S+.(gif|jpg|jpeg)"
	
	// image
	if (sFileName.toLowerCase().match(rxImageFile) != null)
		var previewWin = window.open('../MediaServer/MediaItemPreview.jsp?sFileName='+sFileName,'prevWin','resizable=yes,scrollbars=yes,dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
	
	// other file
	else
		var previewWin = window.open('/MediaServer/MediaItems/'+sFileName,'prevWin','resizable=yes,scrollbars=yes,dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

// opens media item preview
function PreviewMediaItemByID(lMediaItemID)
{
	var h = 500;
	var w = 500;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	
	var previewWin = window.open('../MediaServer/PreviewMediaItemByID.jsp?lMediaItemID='+lMediaItemID,'prevWin','resizable=yes,scrollbars=yes,dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

// opens pop up
function OpenPopUp(sURL, w, h, scroll)
{
	if (w == 0 && h == 0){
		h=500;
		w=700;
	}
		
	if(scroll==undefined){
		scroll='yes';
	}
	
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	//var rxImageFile = "(.*)/pdf/(.*)"
	// check if its a pdf file:
	//if (sURL.toLowerCase().match(rxImageFile) != null){
	//	w = screen.availWidth;
	//	h = screen.availHeight
	//	t = 0;
	//	l = 0;
	//}
	
	var popUpWin = window.open(sURL, '', 'resizable=yes,scrollbars='+scroll+',width='+w+',height='+h+',left='+l+',top='+t);
}

// opens a color selection popup
function OpenColorPopUp(sFunctionName, sColor)
{	
	var h = 300;
	var w = 500;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	
	sColor = sColor.substring(1, sColor.length);
	
	var colWin = window.open('Include/ColorPopUp.jsp?sFunctionName='+sFunctionName+'&sColor='+sColor,'col','dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

// selects all the items in multiple choice list (before submitting the form):
function selectAllList(formName, listName, bSelect)
{
	var d;
	var lLength;
	var mainFrame = window.parent.document.frames.f1.document.all;
	
	//d = document.forms[formName].elements[listName];
	d = window.parent.document.frames.f1.document.forms[formName].elements[listName];
	if(d == null || d =='undefined') return;
	lLength = d.options.length;
	
	for (var i = 0; i < lLength; i ++) 
		d.options[i].selected = bSelect;
	
}

// moves selected items from "src" list to "target" list 
function transfer2List(formName, srcLst, targetLst) 
{
        var itemText;
        var itemVal;
        var i;
        var newIndex;
        
        var src = document.forms[formName].elements[srcLst];
        var target = document.forms[formName].elements[targetLst];
        
		// copy the selected items from source to target list 
        for (i=0; i < src.options.length; i++) 
        {
	       if (src.options[i].selected) 
	       {
              itemText = src.options[i].text;		// the new option text.
              itemVal = src.options[i].value;		// the new option value.
              items=new Option(itemText, itemVal);	// construct the new option.
              newIndex = target.options.length;		// calculate new index.
              target.options[newIndex]=items;		// append the new option.
           }
        }

        /* delete removed items */
        i = 0;
        while (i < src.options.length) 
        {
           if (src.options[i].selected) 
              src.options[i]=null;  
            else
              i = i + 1;
        }
}

// checks if given ID is in the given Select list
// return TRUE if yes
// return FALSE if not
function isInList(lID, formName, srcLst)
{
   var i;
   var bFound;
   var src = document.forms[formName].elements[srcLst];
         
   i = 0;
   bFound = false;
   
   for (i=0; i < src.options.length; i++)
   {
      if (src.options[i].value == lID) 
         bFound = true;       
   }
   
   return bFound;
}


// removes selected items from "src" list 
function removeFromList(formName, srcLst) 
{
     
   var i;
   var src = document.forms[formName].elements[srcLst];
       
   /* delete removed items */
   i = 0;
   while (i < src.options.length) 
   {
      if (src.options[i].selected) 
         src.options[i]=null;  
      else
         i = i + 1;
   }
}

function moveInList(formName, srcLst, lDirection)
{	
    var src = document.forms[formName].elements[srcLst];
	var lLength = src.options.length;
	
	for (var i = 0; i < lLength; i ++) 
			if ((src.options[i].selected) && (i+lDirection < lLength) && (i+lDirection >= 0))
			{						
				src.options[i].swapNode(src.options[i+lDirection]);
				return;
			}			
}

function OpenCategorize(lMediaItemID, lContentObjectID)
{
	OpenPopUp('../Navigation/CategorizeRedirect.jsp?lMediaItemID='+lMediaItemID+'&lContentObjectID='+lContentObjectID, 500, 800);
}


function OpenCategorizeOrder(lSubChannelID, lMediaItemID, lContentObjectID, sDisplayArea, sTemplateTagID, sSubchannelName)
{
	if (lMediaItemID == '')
		lMediaItemID = -1;
	if (lContentObjectID == '')
		lContentObjectID = -1;
	OpenPopUp('../Navigation/CategorizeOrderRedirect.jsp?lSubChannelID=' +lSubChannelID+ '&lMediaItemID='+lMediaItemID+'&lContentObjectID='+lContentObjectID+'&sDisplayArea='+sDisplayArea+'&sTemplateTagID='+sTemplateTagID+'&sSubchannelName='+sSubchannelName, 500, 800);
}


// returns content object type
function SelectContentType()
{
	var sFeatures = "dialogHeight:280px;dialogWidth:300px;status:0;scroll:0;help:0;edge:sunken;";
	return window.showModalDialog("SelectTypePopUp.jsp", "",sFeatures);
}


// returns e mail addresses string
function InsertPreviewEmailAddresses()
{
	var sFeatures = "dialogHeight:280px;dialogWidth:300px;status:0;scroll:0;help:0;edge:sunken;";
	return window.showModalDialog("EnterNLPreviewAddresses.jsp", "",sFeatures);
}


// returns newsletter type
function SelectNewsletterType()
{
	var sFeatures = "dialogHeight:280px;dialogWidth:300px;status:0;scroll:0;help:0;edge:sunken;";
	return window.showModalDialog("SelectTypePopUp.jsp", "",sFeatures);
}

// shows content object history window
function ShowContentObjectHistory(lContentObjectID)
{
	OpenPopUp('ContentObjectHistory.jsp?lContentObjectID='+lContentObjectID, 400, 900);
}

// opens Media Item Select screen
// bIsImgOnly - select screen displays images only
function SelectMediaItem(bIsImgOnly, lTypeOnly)
{
	if (bIsImgOnly)
	{
		OpenPopUp('../MediaServer/MediaItemSelect.jsp?ImgOnly=' + bIsImgOnly , 500, 900);
		return;
	}
	
	if(lTypeOnly)
	{
		OpenPopUp('../MediaServer/MediaItemSelect.jsp?lTypeOnly=' + lTypeOnly , 500, 900);
		return;
	}

	OpenPopUp('../MediaServer/MediaItemSelect.jsp?ImgOnly=false', 500, 900);	
}

// opens Content Object Select screen
function SelectContentObject()
{
	OpenPopUp('../Content/ContentObjectSelect.jsp', 500, 800);
}

// shows content object reamrks window
function ShowContentObjectRemarks(lContentObjectID)
{
	OpenPopUp('RemarksEditor.jsp?lContentObjectID='+lContentObjectID, 500, 800);
}

// shows content object approvals window
function ShowContentObjectApprovals(lContentObjectID)
{
	OpenPopUp('ContentObjectApprovals.jsp?lContentObjectID='+lContentObjectID, 500, 800);
}

// opens Contact Details screen
function ShowContactDetails(lExternalUserID)
{
	if (lExternalUserID != '')
		OpenPopUp('../ExternalUsers/ContactDetailsPopUp.jsp?lExternalUserID='+lExternalUserID, 600, 500);
}

// opens Contacts Group Details screen
function ShowGroupDetails(lGroupID)
{
	if (lGroupID != '')
		OpenPopUp('../Newsletters/ContactGroupPreview.jsp?lGroupID='+lGroupID, 400, 600);
}

// opens Contacts File Details screen
function ShowContactsFileDetails(lMediaItemID, lContactsGroupID, lNewsletterID)
{
	if (lMediaItemID != '')
		OpenPopUp('../Newsletters/ContactFilePreview.jsp?lMediaItemID='+lMediaItemID + '&lContactsGroupID=' + lContactsGroupID + '&lNewsletterID=' + lNewsletterID, 400, 600);
}

// opens select external users screen
function SelectExternalUsers(sContactsList)
{
	OpenPopUp('../ExternalUsers/ExternalUserSelect.jsp?sContactsList='+sContactsList, 600, 980);
}

// opens select contacts group screen
function SelectContactGroups(sGroupsList)
{
	OpenPopUp('../Newsletters/ContactGroupSelect.jsp?sGroupsList='+sGroupsList, 500, 980);
}

// opens pop-up with selected role's keys
function ShowRoleKeys(lRoleID)
{
	var h = 210;
	var w = 280;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	if (lRoleID != '')
		var keysWin = window.open('../Users/RoleKeysPreview.jsp?lRoleID='+lRoleID,'keys','scrollbars=yes,dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

function OpenLinkEditor(lContentMediaLinkID, lNewsletterStripID, lNewsletterMediaItemID, lMediaItemID)
{
	OpenPopUp('../Resources/LinkEditor.jsp?lContentMediaLinkID=' + lContentMediaLinkID + '&lNewsletterStripID=' + lNewsletterStripID + '&lNewsletterMediaItemID=' + lNewsletterMediaItemID + '&lMediaItemID=' +  lMediaItemID, 400, 600);
}

// build list of out of select
function BuildList(formName, listName)
{
	var d;
	var lLength;
	var sList ='0'
	
	d = document.forms[formName].elements[listName];
	lLength = d.options.length;
	
	for (var i = 0; i < d.options.length; i ++) 
		sList = sList + ',' + d.options[i].value;

	return sList;
}

function PreviewSubChannel(lSubChannelID,sSubchannelUrl)
{
	var h = 500;
	var w = 700;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2; 
	window.open(sSubchannelUrl+'?lSubChannelID='+lSubChannelID+'&lContentObjectID=-1&lMediaItemID=-1&bIsInt=1', '', 'resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

function PreviewContentObject(lContentObjectID,sSubchannelUrl)
{
	var h = 500;
	var w = 700;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2; 
	window.open(sSubchannelUrl+'?lSubChannelID=-1&lContentObjectID='+lContentObjectID+'&lMediaItemID=-1&bIsInt=1', '', 'resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes,width='+w+',height='+h+',left='+l+',top='+t);

}

function PreviewNewsletter(lNewsletterID)
{
	var h = 500;
	var w = 700;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	window.open('../Newsletters/NewsletterTemplateSelector.jsp?lNewsletterID='+lNewsletterID, '', 'resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

function DuplicateNewsletter(lNewsletterID)
{
	var doDuplication = msg('Are you sure you want to duplicate this newsletter?', true);

	if(doDuplication)
	{
		location.replace('../Newsletters/DuplicateNewsletter.jsp?lNewsletterID='+lNewsletterID);
	}
}
//

function PreviewNewsletterHistory(lNewsletterID)
{
	var h = 500;
	var w = 700;
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	window.open('../Newsletters/PreviewHistoryContent.jsp?lNewsletterID='+lNewsletterID, '', 'resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes,width='+w+',height='+h+',left='+l+',top='+t);
}

// opens Newsletter history contacts screen
function PreviewNewsletterHistoryContacts(lNewsletterID)
{
	OpenPopUp('../Newsletters/HistoryContactsPreview.jsp?lNewsletterID=' + lNewsletterID, 400, 600);
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function SetArea(sImgName, sDivName)
{
	var sDisplay;
	var sImg;


	// if shown - hide
	if (document.all[sDivName].style.display=='inline')
	{
		sDisplay = 'none';
		sImg = '../Resources/img/close-big.gif'
	}
	else
	{
		sDisplay = 'inline';
		sImg = '../Resources/img/open-big.gif'
	}

	document.all[sDivName].style.display = sDisplay;
	document.all[sImgName].src = sImg;

}

function findNow(){
		var	radioButtons = document.all("radioDates");
		if(radioButtons[0].checked){
	  	    document.all("radioVal").value = radioButtons[0].value;
	  	    
	   	}  
	    else{
	    	
	    	if(document.all("FromDate").value=='' || document.all("ToDate").value=='' ){
	    		return false;
	    	}	
	    	document.all("radioVal").value = radioButtons[1].value;
	    	
	    }
		return true;
	}
/*
Navigates to URL / Subchannel / Content Object / Media Item

sLinkType - Type of the content: U - URL, S - Subchannel, C - Content Object, M - Media Item
sURL - the URL. if sLinkType='U' - the URL, else - empty
lItemID - the ID of the subchannel, content object or media item. empty if sLinkType='U'
bIsNewWindow - 1 or ''
lWinHeight - the height of the new window
lWinWidth - the width of the new window
lCurrSubchannelID - the ID of the subchannel, where we pressed the link
*/

function openLink(sLinkType, sURL, lItemID, bIsNewWindow, lWinWidth, lWinHeigh, lCurrSubchannelID, coSubchannelId)
{
	var h = lWinHeigh;
	var w = lWinWidth;
	if (h==0&&w==0){
		h = 500;
		w = 700;
	}	
	var t = (screen.availHeight-h)/2;
	var l = (screen.availWidth-w)/2;
	var queryString = window.location.href;
	var requestSID;
	
	var re = null;
	
		
	re = new RegExp('(.*)/C-([0-9]+).html$');
	if(queryString.match(re)){
		requestSID = (re.exec(queryString))[2];		
	}
	
	re = new RegExp('(.*)/C-([0-9]+).html([0-9]+)$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[2];
		
	re = new RegExp('(.*)/A-([0-9]+)-([0-9]+).html$');
	if(queryString.match(re)){
		 requestSID = (re.exec(queryString))[2];
	}
		
	re = new RegExp('(.*)/M-([0-9]+)-([0-9]+).html$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[2];
	
	
	
		
	re = new RegExp('Categories/(.*)/([0-9]+).html$');
	if(queryString.match(re)){
		requestSID = (re.exec(queryString))[2];		
	}
		
	re = new RegExp('Categories/(.*)/([0-9]+).html([0-9]+)$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[2];
		
	re = new RegExp('Articles/(.*)/([0-9]+)-([0-9]+).html$');
	if(queryString.match(re)){
		requestSID = (re.exec(queryString))[2];
	}
		
	re = new RegExp('Media/(.*)/([0-9]+)-([0-9]+).html$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[2];
		
	re = new RegExp('Categories/(.*)/DisplaySubchannel.jsp(.*)lSubchannelId=([0-9]+)');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[3];
		
	re = new RegExp('Ext/DisplaySubchannel.jsp(.*)lSubchannelId=([0-9]+)$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[2];
		
	re = new RegExp('Articles/(.*)/DisplaySubchannel.jsp(.*)lSubchannelId=([0-9]+)&amp;(.*)lContentObjectId=([0-9]+)');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[3];
		
	re = new RegExp('Media/(.*)/DisplaySubchannel.jsp(.*)lSubchannelId=([0-9]+)&amp;(.*)lMediaItemId=([0-9]+)');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[3];
	
	re = new RegExp('Search/([0-9]+)/(.*).html([0-9]+)$');
	if(queryString.match(re))
		requestSID = (re.exec(queryString))[1];
    	
	//requestSID=getParameterFromQueryString(queryString,'lSubchannelId');
	
	if(lCurrSubchannelID==0 && requestSID!='null' && requestSID!=undefined){
		lCurrSubchannelID = requestSID;
	}
	
	// alert ("lCurrSubchannelID="+lCurrSubchannelID  + "  ;requestSID="+requestSID);
	
	switch (sLinkType)
	{
		// link to URL
		case 'U':
		if (bIsNewWindow == 1)
			OpenPopUp(sURL, lWinWidth, lWinHeigh);
		else
			window.location.href = (sURL);
		
		break;
		
		// link to Subchannel
		case 'S':
		if (bIsNewWindow == 1)
			OpenPopUp('/'+coSubchannelId+'/C-'+lItemID+'.html', lWinWidth, lWinHeigh);
			//OpenPopUp('/RealCMS/Ext/DisplaySubchannel.jsp?lSubchannelId='+lItemID+'&preview=true', lWinWidth, lWinHeigh);
		else{					
			window.location.href =('/'+coSubchannelId+'/C-'+lItemID+'.html');
			//window.location.href =('/RealCMS/Ext/DisplaySubchannel.jsp?lSubchannelId='+lItemID+'&preview=true');
		}			
		break;
		
		// link to Content Object
		case 'C':
		if (bIsNewWindow == 1)
			OpenPopUp('/'+lCurrSubchannelID+'/A-'+coSubchannelId+'-'+lItemID+'.html', lWinWidth, lWinHeigh);
			//OpenPopUp('/RealCMS/Ext/DisplaySubchannel.jsp?lSubchannelId='+coSubchannelId+'&lContentObjectId='+lItemID+'&preview=true', lWinWidth, lWinHeigh);
		else
			window.location.href =('/'+lCurrSubchannelID+'/A-'+coSubchannelId+'-'+lItemID+'.html');
			//window.location.href =('/RealCMS/Ext/DisplaySubchannel.jsp?lSubchannelId='+coSubchannelId+'&lContentObjectId='+lItemID+'&preview=true');
		break;
		
		// link to media item
		case 'M':
		if (bIsNewWindow == 1){
		// sURL = 1 indicates that the media is a pdf file
			//if (sURL == 1)
			//	OpenPopUp('/RealCMS/Media/PDF/'+coSubchannelId+'/'+lCurrSubchannelID+'-'+lItemID+'.html', lWinWidth, lWinHeigh);
			//else 
			window.open('/Site/Ext/MediaItemFromLink.jsp?mediaId='+lItemID, '', 'resizable=yes,scrollbars=yes,dependent=yes,width='+w+',height='+h+',left='+l+',top='+t);		
			}
		else
			window.location.href =('/'+coSubchannelId+'/M-'+lCurrSubchannelID+'-'+lItemID+'.html');		
			//window.location.href =('/RealCMS/Ext/DisplaySubchannel.jsp?lSubchannelId='+lCurrSubchannelID+'&lMediaItemId='+lItemID+'&preview=true');		
		break;
		
		// link to Map item
		case 'P':
		break;
	}

}

function replaceAll( str, searchTerm, replaceWith, ignoreCase )   {
   var regex = "/"+searchTerm+"/g";
   if( ignoreCase ) regex += "i";
   return str.replace( eval(regex), replaceWith );
}

/*
return the parameter value from the queary string:
*/
function getParameterFromQueryString ( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
}

/*
Function trim:
*/
function trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
		
	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function addCommasToNumber(num,fracLen){
	//var objRegExp  = /^\d{1,3}(,\d\d\d)*\.\d\d$|^\d+\.\d\d$/;
	num=eval(num);
	var fraction=num-Math.floor(num);
	if(fraction != 0) {
		fraction=fraction.toString();
		if(fracLen == undefined){
			fracLen=fraction.length;
		}
		fraction=fraction.substring(fraction.indexOf('.'),fracLen);
	}
	else{
		fraction='';
	}
	num=Math.floor(num);
	num = num.toString();
	var len = num.length;
	for(var i=3; (len>3) && (i< num.length) ; i=i+4){
		num=num.substring(0,num.length-i)+','+num.substring(num.length-i,num.length);
	}
	num=num+fraction;
	return num;
}




function writeObj(url,w,h,bgc,httpType,id){

var str

str = ""

str = str + "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "

str = str + "codebase='"+ httpType + "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'"

str = str + "class='BannerFlash'" 

str = str + "width='"+ w +"' height='"+ h +"' id='"+id+"' align=''>"

str = str + "<param name='allowScriptAccess' value='sameDomain' />"

str = str + "<param name='movie' value='"+ url +"' />"

str = str + "<param name='quality' value='high' />"

str = str + "<param name='bgcolor' value='"+ bgc +"' />"

str = str + "<param name='wmode' value='transparent' />"

str = str + "<embed src='"+ url +"'  "

str = str + "quality='high' "

str = str + "bgcolor='"+ bgc +"' "

str = str + "width='"+ w +"' height='"+ h +"' "

str = str + "name='movieflash_" + id + "' wmode='transparent'" 

str = str + "align='' "

str = str + "allowScriptAccess='sameDomain' "

str = str + "type='application/x-shockwave-flash' "

str = str + "pluginspage='http://www.macromedia.com/go/getflashplayer' />"

str = str + "</object>"

document.write(str);

}
/********************************/

function openMarketingFile()
{
 var h = window.screen.availHeight; //The window height
var w = window.screen.width; //The window width
var t = 0; //The window's distance from the top of the screen
var l = 0; //The window's distance from the left of the screen
 var win1=window.open("https://sol.ordernet.co.il/Opener/Opener.asp?c=117&w=" + window.screen.width + "&h=" + window.screen.availHeight, "ordernet","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbar=no,resizable=no", "replace=true");
win1.focus();
 }
function openPersonalFile() 
{
window.open("https://query.ordernet.co.il/Opener/Opener.asp?c=117&w=" + window.screen.width + "&h=" + window.screen.availHeight, "ordernet","width=" + (window.screen.width - 10) + ",height=" +(window.screen.availHeight - 30) +",fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbar=no,resizable=no", replace=true);
}
/*********************************************************/
function getBrowserDetection()
{
 
 var browser = '';
//var version = '';
//var entrance = '';
//var cond = '';
if (browser == '')
{
     if (navigator.appName.indexOf('Microsoft') != -1)
          browser = 'IE'
     else if (navigator.appName.indexOf('Netscape') != -1)
          browser = 'Netscape'
     else browser = 'IE';
}
//if (version == '')
//{
 //    version= navigator.appVersion;
 //    paren = version.indexOf('(');
 //    whole_version = navigator.appVersion.substring(0,paren-1);
  //   version = parseInt(whole_version);
//}
return  browser;
  }
  
function isMozilla(){
var ver = navigator.appVersion;
var name = navigator.appName;
if ((ver.indexOf("Safari") == -1) && name.indexOf("Microsoft") == -1)
	return true;
else return false;
}
 
var floatingDiv = null,floatingDiv2 = null;
function ShowImages2(url, iframeStatus)
{
	floatingDiv.style.top = parseInt(document.body.scrollTop, 10) + 120;

	if (iframeStatus == 1 || iframeStatus == 4)
		floatingDiv.style.left = "220";
	else
		floatingDiv.style.left = "20";
		
	floatingDiv.style.display = "block";
	
	if (isMozilla()){
		document.getElementById("iframeImages").src = url;
		if (document.getElementById("iframeImages").style.display.toLowerCase() == "none")
			document.getElementById("iframeImages").style.display = "block";
	}
	else{
		var changeDiv = floatingDiv.children[0].children[0].children[1].children[0].children[0];
		changeDiv.src = url;
		if (changeDiv.style.display.toLowerCase() == "none")
			changeDiv.style.display = "block";
	}
	floatingDiv.zIndex = 100;
	
	//clearTimeout(timerHdl);
}
function closeDiv(){
	floatingDiv.style.display = 'none';
}
function loadFloatingDiv(address, city, state, path)
{	
	var addressForMap = address + city + state;
	addressForMap = replaceAll(addressForMap, ",", " ", true);
	floatingDiv2 = document.createElement('div');
	floatingDiv2.id = "divImages";
	floatingDiv2.style.width = "590px";
	floatingDiv2.style.position = "absolute";
	floatingDiv2.style.height = "384px";
	floatingDiv2.innerHTML = '<iframe FRAMEBORDER=0 id="iframeImages" scrolling="no" runat="server" height="384px" width="590"></iframe>';
	//document.body.appendChild(floatingDiv);
	floatingDiv2.style.display = "none";
	floatingDiv = document.createElement('div');
	floatingDiv.style.border = "2px";
	floatingDiv.style.backgroundColor="#DBE4EE";
	floatingDiv.style.borderStyle="solid";
	floatingDiv.style.borderColor="navy";
	floatingDiv.style.fontColor="white";
	floatingDiv.id = "divImages";
	floatingDiv.style.xwidth = "590px";
	floatingDiv.style.position = "absolute";
	floatingDiv.style.height = "408px";
	//floatingDiv.innerHTML = "<br>&nbsp;<img style=\"vertical-align: top;cursor:pointer;\" src='/Site/Ext/Img/CVTSA/general/red_delete_x.gif' title='Close' onclick='closeDiv();'>&nbsp;&nbsp;" + 
	//	"<font style=\"font-family: tahoma;vertical-align: top;font-size: 12px; \">Address : "+ address+", "+city+", "+state+"</font>" + floatingDiv2.innerHTML;
	floatingDiv.innerHTML = "<table border=0px cellspacing='0' cellpadding='1px'>" + 
							"<tr>"+ 
								"<td>" + 
									"&nbsp;<font style=\"font-family: verdana;color:navy;vertical-align: middle;font-size: 12px; \">Address : "+ address+", "+city+", "+state+"</font>" +
								"</td>"+
								"<td align=right>" + 
									"<img style=\"vertical-align: middle;cursor:pointer;\" src='/Site/Ext/Img/CVTSA/general/close_x_red.png' title='Close' onclick='closeDiv();'/>"  +
								"</td>" + 
							"</tr>"+
							"<tr>"+
								"<td colspan=100%>"+ 
	   								 floatingDiv2.innerHTML + 
								"</td>"+
							"</tr>"+
							"</table>";
	document.body.appendChild(floatingDiv);
	floatingDiv.style.display = "none";
	ShowImages2('/Site/Ext/DisplayMap.jsp?lAddress='+address+'&lCity='+city+'&lState='+state,'1');
}
