 
 //global function to catch any script error in the page
 //and write it to the status of the window!
function handleErrorGlobal(strErrorMsg,strUrl,iLineNumber)
{
	window.status = strErrorMsg + ': Line:' + iLineNumber;
	return true;
}
window.onerror = handleErrorGlobal;



/* --- Common Methods  --- */


 var TABLEACTIONSOFFSET = 12;
 
 
function HasContentChanged(next_action)//checks if the content of the branding strategies has changed
{
	if(content_has_changed)
	{
		if (!confirm("You have not saved the changes that you made.\nAre you sure you want to continue?"))
		{
			return;
		}
		else
		{
			document.frmMain.reset();//reset the form without the user's changes
		}
		
	}
	eval(next_action);
}
var content_has_changed=0;//flag for whether the branding strategies content has changed
function ContentChanged()
{
	content_has_changed=1;
}

var whichbar=1;
function doPrg()
{	
	if(whichbar >= 0 && whichbar < 15 ) {
		var imgid = "prog" + whichbar;
		if (document.all["prog1"].length > 1)
		{
		
			return;
		}
		if (whichbar == 1)
		{
			document.all["prog14" ].style.display = 'none';
			document.all["prog1"].style.display = 'inline';
		}
		else
		{
			document.all[imgid].style.display = 'inline'
			document.all["prog" +(whichbar -1 )].style.display = 'none'
		}
		setTimeout("doPrg()", 250)
		whichbar ++;
	}
	else
	{
	  	whichbar =1
	  	for (var i =1 ; i < 15 ; i++ ){
	  		document.all["prog"+i].style.display = 'none'
	  	}
	  	setTimeout("doPrg()", 250)
	}	
}
	

//----------------------

function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor = 
      document.all ? 'hand' : 'pointer';
}
function toggleLink (link) {
  if (link.disabled) 
    enableLink (link)
  else 
    disableLink (link);
  link.disabled = !link.disabled;
}
//----------------------


function back()
{
	history.back();
}
function getIFValueOK( val)
{
	if (val.value.indexOf('.',0) == -1 || val.value == "http://" || val.value == "" || val.value.length < 7)
	{
		return false;
	}
	else
	{	
		return true;
	}	
}	

function getIftxtMenuUrlValue(source, args)
{

	var val = GetElementBySubID(document, "txtUrl"); 
	args.IsValid = getIFValueOK( val);
	
}


function getIfTxtUrlValue(source, args)
{
	var val = GetElementBySubID(document, "txtUrl"); 
	if (getIFValueOK(val)== false)
	{
		val.focus();
	}
	args.IsValid = getIFValueOK( val);
}



function ChangeDisabled()
{
	var frm = GetElementBySubID(document, "frmMain"); 
	var chk = GetElementBySubID(document, "chkboxButtonWizard"); 
	
	if (chk != null)
	{
		if (!chk.checked)
		{
			var i=0
			//document.getElementById("iconsGif").useMap="";
			for ( i=0 ; i < frm.length ; i ++)	
			{
				if (frm[i].type == "text" || frm[i].type == "file" 
				|| frm[i].type == "radio"  )
				{
					frm[i].disabled = true;
				}
			}
		}
		else
		{	
			var i=0
			for (var i=0 ; i < frm.length ; i ++)	
			{
				if (frm[i].type == "text" || frm[i].type == "file"
				|| frm[i].type == "radio" )
				{
					frm[i].disabled = false;
				}
			}
		}
	}
}


function GetEmptyInput()
{
	window.event.returnValue = false;
}


function GetElementBySubID(objParent, id)
{	
	var retVal = null;
	
	for (var i=0; i<objParent.all.length; i++)
	{
		if (objParent.all[i].id.indexOf(id) >= 0)
		{
			retVal = objParent.all[i];
			break;
		}
	}
	return retVal;
}

function chooseRightBTNOnEnter()
{
	var chr = window.event.keyCode;
	if (chr == 13 )
	{
		var obj =GetElementBySubID(document, "btnLogin")
		document.all[obj.id].focus();
	}
}


function SetToolbarBackgroundOnLandingPage()
{
	var img			= document.all['landingPageBrowserImage'];
	var imgPos		= GetElementPosition('landingPageBrowserImage');
	var toolbar     = document.all['divToolbar'];
	
	toolbar.style.top = imgPos.top + 7	;

	toolbar.style.left = imgPos.left + 240;
	toolbar.style.right = imgPos.left + 240 + 30;
	
	toolbar.style.display = "Inline";
}


function SearchLogoValidator(source, args)
{
	try
	{
		var txt = GetElementBySubID(document, "upFile");
		//var imgUrl = txt.value ;
		var temp = txt;
		
		if (txt != null && txt.value == "")
		{
			txt = GetElementBySubID(document, "txtLogoIcon");
			if (txt == null)
			{
				txt = temp;
			}
		}
		
		if (txt != null)
		{
			var radioBtn = GetElementBySubID(document, "radioBtn_0");
			if (txt.value == "" && radioBtn.checked)
			{			
				args.IsValid =  false;
			}
			else
			{
				if (!radioBtn.checked)
				{
					args.IsValid =  true;
				}
				else
				{
					imgUrl = txt.value;
					var isOk=VerifyUploadImage( imgUrl )
					if (isOk)
					{				
						focusLogoImage()
						args.IsValid =  true;
					}
					else
					{				
						args.IsValid =  false;
					}	
				}
			}
		}
	}
	catch(er)
	{
		
	}
}
function SearchLogoTextValidator(source, args)
{
	var theText			=GetElementBySubID(document, "txtText");
	theText.value		=RTrim ( theText.value);
	theText.value		=LTrim ( theText.value);
	
	if(GetElementBySubID(document, "RadioButton2").checked)
	{
		if (theText.value == null  || theText.value == "")
		{
			args.IsValid =  false;
			theText.focus();
			return;
		}
	}
	args.IsValid =  true;
}




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 SearchLogoTextLengthValidator(source, args)
{
	var theText=GetElementBySubID(document, "txtText");
	if(GetElementBySubID(document, "RadioButton2").checked)
	{
		if (theText.value.length >45)
		{
			args.IsValid =  false;
			theText.focus();
			return;
		}
	}
	args.IsValid =  true;
}


function VerifyUploadImage(fileName)
{
	if (fileName == "" ) 
	{
		var val = GetElementBySubID(document, "lblTitle");
		if (val.id.toLowerCase()=="lblTitle".toLowerCase()) 
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
	if (fileName.toLowerCase().indexOf('.gif') ==-1 &&
		fileName.toLowerCase().indexOf('.bmp')==-1 &&
		fileName.toLowerCase().indexOf('.jpeg')==-1 &&
	//	fileName.toLowerCase().indexOf('.png') ==-1 &&
		fileName.toLowerCase().indexOf('.jpg')==-1 )
	{
		//alert("The only supported formats are: gif, bmp, png or jpg");
		return false;
	}
	return true;
}

function GetElementPosition(elemID) 
{    
	var counter = 0;
	
	var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) 
    {
	
		offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
        counter ++;
    }
   
    return {left:offsetLeft, top:offsetTop};
}
/* --- editControls  --- */
function ShowFramework(srcID )
{
	var img = 	document.all[srcID];
	img.style.border="1px dotted #000000";
}


function ShowLinkButtonComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move , ComunicateId)
{	

	pos		= GetElementPosition(srcID);	
	var img = document.all[srcID];
	

	
	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	SetSpanActionPosition(spnID, img);
	
														
	
	//60 instead of (document.all[spnID].offsetWidth / 2)	
	document.all[deleteID].parentElement.style.display				= "inline";	
	document.all[editID].parentElement.style.display				= "inline";	
	document.all[addID].parentElement.style.display					= "none";
	document.all[ComunicateId].parentElement.style.display			= "none";
	
	
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move);
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}



function ShowExternalComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move , ComunicateId)
{	

	pos		= GetElementPosition(srcID);	
	var img = document.all[srcID];
	

	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	SetSpanActionPosition(spnID, img);
	
														
	
	//60 instead of (document.all[spnID].offsetWidth / 2)	
	document.all[deleteID].parentElement.style.display				= "inline";	
	document.all[editID].parentElement.style.display				= "inline";	
	document.all[addID].parentElement.style.display					= "none";
	document.all[ComunicateId].parentElement.style.display			= "none";
	
	
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move);
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}


function ShowRssActions( rssTblID , spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move , ComunicateId , isMsg,sug)
{	
	if (sug == "msg")
		document.getElementById("tdDelete").onclick = ConfirmDelete;
	else
		document.getElementById("tdDelete").onclick = "";
	pos = GetElementPosition(rssTblID);		
	var img = document.all[rssTblID];
	
	
		
	// the focus table
	var tbl = GetElementBySubID(document, "tblActionsFocus");
	var tblRss = GetElementBySubID(document, rssTblID);
	tbl.style.width = tblRss.offsetWidth + TABLEACTIONSOFFSET;
	
	document.all[deleteID].parentElement.style.display	= "inline";	
//	document.all[moveLeftID].parentElement.style.display	= "inline";	
//	document.all[moveRightID].parentElement.style.display	= "inline";	
	document.all[addID].parentElement.style.display	= "none";	
	document.all[editID].parentElement.style.display	= "inline";
	if (isMsg == "true")	
		document.all[ComunicateId].parentElement.style.display	= "inline";	
	else
		document.all[ComunicateId].parentElement.style.display	= "none";		
	
	
	
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move);
	
	SetSpanActionPosition(spnID, img);
	
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";
}

function ShowSearchComponentActions(spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move,imageId , ComunicateId )
{
	
	pos			= GetElementPosition(imageId);
	var img		= document.getElementById(imageId);

	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = document.getElementById(imageId).offsetWidth + TABLEACTIONSOFFSET;//event.srcElement.offsetWidth + 20;
	
	document.all[ComunicateId].parentElement.style.display			= "none";
	
	document.all[addID].parentElement.style.display					= "none";
	
	if (document.getElementById('editControls_toolbar_hiddenHighLiter').value != 'true')
	{	
		document.all[editID].parentElement.style.display	= "inline";	
		document.all[deleteID].parentElement.style.display	= "none";	
	}
	else
	{
		document.all[editID].parentElement.style.display	= "none";	
		document.all[deleteID].parentElement.style.display	= "inline";
	}	
	
	var moveLeftIDdisplay="none";
	var moveRightIDdisplay="none";
	if (document.getElementById('editControls_toolbar_hiddenHighLiter').value != 'true')
	{	
		if(move == 0)
		{
			moveLeftIDdisplay= "inline";	
			document.all[moveLeftID].innerText  = "Move Left";
		}
		if(move == 2)
		{
			moveLeftIDdisplay= "inline";	
			document.all[moveLeftID].innerText  = "Move Left";
		}
	}
	
	document.all[moveLeftID].parentElement.style.display	="none";
	document.all[moveRightID].parentElement.style.display	= moveRightIDdisplay;
	
	SetSpanActionPosition(spnID, img);
	
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display					= "inline";
	
	
}

function ShowHighLiterActions(spnID, editID, deleteID, moveLeftID, moveRightID ,addID, imageId , ComunicateId )
{
	
	pos				= GetElementPosition(imageId);//event.srcElement.id);		
	var img			= document.getElementById(imageId);
	
	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = document.getElementById(imageId).offsetWidth + 10;//event.srcElement.offsetWidth + 20;
	document.all[ComunicateId].parentElement.style.display			= "none";
	document.all[addID].parentElement.style.display					= "none";
	document.all[deleteID].parentElement.style.display				= "inline";
	document.all[moveLeftID].parentElement.style.display			= "none";
	document.all[moveRightID].parentElement.style.display			= "none";
	document.all[editID].parentElement.style.display				= "none";	
	document.all[spnID].style.top									= pos.top - 9;
	
	SetSpanActionPosition(spnID, img);
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display					= "inline";
	
}





function ShowLogoComponentActions(spnID, editID, deleteID, moveLeftID, moveRightID, addID ,imageId,ComunicateId)
{	
	pos			= GetElementPosition(imageId);		
	var img		= 	document.all[imageId];
	// the focus table
	
		
	var tbl			= GetElementBySubID(document, "tblActionsFocus");

	tbl.style.width = document.getElementById(imageId).offsetWidth + TABLEACTIONSOFFSET;	//event.srcElement.offsetWidth + 20;	

	document.all[deleteID].parentElement.style.display			= "none";	
	document.all[moveLeftID].parentElement.style.display		= "none";	
	document.all[moveRightID].parentElement.style.display		= "none";	
	document.all[addID].parentElement.style.display				= "none";	
	document.all[editID].parentElement.style.display			= "inline";	
	document.all[ComunicateId].parentElement.style.display		= "none";

	
	SetSpanActionPosition(spnID, img);
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";
}



function ShowMenuItemComponentActions(spnID, editID, deleteID, moveLeftID, moveRightID ,addID, edit,imageId,ComunicateId)
{
	
	pos = GetElementPosition(imageId);//event.srcElement.id);		
	
	// the focus table

	var tbl = GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = document.getElementById(imageId).offsetWidth + TABLEACTIONSOFFSET;	//event.srcElement.offsetWidth + 20;	
	
	document.all[deleteID].parentElement.style.display				= "none";	
	document.all[moveLeftID].parentElement.style.display			= "none";	
	document.all[moveRightID].parentElement.style.display			= "none";	
	document.all[addID].parentElement.style.display					= "none";	
	document.all[ComunicateId].parentElement.style.display			= "none";		
	
	document.all[editID].parentElement.style.display				= "inline";	

	//document.all[spnID].style.left = pos.left + ( document.getElementById(imageId).offsetWidth / 2) - 60; //pos.left + (event.srcElement.offsetWidth / 2) - 60;//60 instead of (document.all[spnID].offsetWidth / 2)	
	SetSpanActionPosition(spnID, document.getElementById(imageId));
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";
}

function HideComponentBySpanID(spnID)
{

	// if the spnID display is 'none' it will be null and we dont need to do any work here
	if (document.all[spnID] != null)
	{
		var eventX = window.event.x+getScrollWidth();
		var eventY = window.event.y+getScrollHeight();
	
		var pos = GetElementPosition(spnID);
		pos.top+=2;//the mouseout even fires too soon and we aren't really out yet so add some padding
		pos.left+=2;//the mouseout even fires too soon and we aren't really out yet so add some padding
	
		var right = pos.left + document.all[spnID].offsetWidth;
		var bottom = pos.top + document.all[spnID].offsetHeight;
		
		// If the mouse is out of the actions (the span) we hide it
		if (!(( eventX > pos.left && eventX < right ) && ( eventY > pos.top && eventY < bottom )))
		{	
			document.all[spnID].style.display	= "none";
			document.getElementById("tdDelete").onclick = "";
		}
	}	
}

//cross platform function for getting the scroll width of the page
function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

//cross platform function for getting the scroll height of the page
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

/* --- ComponentsActions --- */
function ActionItem_MouseOver()
{
	// We need to fine the TR
	var tr = event.srcElement;
	while(tr.tagName.toUpperCase() != "TR")
	{
		tr = tr.parentElement;
	}
	tr.style.backgroundColor = "#DAE7EA";
}
function ActionItem_MouseOut()
{
	// We need to fine the TR
	var tr = event.srcElement;
	while(tr.tagName.toUpperCase() != "TR")
	{
		tr = tr.parentElement;
	}
	tr.style.backgroundColor = "#DBD8D2";
}


/*-- AddEditCampaign --*/
function AddEditCampaignText_KeyDown(spnID, length)
{
	document.all[spnID].innerText = event.srcElement.value.substring(0, length);	
}
function AddEditCampaignText_KeyUp(spnID, length)
{
	document.all[spnID].innerText = event.srcElement.value.substring(0, length);	
}

/*-- Wizard --*/
function Toolbar_Resize(componentID, imgFocusID, gapTop)
{
	var component = GetElementBySubID(document, componentID);	
	var imgFocus  = document.all[imgFocusID];
	if (component != null)
	{	
		var pos = GetElementPosition(component.id);
		
		imgFocus.style.top  = pos.top - gapTop + 42//gapTop; 
		imgFocus.style.left = pos.left - 10;//- gapLeft;
	}
}

/*-- UploadProgress --*/
function ShowUploadProgressWithID( id )
{

	try
	{
		var isOK = true;//Page_ClientValidate();
		isOK = Page_ClientValidate();
	
		var btnSave = GetElementBySubID(document, 'btnFinish');	
		var btnBack;
		if (btnSave	==	null)
		{
			btnSave =	GetElementBySubID(document, 'btnSave');
			btnBack	=	GetElementBySubID(document,	'btnBack');
			if (btnSave	!=	null)
			{
				btnBack.style.display ="none";
			}
		}
		
		var i;
		if (isOK)
		{
			var uploadGif	= GetElementBySubID(document, "UploadProgress");	
			var pos			= GetElementPosition(event.srcElement.id);
			btnSave.style.display ="none";
			uploadGif.style.left		= pos.left - 150;
			uploadGif.style.top			= pos.top - 20;
			uploadGif.style.display		= "inline";
			setTimeout('doPrg()', 250);
		}
	}
	catch(er)
	{
		
	}	
}

function ShowUploadProgress( id )
{
	try
	{
	
		var isOK = true;//Page_ClientValidate();
		isOK = Page_ClientValidate();
				
		var btnBack = GetElementBySubID(document, "btnBack");		
		var btnAdd = GetElementBySubID(document, "btnSave");
		
		
		
		var i;
		if (isOK)
		{
			btnBack.style.display = "none";
			btnAdd.style.display = "none";

			var uploadGif	= GetElementBySubID(document, "UploadProgress");	
			var pos			= GetElementPosition(event.srcElement.id);

			
			uploadGif.style.left		= pos.left - 150;
			uploadGif.style.top			= pos.top - 20;
			uploadGif.style.display		= "inline";
			if (typeof document.getElementById('imgBtnCancel') != 'undefined'   )
			{
				if (document.getElementById('imgBtnCancel') != null)
					document.getElementById('imgBtnCancel').style.display='none'
			}
			setTimeout('doPrg()', 250);
		}
	}
	catch(er)
	{
		
	}	
}
function ShowUploadProgressSingle( id )
{

	try
	{
		var btnAdd = GetElementBySubID(document, "btnSave");
		var i;
		var uploadGif	= GetElementBySubID(document, "UploadProgress");	
		var pos			= GetElementPosition(event.srcElement.id);
		btnAdd.style.display ="none";
		uploadGif.style.left		= pos.left - 150;
		uploadGif.style.top			= pos.top - 20;
		uploadGif.style.display		= "inline";
		setTimeout('doPrg()', 250);
	}
	catch(er)
	{
	}	
}



//made for wizard step 1
function UploadProgressForNextButton(ifSearch)
{
	try
	{
		
		var btnNext = GetElementBySubID(document, "btnNext");
		var isOK = true;//Page_ClientValidate();
		if (ifSearch == null)
			isOK = Page_ClientValidate();
		else
			isOk  = true;	
		var i;
		if (isOK)
		{
			var uploadGif	= GetElementBySubID(document, "UploadProgress");	
			var pos			= GetElementPosition(event.srcElement.id);
			if (ifSearch != null)
			{
				var btnBack = GetElementBySubID(document, "btnBack");
				btnBack.style.display ="none";
			}
			btnNext.style.display ="none";
			uploadGif.style.left		= pos.left - 150;
			uploadGif.style.top			= pos.top - 20;
			uploadGif.style.display		= "inline";
			setTimeout('doPrg()', 250);
		}
	}
	catch(er)
	{		
	}	
	
}

function HideButtonsAndShowUploadProgress(btnClicked)
{
	try
	{
		var btnBack = GetElementBySubID(document, "btnBack");
		var btnNext = GetElementBySubID(document, "btnNext");
		var lblErr =GetElementBySubID(document, "lblErr");
		lblErr.innerHTML="";
		// var btnFinish = GetElementBySubID(document, "btnFinish");
		var isOK = true;//Page_ClientValidate();
		if (btnClicked =='next')
		isOK = Page_ClientValidate();
		var i;
		if (isOK)
		{
			var uploadGif = GetElementBySubID(document, "UploadProgress"); 
			var pos   = GetElementPosition(event.srcElement.id);
			//next check is for cases where there is no back button
			if(btnBack!=null)
				btnBack.style.display ="none";
			    
			btnNext.style.display ="none";
			// btnFinish.style.display ="none";
			uploadGif.style.left  = pos.left - 150;
			uploadGif.style.top   = pos.top - 20;
			uploadGif.style.display  = "inline";
			setTimeout('doPrg()', 250);
		}
	}
	catch(er)
	{
	  
	} 
}


var currentlySelectedIcon



/*function SelectIcon(element,clickedImg)
{
	alert('1');
	ClearSelectedIcon(currentlySelectedIcon)
	currentlySelectedIcon=clickedImg;
	HighlightSelectedIcon(clickedImg);
	
}*/
function ClearSelectedIcon(clickedImg)
{
	if (!clickedImg)
	{
		return;
	}
	clickedImg.style.border="1px solid #F5F4EB";
	clickedImg.style.backgroundColor="#F5F4EB";
}
function HighlightSelectedIcon(td_id)
{
	td_id.style.border="1px ridge #0033CC";
	td_id.style.backgroundColor="#CCFFCC";
}


function createTextRange(idTxtBox)
{
	var tempval=eval( GetElementBySubID(document, idTxtBox)); 
	if (document.all["trMessage"].style.display.indexOf("none") == -1 && tempval.style.display.indexOf("none") == -1)
	{
		if (tempval.innerHTML != ""   )
		{
		//	tempval.focus();
			tempval.select();
			therange=tempval.createTextRange(); 
		}
	}
}
function WhenToDisplay(radioBtn)
{
	switch (radioBtn)
	{
	case 0:
		document.getElementById('txtWhenToDisplay').value = "-1"
		break;
	case 1:
		document.getElementById('txtWhenToDisplay').value = "60*1000"
		break;
	case 2:
		document.getElementById('txtWhenToDisplay').value = "60*60*1000"
		break;
	case 3:
		document.getElementById('txtWhenToDisplay').value = "-1"
		break;
	case 4:
		document.getElementById('txtWhenToDisplay').value = "24*60*60*1000"
		break;
	}
}
function ChangeDisplayRSS(radioBtn)
{
	var Discovery=document.getElementById('_ctl0_rssFeedAdd_btnDiscovery');//eval( GetElementBySubID(document, "Discovery")); 
	var txtRssFeed=eval( GetElementBySubID(document, "txtRssFeed")); 
	var tdNewRss=eval( GetElementBySubID(document, "tdNewRss")); 
	var txtInterval = eval ( GetElementBySubID(document, "txtInterval")); 

	if (radioBtn.value == "rss")
	{
		txtRssFeed.disabled = false;
		Discovery.disabled = false;
		txtInterval.value =120;
	}
	else
	{
		txtRssFeed.disabled = true;
		Discovery.disabled = true;
		txtInterval.value =30;
	
	}

}
function RSSFeedUrl(source, args)
{
	var txtLink=eval( GetElementBySubID(document, "txtLink")); 
	if (txtLink.style.display != "none" &&  !getIFValueOK( txtLink))
	{
		args.IsValid = false
	}
	else
	{
		args.IsValid = true
	}
}

function RSSFeedExistUrlAdd(source, args, controlID, elementID)
{
	var radioBtn_0 = GetElementBySubID(document, controlID);
	if (radioBtn_0.checked == true )
	{
		var txtRssFeedExist = eval(document.getElementById(elementID)); 
		if (!getIFValueOK(txtRssFeedExist ))
		{
			args.IsValid = false;
		}
		else	
		{
			args.IsValid = true;
		}
	}
	
}
function RSSFeedUrlAdd(source, args,  controlID, elementID)
{
	var radioBtn_1 = GetElementBySubID(document, controlID);
	if (radioBtn_1.checked == true )
	{
		var txtRssFeed = eval(document.getElementById(elementID)); 
		if (!getIFValueOK(txtRssFeed))
		{
			args.IsValid = false;
		}
		else	
		{
				args.IsValid = true;
		}
	}
	
}
function EmptyTextArea(source, args)
{
	var txtMessage = document.getElementById('txtMessage');
	if (txtMessage.value =="Enter your message here" || txtMessage.value=="")
	{
		args.IsValid = false
	}
	else
	{
		args.IsValid = true
	}
}

function IntervalMustNumber(source, args)
{
	var txtInterval = GetElementBySubID(document, "txtInterval");
	var strTemp = txtInterval.value;
	strTemp = trimAll(strTemp);
	var isNumber = IsNumeric( strTemp );
	args.IsValid = false;
	
    if(strTemp.length > 0 &&  strTemp < 10000   && isNumber && strTemp != "0" && strTemp != 0)
    {
		args.IsValid = true;
    }
}

function IntervalMustNumberMessageBox(source, args)
{
	var txtInterval = GetElementBySubID(document, "txtInterval");
	var strTemp = txtInterval.value;
	strTemp = trimAll(strTemp);
	var isNumber = IsNumeric( strTemp );
	args.IsValid = false;
	
    if(strTemp.length > 0 &&  strTemp < 10000   && isNumber && strTemp != "0" && strTemp > 14)
    {
		args.IsValid = true;
    }
}

function IsNumeric(strString)
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function IsLetter(strString)
{
	var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	
	strString	=	strString.toLowerCase();
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function trimAll( strValue ) 
{

 //var objRegExp = /^(\s*)$/;
	var objRegExp = new RegExp( "/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/");
    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading &amp; trailing spaces
   objRegExp =  new RegExp( "/^(\s*)([\W\w]*)(\b\s*$)/");
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function setSubjectFocus()
{
	if (document.all.trSubject.style.display != "none")
		document.all.txtSubject.focus();
}


function CheckToolbarName(source, args)
{
	var txtCompName = GetElementBySubID(document, "txtCompName");
	var strTemp = txtCompName.value;
	var isOk=true;
	if ( strTemp.charAt(0) == " "  || strTemp.charAt(strTemp.length -1 ) == " " )
	{
		txtCompName.focus();
		isOk= false;
	}
	var isFile =IsFile(strTemp)
    if( !isFile)
    {
		isOk= false;
    }
 
    var isChar =SpecificChars(strTemp,"&")
    var isChar2 =SpecificChars(strTemp,"!")
    var isChar3 =SpecificChars(strTemp,"#")
    if (!isChar || !isChar2 || !isChar3)
    {
		isOk= false;
    }
    if (!isOk)
	{
		args.IsValid = false;
		txtCompName.focus();
    }
    else
    {
    	args.IsValid = true;
    }
    		
}

function CheckPassword(source, args)
{
	var txtPassword = GetElementBySubID(document, "txtPassword");
	var strTemp = txtPassword.value;
	
	var isOk=true;
	if ( strTemp.charAt(0) == " "  || strTemp.charAt(strTemp.length -1 ) == " " )
	{
		txtPassword.focus();
		isOk= false;
		args.IsValid = false;
	}
	if (isOk)
	{
		var isFile =IsFile(strTemp)
		if( isFile)
		{
			args.IsValid = true;
		}
		else
		{
    		args.IsValid = false;
		}
 
    }
}

function CheckLiecenseAgree(source, args)
{
	var chkAgree = GetElementBySubID(document, "chkAgree");
	

	if (chkAgree.checked==true)
	{
		args.IsValid = true;
	}
	else
	{
		args.IsValid = false;
	}

}

function CheckMinChars(source, args)
{

	var txtCompName = GetElementBySubID(document, "txtPassword");

	if (txtCompName.value.length < 6 && txtCompName.value.length != 0)
	{
		args.IsValid = false;
    }
    else
    {
    	args.IsValid = true;
    }
}

function IsFile(strString)
{
	var strNotValidChars = "\/:*?<>|\\";
	var strChar;
	var blnResult = true;
	
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strNotValidChars.indexOf(strChar) != -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}


var GlobalClickedTD;

function SelectIcon(element,idSelection)
{
		//var imageTest = document.getElementById('imgtest');		
		//imageTest.src="bankimages/" + idSelection;
	var ClickedRadioId = document.getElementById("ClickedRadioId");
	ClickedRadioId.value=element.id;

	
	var upFileID = document.getElementById(upFileIdFromPage);
	upFileID.disabled =true ;
	var txtImgUrl = document.getElementById(txtImgUrlIdFromPage); 
	txtImgUrl.value=idSelection;
	
	
	//adiel:
	//call the function 'onClickRadioImageButton' to the 
	//dynamic menu component to change the image dynamically
	//it's in try-catch cause not all the pages defines it(just the dynamic menu
	//meanwhile)
	try
	{
		onClickRadioImageButton();
	}
	catch(err){}
	
}
function SelectUpload()
{
	var upFileID = document.getElementById(upFileIdFromPage);
	upFileID.disabled =false ;
	
	//function onSelectImageUpload() for the dynamic menu 
	//try-catch cause not everyone defines it!
	try
	{
		onSelectImageUpload();
	}
	catch(err){}
}

function ChangeDisplayLinkButton(radioBtn)
{
	if (radioBtn.value == "1")
	{
		EnableChoosingIcon()
	}
	else
	{
		EnableUploadIcon()
	}
}

function EnableChoosingIcon()
{
		var upFileID = GetElementBySubID(document, "upFile");
		upFileID.disabled =true ;	
} 

function EnableUploadIcon()
{
	/*xml retrieve code
	//disable all radio buttons
	//ChangeButtonsGroupsStatus(true);
	
	//hiding the "choose one of..."
	
	var ChooseIconArrowLine = GetElementBySubID(document, "ChooseIconArrowLine");
	ChooseIconArrowLine.style.display="none";		
	*/
	var upFileID = GetElementBySubID(document, "upFile");
	upFileID.disabled = false;
	//var tdOneimg= GetElementBySubID(document, "tdOneimg");
	//tdOneimg.innerHTML ="&nbsp;";
	//document.getElementById("iconsGif").useMap="";
	var txtImgUrl = GetElementBySubID(document, "txtImgUrl"); 
	txtImgUrl.value ="";
}
function ChangeColorOver()
{
	var lbl		= event.srcElement;	
	lbl.style.color ="#7DABBE";
}
function ChangeColorOut()
{
	var lbl		= event.srcElement;	
	lbl.style.color = "#10516B";
}

function CheckEmptyLinkButtonUploadImg(source, args)
{
	var radioUpload="";
	args.IsValid =true;
	/*var chk = GetElementBySubID(document, "chkboxButtonWizard"); 
	if (chk != null)
		if (!chk.checked)
			return;
	*/
	if (self.location.href.toLowerCase().indexOf("wizard.aspx") != -1) 
	{
		args.IsValid =true;
		
	/*	var radioBtn = document.getElementById("stepsComponent_btnCtls_lnkbtn_ButtonsImagesControl_radioBtn2");
		if (radioBtn.checked == true )
		{
			var upFile =document.getElementById("stepsComponent_btnCtls_lnkbtn_ButtonsImagesControl_upFile");	
			if ( upFile.value == "") 
			{	
				source.innerHTML ="<br>Either browse to an image or choose one of the existing icons";
				radioBtn.focus();
				args.IsValid =false;
			}
		}*/
		return;
	}
	else if (self.location.href.toLowerCase().indexOf("addeditsinglecontrol.aspx?mode=add") != -1)
	{
	
		source.innerHTML ="Required Field"; 
		var found= false;
		for (var i = 0 ; i < frmMain.elements.length ; i++)
		{
			if (frmMain.elements[i].type == "radio" )
			{
				if (frmMain.elements[i].checked)
				{
					if (frmMain.elements[i].id== "AddEditSingleControl_lnkBtn_ButtonsImagesControl_radioBtn2")
						radioUpload = frmMain.elements[i].id;
					found = true;
					break;
				}
			}
		}
		if (!found)
		{
			args.IsValid =false;
			return;
		}
		else
		{
			args.IsValid =true;
			if (radioUpload != "")
			{
				var upFile = document.getElementById("AddEditSingleControl_lnkBtn_ButtonsImagesControl_upFile");	
				if ( upFile.value == "") 
				{	
					source.innerHTML ="<br>Either browse to an image or choose one of the existing icons";
					document.getElementById("AddEditSingleControl_lnkBtn_ButtonsImagesControl_radioBtn2").focus();
					args.IsValid =false;
				}
				else 
				{
					if( upFile.value.toLowerCase().indexOf(".gif") != -1 ||
						upFile.value.toLowerCase().indexOf(".bmp") != -1 ||
						upFile.value.toLowerCase().indexOf(".jpg") != -1 ||
						upFile.value.toLowerCase().indexOf(".jpeg") != -1) 
					{
					}
					else
					{
						source.innerHTML ="<br>&nbsp;The selected image should be gif, bmp or jpg";
						document.getElementById("AddEditSingleControl_lnkBtn_ButtonsImagesControl_radioBtn2").focus();
						args.IsValid = false;
					}
				}
			}
			return;
		}
		
	}
/*	var radioBtn = GetElementBySubID(document, "radioBtn2");
	if (radioBtn.checked == true )
	{
		var upFile = GetElementBySubID(document, "upFile");
		if ( upFile.value == "") 
		{	
			radioBtn.focus();
			args.IsValid =false;
		}
	}
	*/	
}
function CheckEmptyButtonLink(source, args)
{
	args.IsValid =true;
	var chk = GetElementBySubID(document, "chkboxButtonWizard"); 
	if (chk != null)
		if (!chk.checked)
			return;
	var txtButtonLink	 = GetElementBySubID(document, "txtButtonLink");
	if ( txtButtonLink.value == "") 	
			args.IsValid =false;	
}			
function ShowSeperatorComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move,ComunicateId)
{		
	pos			= GetElementPosition(srcID);	
	var img		= 	document.all[srcID];

	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	
	SetSpanActionPosition(spnID, img);
	
																				//60 instead of (document.all[spnID].offsetWidth / 2)	
	document.all[deleteID].parentElement.style.display			= "inline";	
	document.all[editID].parentElement.style.display			= "none";	
	document.all[addID].parentElement.style.display				= "none";
	document.all[ComunicateId].parentElement.style.display		= "none";
	
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}
function SpecificChars(strString, chr)
{
	var blnResult = true;
	for (var i = 0; i < strString.length && blnResult == true; i++)
	{
		var strChar = strString.charAt(i);
		if (strChar == chr)
		{
			blnResult = false;
		}
	}
	return blnResult;
} 

function CountChars(source, args)
{
	args.IsValid =true;
	var chk = GetElementBySubID(document, "txtSubject"); 
	if( parseInt(chk.value.length) >= 200)
	{
		args.IsValid =false;
	}
	
}


function CountCharsTextArea(source, args)
{
	args.IsValid =true;
	var chk = document.getElementById("txtMessage"); 
	if( parseInt(chk.value.length) >= 8000)
	{
		args.IsValid =false;
	}
	
}



var carIndex = null;

function EditSearch(search , trDetails , trId , isWrongInput)
{
	if (carIndex == null)
		carIndex =trId;//.split("tr_")[1]*1;
//	alert(carIndex)

	if (html != null && (tdPanelDetails.innerHTML == "" || tdPanelDetails.innerHTML == "&nbsp;" ))
	{

		tdPanelDetails.innerHTML = '';
		var tblSearches = GetElementBySubID(document, "tblSearches");
		
		for (var i = 0 ; i < tblSearches.rows.length; i++)
		{
			var trDetails2 = tblSearches.rows[i];
			if ( trDetails2.id.indexOf("trDetails_") != -1)
			{
				trDetails2.cells[0].innerHTML ="";
			}
			var tr2 = tblSearches.rows[i];
			if ( tr2.id.indexOf("tr_") != -1)
			{
			//	if (tr2.cells[1].childNodes[0].edit == "true")
			//		return;
			//	tr2.cells[1].childNodes[0].edit = "true"
			//	document.getElementById(tr2.childNodes[1].childNodes[0].id).disabled = true;
			
				toggleLink(document.getElementById(tr2.childNodes[1].childNodes[0].id));
				toggleLink(document.getElementById(tr2.childNodes[2].childNodes[0].id));

			}
		}
		
		document.getElementById("btnAdditional").style.display = "none";

		tdDetails =	document.all[trDetails].children[0];
		tdDetails.innerHTML =html;
		
		ShowHTML()
		document.all[trDetails].style.display = "inline";
		
		var icon = search.icon 
		//if (icon == "")
		//	icon =search.IconUrl
		var caption = "" ;
		if (!isWrongInput)
		{
			document.getElementById(captionID).value =search.value;
			document.getElementById(searchEngineID).value =search.url;
			document.getElementById(prefixID).value = search.prefix;
			caption = search.value;
			document.getElementById(captionHidden).value =search.value;
			document.getElementById(searchEngineHiddenID).value =document.getElementById(searchEngineID).value//search.prefix.Substring(0, search.prefix.IndexOf("UCM_SEARCH_TERM"));//search.url;
			document.getElementById(prefixHiddenID).value = document.getElementById(prefixID).value //search.prefix.Substring( search.prefix.IndexOf("UCM_SEARCH_TERM")+15 );//search.prefix;
			document.getElementById(txtIconHiddenID).value = search.icon;
			var chk =document.getElementById(checkOldImag);
			chk.checked = true;

		}
		else
		{
			document.getElementById(captionID).value =strCaption;
			document.getElementById(searchEngineID).value =strPrefix;
			document.getElementById(prefixID).value = strPostfix;
			icon = strIconHidden;// document.getElementById(txtIconHiddenID).value ;
			//document.getElementById(txtLineNumber).value = "-1";
			caption = strCaption ;
			document.getElementById(captionHidden).value = strCaptionHidden;
			document.getElementById(searchEngineHiddenID).value = strPrefixHidden;
			document.getElementById(prefixHiddenID).value = strPostfixHidden ; 
			//document.getElementById(txtIconHiddenID).value = strIconHidden ; 
		}
		
			document.getElementById(lblTitleID).innerHTML = "Editing <span style='color:crimson'>" + caption + "</span> search engine";
		
			
		document.getElementById(imgOldID).src =icon;
		if ( document.getElementById(imgOldID).src.indexOf("search_icon.gif") == -1 
			&& document.getElementById(imgOldID).src != ""
			&& document.getElementById(imgOldID).src != null  && 
			document.getElementById(imgOldID).src != "undefined" 
			&& (document.getElementById(imgOldID).src.indexOf(".gif") != -1 ||
			 document.getElementById(imgOldID).src.indexOf(".bmp") != -1 ||
			 document.getElementById(imgOldID).src.indexOf(".jpg") != -1 ||
			 document.getElementById(imgOldID).src.indexOf(".jpeg") != -1) )
		{
			document.getElementById(imgOldID).src =icon;
			document.getElementById(checkOldImag).style.display = "inline";
			document.getElementById(imgOldID).style.display = "inline";
		}
		else
		{
			document.getElementById(checkOldImag).style.display = "none";
		//	document.getElementById(checkOldImag).checked = true;
			document.getElementById(imgOldID).style.display = "none";
		}
		
		document.getElementById(addID).onclick = SelectImageToLoadOnEdit;
		
		var chk = document.getElementById("checkPostfix")
		if (chk != null && document.getElementById(prefixID).value != "")
		{
			document.getElementById(prefixID).disabled = false;
			chk.checked = true;
		}	
		else
		{
			document.getElementById(prefixID).disabled = false;
			chk.checked = false;
		}
		
		
		document.getElementById(txtIcon).value = search.icon;
		
		var ok = true;
		if (!isOkImage)
		{
			document.getElementById("spnImage").innerHTML ="Image upload failed";
			document.getElementById("spnImage").style.display ="inline";
			ok = false;
		}
		else
		{
			document.getElementById("spnImage").innerHTML ="&nbsp;";
		}
		if (!isOkCaption)
		{
			document.getElementById("spnCaption").innerHTML ="Invalid characters<br> in search engine name";
			document.getElementById("spnCaption").style.display ="inline";
			ok = false;
		}
		else
		{
			document.getElementById("spnCaption").innerHTML ="&nbsp;";
		}
			isOkCaption =true;
			isOkImage =true;
			searchIndex =0;
			strCaption ='';
			strPrefix ='';
			strPostfix ='';
			edit =true;	
		}
		if (ok)
		{
			return true;
			
		}
		else
		{
		return false;
		}
}


function ShowAdd()
{
	if (html != null)
	{
		tdPanelDetails.innerHTML = html;
	}
	document.getElementById(addID).value = 'Done';
	document.getElementById("btnAdditional").style.display = "none";
	document.getElementById(lblTitleID).innerHTML = "New search engine properties"
}
function ShowHTML()
{
	var chk = document.getElementById("stepsComponent_searchCtl_chkboxButtonWizard"); 
	if (chk != null)
	{
		chk.disabled = true;
		chk.checked=true;
	}
	document.getElementById("trMySearchBox").style.display = "inline";
	document.getElementById(addID).onclick=CheckEmpty;
	
	var btnSave = GetElementBySubID(document, "btnSave");
	var btnBack = GetElementBySubID(document, "btnBack");
	if (btnSave == null)
	{
		btnSave =document.getElementById("stepsComponent_btnNext_lnkButton");
		btnBack =document.getElementById("stepsComponent_btnBack_lnkButton");
	}
	
	btnSave.style.display = "none";
	btnBack.style.display = "none";
	
	
}

function HideHTML()
{
	document.getElementById("trMySearchBox").style.display = "none";
	var btnSave = GetElementBySubID(document, "btnSave");
	var btnBack = GetElementBySubID(document, "btnBack");
	if (btnSave == null)
	{
		 btnSave =document.getElementById("stepsComponent_btnNext_lnkButton");
		 btnBack =document.getElementById("stepsComponent_btnBack_lnkButton");
	}
	btnSave.style.display = "inline";
	btnBack.style.display = "inline";
	document.getElementById("btnAdditional").style.display = "inline";
	
}
function Cancel()
{
	try
	{
		var chk = document.getElementById("stepsComponent_searchCtl_chkboxButtonWizard"); 
		if (chk != null)
		{
			chk.disabled = false;
			chk.checked= true;
		}
		tdPanelDetails.innerHTML = '';
		var tblSearches = GetElementBySubID(document, "tblSearches");
		
		for (var i = 0 ; i < tblSearches.rows.length; i++)
		{
			var trDetails2 = tblSearches.rows[i];
			if ( trDetails2.id.indexOf("trDetails_") != -1)
			{
				trDetails2.cells[0].innerHTML ="";
			}
			var tr2 = tblSearches.rows[i];
			if ( tr2.id.indexOf("tr_") != -1)
			{
			//	if (!document.getElementById(tr2.childNodes[1].childNodes[0].id).disabled) 
				{
					toggleLink(document.getElementById(tr2.childNodes[1].childNodes[0].id));
					toggleLink(document.getElementById(tr2.childNodes[2].childNodes[0].id));
				}
				

	//			if (tr2.cells[1].childNodes[0].edit == "true")
	//				tr2.cells[1].childNodes[0].edit = "false";
		//		document.getElementById(tr2.childNodes[1].childNodes[0].id).disabled = true;
			}
		}
		if (document.getElementById(captionID) != null)
		{
			document.getElementById(captionID).value ="";
			document.getElementById(searchEngineID).value ="";
			document.getElementById(prefixID).value = "";
			document.getElementById(txtIcon).value = "";
			document.getElementById(captionHidden).value ="";
			document.getElementById(searchEngineHiddenID).value ="";
			document.getElementById(prefixHiddenID).value = "";
			document.getElementById(txtIconHiddenID).value = "";
		}
	}
	catch(er)
	{
	}	
}

function CheckEmpty()
{
	document.getElementById("spnCaption").innerHTML = "&nbsp;"
	document.getElementById("spnName").innerHTML = "&nbsp;"
	var ok = true;
	var tblSearches = GetElementBySubID(document, "tblSearches");
	if (carIndex != null)
	{//check on edit
	
		for (var i = 0 ; i < tblSearches.rows.length; i++)
		{
			var tr2 = tblSearches.rows[i];
			if (tr2.id.indexOf("tr_") != -1 )
			{
				
				if (tr2.cells[1].childNodes[0].del  == null)
				{
					var link = tr2.cells[1].childNodes[0]
		//			alert(i + " carIndex =" + carIndex + " tr2.id =" + tr2.id )
					if ( carIndex != tr2.id )
					{
			//			alert(i + " link.value =" + link.value + " document.getElementById(carIndex).cells[1].childNodes[0].value =" +document.getElementById(carIndex).cells[1].childNodes[0].value )
			//			alert( document.getElementById(carIndex).cells[1].childNodes[0].outerHTML )
					
						if (  link.value == document.getElementById(captionID).value)
						{
							document.getElementById("spnCaption").innerHTML = "search engine name<br> already exist";
							ok = false;
						}
					}
				}
			}
		}
	}
	else
	{
		for (var i = 0 ; i < tblSearches.rows.length; i++)
		{
			var tr2 = tblSearches.rows[i];
			if (tr2.id.indexOf("tr_") != -1 )
			{
				if (tr2.cells[1].childNodes[0].del  == null)
				{
					var link = tr2.cells[1].childNodes[0]
					
					if (document.getElementById(captionID).value == link.value )
					{
						document.getElementById("spnCaption").innerHTML = "search engine name<br> already exist";
						ok = false;
					}
				}
			}
		}
	}
		
	
	if (document.getElementById(captionID).value == "" )
	{
		document.getElementById("spnCaption").innerHTML = "search engine name<br> can not be empty"
		ok = false;
	}
	
	if (document.getElementById(searchEngineID).value == "")
	{
		document.getElementById("spnName").innerHTML = "search engine string<br> can not be empty"
		ok = false;
	}
	
	if (!ok)
	{
		return false;
	}
	else
	{
		carIndex = null
		document.getElementById("spnCaption").innerHTML = "&nbsp;";
		document.getElementById("spnName").innerHTML = "&nbsp;";
		var tblSearches = GetElementBySubID(document, "tblSearches");
		if (tblSearches != null)
		{ 
			for (var i = 0 ; i < tblSearches.rows.length; i++)
			{
				var tr2 = tblSearches.rows[i];
				if ( tr2.id.indexOf("tr_") != -1)
				{
					toggleLink(document.getElementById(tr2.childNodes[1].childNodes[0].id));
					toggleLink(document.getElementById(tr2.childNodes[2].childNodes[0].id));
				}
			}
		}		
	}
	
}

function checkPrefix()
{
	var chk = document.getElementById("checkPostfix")
	if (chk != null)
	{
		if (chk.checked)
		{
			document.getElementById(prefixID).disabled = false;
			
		}
		else
		{
			document.getElementById(prefixID).disabled = true;
			document.getElementById(prefixID).value=""
		}
	}	
}

function doAddFunctions(withValues)
{

	Cancel();
	ShowAdd();
	ShowHTML();
	
	document.getElementById(checkOldImag).style.display = "none";
//	document.getElementById(checkOldImag).checked= true;
	document.getElementById(imgOldID).style.display = "none";
	//if (typeof(icon) != "undefined")
	//	if (icon != "")
	//		document.getElementById(txtOldIcon).value  = icon ; 
	if (withValues)
	{
		document.getElementById(captionID).value =strCaption;
		document.getElementById(searchEngineID).value =strPrefix;
		document.getElementById(prefixID).value = strPostfix;
		document.getElementById(captionHidden).value ="";
		document.getElementById(searchEngineHiddenID).value ="";
		document.getElementById(prefixHiddenID).value = "";
		document.getElementById(IconHiddenID).value = "";
	
	}
	if (!isOkImage)
	{
		document.getElementById("spnImage").innerHTML ="Image upload failed";
		document.getElementById("spnImage").style.display ="inline";
	}
	else
	{
		document.getElementById("spnImage").innerHTML ="&nbsp;";
	}
	if (!isOkCaption)
	{
		document.getElementById("spnCaption").innerHTML ="Invalid characters<br> in search engine name";
		document.getElementById("spnCaption").style.display ="inline";
	}
	else
	{
		document.getElementById("spnCaption").innerHTML ="&nbsp;";
	}
	isOkCaption =true;
	isOkImage =true;
    searchIndex =0;
	strCaption ='';
	strPrefix ='';
	strPostfix ='';
	edit =true;
}

function doEditFunctions()
{
	try
	{
		var trDetailsClient = GetElementBySubID(document, trDetailsClientID);
		var trClient = GetElementBySubID(document, trClientID);
		return EditSearch(anchorProperties, trDetailsClient.id,trClient.id , true);
	}
	catch(er)
	{
	
	}
}

function SelectImageToLoadOnEdit()
{
	//document.getElementById(IconHiddenID).value = "";
	var upFile = document.getElementById(upFileID);
	var imgUrl =upFile.value ;
	if (	document.getElementById(checkOldImag).style.display == "inline" &&
			document.getElementById(imgOldID).style.display == "inline" && 
			document.getElementById(checkOldImag).checked == true)
	{
		if	(imgUrl == "" ||  (imgUrl.indexOf(".gif") == -1 || imgUrl.indexOf(".bmp") == -1 ||	imgUrl.indexOf(".jpg") == -1 ||	imgUrl.indexOf(".jpeg") != -1) )
		{
			document.getElementById(IconHiddenID).value = document.getElementById(imgOldID).src;
		}
		else 
		{
			document.getElementById(IconHiddenID).value = "";
			
			
		}
	}
	edit =true;
}



function ChecFieldLength(source,args)
{
	args.IsValid = true;
	var txtToolTip = GetElementBySubID(document, "txtToolTip"); 
	if (txtToolTip.value.length  > 200)
		args.IsValid = false;
}

function ConfirmDelete()
{
	var agree=confirm("All your old messages are going to be deleted. Are you sure you wish to continue? ");
	if (agree)
		return true ;
	else
		return false ;
}



function CheckNumber(val)
{
	var retVal = true;
	if (typeof document.getElementById(val)!= "undefined")
	{
		var isOk =IsNumeric(document.getElementById(val).value )
		if (!isOk)
			retVal = false;
	}
	return retVal;
	
}
function CheckIfNumber1(source,args)
{
	args.IsValid = CheckNumber(txtWidthId);
}
function CheckIfNumber2(source,args)
{
	args.IsValid = CheckNumber(txtWidthURLId);
}
function ShowDynamicMenuComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move , ComunicateId)
{	

	pos = GetElementPosition(srcID);	
	var img = 	document.all[srcID];
	
	
	// the focus table
	var tbl = GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	SetSpanActionPosition(spnID, img)
	
	
	document.all[deleteID].parentElement.style.display	= "inline";	
	document.all[editID].parentElement.style.display	= "inline";	
	document.all[addID].parentElement.style.display	= "none";
	document.all[ComunicateId].parentElement.style.display	= "none";
	
		
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";



}

function ShowBrowserComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move , ComunicateId,isEdit )
{

	pos				= GetElementPosition(srcID);	
	var img			= 	document.all[srcID];
	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	SetSpanActionPosition(spnID, img)
	
	document.all[deleteID].parentElement.style.display	= "inline";	
	if (isEdit.toLowerCase() == "true" )
	{
		document.all[editID].parentElement.style.display	= "inline";	
	}			
	else	
	{
		document.all[editID].parentElement.style.display	= "none";	
	}
	
	document.all[addID].parentElement.style.display					= "none";
	document.all[ComunicateId].parentElement.style.display			= "none";
		
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}
function ShowAliasComponentActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, move,ComunicateId)
{		
	pos					= GetElementPosition(srcID);	
	var img				= 	document.all[srcID];
	// the focus table
	var tbl				= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width		= img.offsetWidth + TABLEACTIONSOFFSET;	
																					
	SetSpanActionPosition( spnID, img)
	
	document.all[deleteID].parentElement.style.display			= "inline";	
	document.all[editID].parentElement.style.display			= "none";	
	document.all[addID].parentElement.style.display				= "none";
	document.all[ComunicateId].parentElement.style.display		= "none";
	
    SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
    
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}


function ShowUnknownActions( srcID, spnID, editID, deleteID, moveLeftID, moveRightID ,addID, ComunicateId,move)
{		

	pos				= GetElementPosition(srcID);	
	var img			= 	document.all[srcID];
	// the focus table
	var tbl			= GetElementBySubID(document, "tblActionsFocus");
	tbl.style.width = img.offsetWidth + TABLEACTIONSOFFSET;	
	
	SetSpanActionPosition( spnID, img)	
	
	document.all[deleteID].parentElement.style.display			= "none";	
	document.all[editID].parentElement.style.display			= "none";	
	document.all[addID].parentElement.style.display				= "none";
	document.all[ComunicateId].parentElement.style.display		= "none";
	
	SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
	
	document.all[spnID].style.display	= "inline";
	tbl.style.display	= "inline";

}


function SetSpanActionsLeftPosition( spnID, img)
{

	var ofset = -3;	
	if (img.offsetWidth < parseInt(document.getElementById("tblActions").style.width))	//the width of the img is less than the width of the actions span
	{
		//offset will be a nagative number for how much to move the focus table back
		//offset is the difference between the width of the img and the actions table
		ofset =   (img.offsetWidth / 2) - (parseInt(document.getElementById("tblActions").style.width)/ 2) + 3;
	}									 
	document.all[spnID].style.left = pos.left+ofset

}


function SetSpanActionsTopPosition( spnID)
{
	var ofset = -7;	
	
	var tbl = GetElementBySubID(document, "tblToolbar");
	
	var tblPos = GetElementPosition(tbl.id);	
	
	document.all[spnID].style.top = tblPos.top+ofset
	
	
	
}

function SetSpanActionPosition( spnID, img)
{
	SetSpanActionsLeftPosition( spnID, img);
	
	SetSpanActionsTopPosition( spnID)
}


function SetMoveLeftMoveRightDisplay(moveLeftID,moveRightID,move)
{
	var moveLeftIDdisplay="none";
	var moveRightIDdisplay="none";
	if(move == 0)
	{
		moveLeftIDdisplay= "inline";	
		moveRightIDdisplay= "inline";	
		
		document.all[moveLeftID].innerText  = "Move Left";
		document.all[moveRightID].innerText = "Move Right";
	}
	if(move == 1)
	{
		moveRightIDdisplay= "inline";	
		document.all[moveRightID].innerText = "Move Right";
	}
	if(move == 2)
	{
		moveLeftIDdisplay= "inline";	
		document.all[moveLeftID].innerText  = "Move Left";
	}
	document.all[moveLeftID].parentElement.style.display	= moveLeftIDdisplay;
	document.all[moveRightID].parentElement.style.display	= moveRightIDdisplay;
} 
function FocusOnFrame()
{
	document.getElementById('ifrm').focus();
}

function CheckMinDescriptionChars(source, args)
{

	if (document.getElementById(txtDescriptionId).value.length > 50
	 && document.getElementById(txtDescriptionId).value.length != 0)
	{
		args.IsValid = false;
    }
    else
    {
    	args.IsValid = true;
    }
}

function CheckIfNumberMinutes(source,args)
{
	args.IsValid = true;
	if (typeof document.getElementById(txtNumberMinutes)!= "undefined")
	{
		var isOk =IsNumeric(document.getElementById(txtNumberMinutes).value )
		if (!isOk)//wrong type of id
		{
			args.IsValid = false;
		}
		else
		{
			 if (document.getElementById(txtNumberMinutes).value < 1 ||  document.getElementById(txtNumberMinutes).value > 60000 )	
			 	args.IsValid = false;
		}	 	
	}
}
function CheckIfNumberHours(source,args)
{
	args.IsValid = true;
	if (typeof document.getElementById(txtNumberHours)!= "undefined")
	{
		var isOk =IsNumeric(document.getElementById(txtNumberHours).value )
		if (!isOk)//wrong type of id
			args.IsValid = false;
		else
			if (document.getElementById(txtNumberHours).value < 1 || document.getElementById(txtNumberHours).value > 60000 )	
				args.IsValid = false;
	}
}


function CheckIfNumber(source,args)
{
	args.IsValid = true;
	if (typeof document.getElementById(txtWidthId)!= "undefined")
	{
		var isOk =IsNumeric(document.getElementById(txtWidthId).value )
		if (!isOk)//not number
		{
			args.IsValid = false;
			
		}
	}
}


function CheckValidWidth(source,args)
{
	args.IsValid = true;
	if (typeof document.getElementById(txtWidthId)!= "undefined")
	{
		if (document.getElementById(txtWidthId).value < 20)
		{
			args.IsValid = false;
		}
		else if (document.getElementById(txtWidthId).value >300 )
		{
			args.IsValid = false;
		}
	}
}

function CheckValidWidth2(source,args)
{
	args.IsValid = true;
	if (typeof document.getElementById(txtWidthURLId)!= "undefined")
	{
		if (document.getElementById(txtWidthURLId).value < 20)
		{
			args.IsValid = false;
		}
		else if (document.getElementById(txtWidthURLId).value >300 )
		{
			args.IsValid = false;
		}
	}
}

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	}
	 else
	{
	myField.value += myValue;
	}

}



function GetIfTxtUrlOK(source, args)
{
	var val = GetElementBySubID(document, "txtURL"); 
	if (getIFValueOK(val)== false)
	{
		val.focus();
	}
	args.IsValid = getIFValueOK( val);
}

function CheckEffectivebrand(source, args)
{
	var SearchEngine = document.getElementById(txtSearchEngineID).value
	var retVal = true;
	
	if (SearchEngine.toLowerCase().indexOf('mysearchterm') ==-1)
	{
		retVal = false;
	}
	if (SearchEngine.length == 0 )
	{
		retVal = true;
	}
	args.IsValid  = retVal;
}

function CheckIfImg(source, args)
{
	var retVal = true;
	var fileName = document.getElementById(upFileID).value;
	if (fileName.toLowerCase().indexOf('.gif') ==-1 &&
		fileName.toLowerCase().indexOf('.bmp')==-1 &&
		fileName.toLowerCase().indexOf('.jpeg')==-1 &&
		fileName.toLowerCase().indexOf('.jpg')==-1 )
	{
		retVal = false;
	}
	if (fileName.length == 0 )
	{
		retVal = true;
	}
	args.IsValid  = retVal;
}
function TryIt()
{
	var SearchEngine = document.getElementById(txtSearchEngineID).value
	
	if ( SearchEngine.length == 0)
	{
		return false;
	}
	else
	{
		var new_window = window.open(SearchEngine );
		new_window.focus();
		return false;

	}
}
function ReplaceLocation(locationTo)
{
	location.href= locationTo;
	return false;
}

function ChangeSearchEngine() 
{
	try
	{
		if (document.getElementById('search_SearchDetails_txtSearchEngine').value.length > 0)
		{
			document.getElementById('btnTry').disabled=false
		}
		else
		{
			document.getElementById('btnTry').disabled=true
		} 
	}
	catch(er)
	{
	}
}

function FocusDetails()
{
	try
	{
		document.getElementById("search_SearchDetails_btnSave_lnkButton").focus();
		
		var SearchEngine = document.getElementById(txtSearchEngineID).value
		
		if ( SearchEngine.length != 0)
		{
			document.getElementById("btnTry").disabled=false;
		}
		else
		{
		document.getElementById("btnTry").disabled=true;
		}
	}
	catch(er)
	{
	}	
}




//adding by adiel[19.5.05]
function setCookie(name,value)
{													//Gabi hapatish and mine birthday!! :-)
	document.cookie = name + "=" + value +";expires=Thu, 27 Oct 2201 15:59:28 UTC ;path=/"; 
}
function killCookie(name)
{
	document.cookie = name + "=;expires=Thu, 27 Oct 1979 15:59:28 UTC ;path=/";
}
function getCookie(name) 
{
	name += "=";
	var os; 
	var retVal=""; 
	if (document.cookie.length > 0) 
	{ 
		os = document.cookie.indexOf(name);
		if (os != -1) 
		{ 
			os += name.length; 
			end = document.cookie.indexOf(";", os); 
			if (end == -1) 
				end = document.cookie.length;
			retVal= document.cookie.substring(os, end); 
		} 
	}
	return retVal; 
}
function killAllCookies()
{
	var arrCookies = document.cookie.split(';');
	var cookieName;
	for(var i=0;i<arrCookies.length;i++)
		killCookie(arrCookies[i].split('=')[0]);
}

function killCookies(strCookieIdentifier)
{
	var arrCookies = document.cookie.split(';');
	var cookieName;
	for(var i=0;i<arrCookies.length;i++)
	{
		cookieName = arrCookies[i].split('=')[0];
		if(cookieName.indexOf(strCookieIdentifier) != -1)
			killCookie(cookieName);
	}
}
function cutSpaces(str)
{
	var cleanStr = "";
	for(var i=0;i<str.length;i++)
	{
		if(str.charAt(i) != ' ')
			cleanStr = cleanStr + str.charAt(i);
	}
	return cleanStr;

}

function CheckUrlLength(source, args,inputID)
{
	var i ;
	if (document.getElementById(inputID).value.length > 2048)
	{
		args.IsValid = false;
	}
}



function CheckCookie()
{
	
	var retVal = true;
	var my_taarich = new Date()
	//my_taarich.getTime() -Returns the number of milliseconds since midnight 1/1-1970
	//365*24*60*60*1000 - number of milliseconds of 365 days
	var dayExpires=new Date(my_taarich.getTime() + 365*24*60*60*1000)
	
	dayExpires=dayExpires.toGMTString(); // returns something like: Thu Mar 3 10:40:18 UTC+0200 2005
	
	
	SetCookie(dayExpires, dayExpires);
	
	retVal=getCookie(dayExpires);
	
	
	if (retVal == false)
	{
		location.replace('error.aspx?errorid=privacy') ;
		//location.href="error.aspx?errorid=privacy";
	}
	return retVal;
}



function SetCookie(sName, sValue)
{
	document.cookie = sName + "=" + sValue + ";;";
}





function getCookie(name)
{
	try
	{
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1)
		{
			begin = dc.indexOf(prefix);
			if (begin != 0)
			{
					return false;
			}
		}
		else
		{
			begin += 2;
		}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1)
		{
			end = dc.length;
		}
		return true;
	}	
	catch(er)	
	{
		
		return false;
	}
}



function CheckPartnersPassword(source, args,txtPasswordID)
{
	var txtPassword =	document.getElementById(txtPasswordID);
	var strTemp		=	txtPassword.value;
		
	if (strTemp.length <= 0)
	{
		args.IsValid = true;
		return;
	}
	var isOk		=	IsLetter( strTemp );
	
	if (isOk)
	{
		args.IsValid = true;
	}
    else
	{
    	args.IsValid = false;
	}
}

