//global javascript variables
	var multiPrintSongId ="";
//---------------------------
function OpenLink(link)
{
	window.location = link;
}
function newWindow(wintype)
{	
	window.open(wintype,"","toolbar=no,scrollbars=no,resizable=no,location=no,status=no,menubar=no,width=570,height=560");
}
function URLencode(sStr) 
{
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}
function ChangeVisual(elm,action)
{
	var cssClass = ( action.toLowerCase()  == "over" ? "cellSubMenuOver" : "cellSubMenu" );	
	elm.className = cssClass;
}
function ChangeVisualTopMenu(elm,action)
{
	var cssClass = ( action.toLowerCase()  == "over" ? "topMenuItemOver" : "topMenuItem" );	
	elm.className = cssClass;
}
function ChangeTopMenuItem(imgElm,action)
{
	var imgSrc = ( action.toLowerCase()  == "over" ? "img/bullet2.jpg" : "img/bullet1.jpg" );
	document.getElementById(imgElm).src = imgSrc;

}
function UpdateOrder(cbElm,itemID,level,returnElmId)
{
	var action = ( cbElm.checked ? "1" : "0");
	var url = level + "orderIFrame.aspx?itm_id=" + itemID + "&action=" + action +
	          "&retID=" + returnElmId;
	document.getElementById('orderIframe').src = url;
}

function SetHiddenCB(txtHiddenID,cb)
{
	var txt = document.getElementById(txtHiddenID);	
	txt.value = "0";
	if ( cb.checked )
		txt.value = "1";		
}
function SetValue(txtHiddenID,cbID,txtID)
{
	if ( ! document.getElementById(cbID).checked )
		document.getElementById(txtHiddenID).value = txtID.value;
	else
	{
		document.getElementById(txtHiddenID).value = "";	
	}
}
function ToggleVis(elmId)
{
	var elm = document.getElementById(elmId);
	if ( elm.style.display == 'block' )
		elm.style.display = 'none';
	else
		elm.style.display = 'block';

}
function ChangeImage(imgID,isSelected,cssClass)
{
	document.getElementById(imgID).className = cssClass;			
} 
function ToggleVisWithImage(elmId,imgID,imgSrcOpen,imgSrcClose)
{
	var elm = document.getElementById(elmId);
	var img = document.getElementById(imgID);
	if ( elm.style.display == 'block' || elm.style.display == '' )
	{
		elm.style.display = 'none';
		img.src = imgSrcClose;		
	}
	else
	{
		elm.style.display = 'block';
		img.src = imgSrcOpen;		
	}		
}
// Keywords: Numeric Digits and Period Only
// Fields that require a numeric-only style input should relate their events to this function
// ro be used as following 
// onkeypress="return checkNumeric()" 
function checkNumeric()
{
	var bReturnCode = false;
	if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 46))
		bReturnCode = true;
	else if (event.keyCode == 13)
		bReturnCode = true;
	return bReturnCode;
}
// Keywords: Numeric Number Only
// Fields that require a numeric-only style input should relate their events to this function
// ro be used as following 
// onkeypress="return NumbersOnly()" onpaste="return BlockPasteChars()"
function NumbersOnly()
{
	var bReturnCode = false;
	if (event.keyCode >= 48 && event.keyCode <= 57)
		bReturnCode = true;
	else if (event.keyCode == 13)
		bReturnCode = true;
	return bReturnCode;
}
function NumbersWithMinus() 
{

 	var bReturnCode = false;
	if (event.keyCode >= 48 && event.keyCode <= 57)
		bReturnCode = true;
	else if (event.keyCode == 13 || event.keyCode == 46 || event.keyCode == 45)
		bReturnCode = true;
	return bReturnCode;
}
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 LTrim(str) 
{
	if (str.length == 0) return str;
	for (var i=0; str.charAt(i)<=" "; i++);
	return str.substring(i,str.length);
}
function RTrim(str) 
{
	if (str.length == 0) return str;
	for (var i=str.length-1; str.charAt(i)<=" "; i--);
	return str.substring(0,i+1);
}
function Trim(str) 
{
	return LTrim(RTrim(str));
}
function CvPositiveNumbersOnly(sender, args)
{	
	args.IsValid = IsNumeric(Trim(args.Value));
}

function CvCheckAccessMaxLength(sender, args)
{	
	args.IsValid = (Trim(args.Value)).length < 255;
}
function CvCheckLength100(sender, args)
{	
	args.IsValid = (Trim(args.Value)).length < 100;
}
function CvCheckLength50(sender, args)
{	
	args.IsValid = (Trim(args.Value)).length < 50;
}
function OpenPrintDialog(sid) //Used top print 1 control when we are in song presentation mode
{
	var url='print.aspx?printCtl=' + sid+"X"+'&printVsb=no';
	window.open(url,'','width=700,height=550,scrollbars=yes,toolbar=yes,menubar=yes');
	//window.showModalDialog(url,window,'status:no;dialogWidth:700px;dialogHeight:500px;help:0;');
}


function AddSongId(checkBoxId,sid)
{
	var arr;
	if(document.getElementById(checkBoxId).checked)//adding new id to the list, if it does not exist there already
	{	
		if( document.getElementById('SongBook1_printControlsId').value.length > 0)
		{
			arr=document.getElementById('SongBook1_printControlsId').value.split("X"); 
			var notInString ="true";
			for(i=0;i<arr.length-1;i++)
			{
				if(sid==arr[i])
				{
					notInString = "false"
				}
			}
			if(notInString == "true")
			{
				 document.getElementById('SongBook1_printControlsId').value  += sid + "X"; 
			}
		}else
		{	
			document.getElementById('SongBook1_printControlsId').value += sid + "X"; 
		}
	}else //removung the id from the list of id's
	{
		document.getElementById('SongBook1_printControlsId').value=document.getElementById('SongBook1_printControlsId').value.replace(sid+"X","");
	}
	
}
function OpenMultiPrintWindow()
{
	
	if(document.getElementById('SongBook1_printControlsId').value == '')
	{
		alert("   יש לבחור שירים להדפסה   ");
	}else
	{
		var url ="Print.aspx?sid=multi&printCtl=" +document.getElementById('SongBook1_printControlsId').value;
		window.showModelessDialog(url,window,'status:no;dialogWidth:680px;dialogHeight:550px;help:0;scroll:1;');
		//window.open(url,'','width=700,height=550,scrollbars=yes,toolbar=yes,menubar=yes');
	}
}
//clear the songs selection for print 
function ClearSongsSelectionForPrint()
{
	 document.getElementById('SongBook1_printControlsId').value  = "";
}
function ToggleMenu(menu,imgId,module)
{
	if(document.getElementById)
	{
		thisMenu = document.getElementById(menu).style;
		if(thisMenu.display == "block")
		{
			thisMenu.display = "none";
			if(module == "tree")
			{
				document.getElementById(imgId).src=plus.src;
			}
			else
			{
				document.getElementById(imgId).src=subjectPlus.src;
			}
			
		}	
		else
		{
			thisMenu.display = "block";
			if(module == "tree")
			{
				document.getElementById(imgId).src=minus.src;
			}
			else
			{
				document.getElementById(imgId).src=subjectMinus.src;
			}
			
		}
		return false;
	}
	else
	{
		return true;
	}
}
function ValidEmail(email)
{
	
	invalidChars = " /:,;'";
	
	if(email != "")
	{
		for(i=0;i<invalidChars.length;i++)
		{
			var badChar = invalidChars.charAt(i);
			if(email.indexOf(badChar,0) > -1)
			{
				return false;
			}
		}
		var atPos = email.indexOf("@",1);
		
		if(	atPos == -1)
			return false;
			
		if(email.indexOf("@",atPos+1) > -1)
			return false;
		
		var periodPos = email.indexOf(".",atPos);
		
		if(periodPos == -1)
			return false;
			
		if(periodPos+3 > email.length)
			return false;
		}	
		
	return true;
	
}
function EmailAlert(emailId)
{
	var email = document.getElementById(emailId).value;
		
	if(!ValidEmail(email))
	{
		alert("כתובת הדואר האלקטרוני אינה חוקית");
		document.getElementById(emailId).focus();	
		return false;
	}
	return true;			
}
function OpenMailModalDialog(mailto)
{
	var url ="SendMail.aspx?mto=" + mailto;
	window.showModalDialog(url,window,'status:no;dialogWidth:600px;dialogHeight:520px;help:0;scroll:0;');
}
function CloseWindow()
{
	window.close();
}





