/***************************************************
 file contains javascript functions 
****************************************************/
var qoutes_char;
qoutes_char='"';
window.status='';


/**********************************************************************
 functions check_data 
 **********************************************************************/

function check_data(st,min_value,max_value)
{
var i,ch,j,z;	var checkOK = "0123456789";	var checkStr = st; var allValid = true;
z=0;
for (i = 0;  i < checkStr.length;  i++)
		{
		 ch = checkStr.charAt(i);
		 for (j = 0;  j < checkOK.length;  j++)	
			 if (ch == checkOK.charAt(j))
				break;
		  if (j == checkOK.length)
			{
			allValid = false;break;
			}
		}
if (!allValid ) {z=1}
if (st<min_value-1) {z=1}
if (st>max_value) {z=1}
return z
}

/**********************************************************************
 functions  check_date
 **********************************************************************/
	
function check_date(date_format,input_name)
{	
var ok_flag,i,run_this;
var mm,dd,yy,hour,min,sec;
if ( eval("document."+input_name+".value.length") == 19) 
{
	 if (date_format==1)
		{
		dd = eval("document."+input_name+".value.slice(0,2)");
		mm = eval("document."+input_name+".value.slice(3,5)");
		}
		else
		{
		mm = eval("document."+input_name+".value.slice(0,2)");
		dd = eval("document."+input_name+".value.slice(3,5)");
		}
		yy = eval("document."+input_name+".value.slice(6,10)");
		hour = eval("document."+input_name+".value.slice(11,13)");
		min = eval("document."+input_name+".value.slice(14,16)");
		sec = eval("document."+input_name+".value.slice(17,19)");
		if (check_data(mm,1,12) + check_data(dd,1,31) + check_data(yy,1951,2037) + check_data(hour,00,24) + check_data(min,00,59)+ check_data(sec,00,59) >0)
		{
		eval("document."+input_name+".focus();")
		}
		}
else
{
eval("document."+input_name+".focus();")
}
};

/**********************************************************************
 functions  add_to
 **********************************************************************/
function add_to(inputname,unit,max,min,action)
{
 var inp_str,delta;
 var obj=eval('document.'+inputname);
	 if ((unit.toString().indexOf(".") > 0) && (obj.value.indexOf(".") < 0))
		inp_str = unit.toString();
	 else if((unit.toString().indexOf(".") < 0) && (obj.value.indexOf(".") > 0))
		inp_str = obj.value;
	 else if((unit.toString().indexOf(".") < 0) && (obj.value.indexOf(".") < 0))
		inp_str = obj.value;
	 else if ((unit.toString().length - unit.toString().indexOf(".")) > (obj.value.length - obj.value.indexOf("."))) 
		inp_str = unit.toString();
	 else	
		inp_str = obj.value;
	 if (inp_str.indexOf(".") > 0)
		delta = Math.pow(10,inp_str.length - (inp_str.indexOf(".")+1));
	 else
		delta = 1;
	 //alert (inp_str + "    " + inp_str.indexOf(".") + "   " + delta);
	if (action=='+')
	{
			if (obj.value*delta +unit*delta<=max*delta)
			 {obj.value=Math.round(obj.value*delta+unit*delta)/delta;};};
	if (action=='-')
	{
			if (obj.value*delta -unit*delta>=min*delta)
			 {obj.value=Math.round(obj.value*delta-unit*delta)/delta;};};
	}
	
/**********************************************************************
 * functions Allow_to_enter(param_chars_to_enter)
 *************************************************
 *example:Allow_to_enter('1234567890')-you can enter only those numbers.
 *this function allow the user to enter only the keys that in the string
 *you give her.
 **********************************************************************/
 
function Allow_to_enter(param_chars_to_enter)
	{
		var isok_flag='no'; 
		var chars_to_enter;
		chars_to_enter = param_chars_to_enter.toUpperCase();
		chars_to_enter = chars_to_enter.replace('/',String.fromCharCode(111)+String.fromCharCode(191)); // replace the slashes
		for (var ii=0; ii< chars_to_enter.length;ii++)
			{
				if ((!(event.shiftKey &&( 47<event.keyCode && event.keyCode<58 ||(event.keyCode!=221 || event.keyCode!=190 || event.keyCode!=189 )))
				&&(event.keyCode==chars_to_enter.charCodeAt(ii) ||(event.keyCode==chars_to_enter.charCodeAt(ii)+48 
				&& 95<event.keyCode && event.keyCode<106)|| event.keyCode==8 || event.keyCode==37 || event.keyCode==39 
				|| event.keyCode==16 || event.keyCode==46 || (event.keyCode==190) 
				&& (chars_to_enter.charCodeAt(ii)==46) || (event.keyCode==189) && ((chars_to_enter.charCodeAt(ii)==45)) )) || event.keyCode==9 || (event.shiftKey && event.keyCode==186 && chars_to_enter.charCodeAt(ii)==58))
					
					{
						isok_flag='yes';
					};
			};
		if (isok_flag!='yes') 
			{event.returnValue =false;}
	};

/**********************************************************************
 functions Block_enter 
 ************************
 * block the Enter key in the page
 **********************************************************************/

function Block_enter() 
{
	if (event.keyCode==13)
	{
 	event.returnValue =false;
	}
	else
	{
	}
}

/**********************************************************************
 functions ifEnter(x) 
 ************************
 * If the user press the enter key we can do an action
 * example:ifEnter(alert('itsik'))
 **********************************************************************/
function ifEnter(x)
{
	if (event.keyCode==13)
		{
		eval(x);
		}
	}	

/**********************************************************************
 functions Block_Illegal_Chars (chars_to_block)
 **********************************************
 *example: Block_Illegal_Chars('1234567890')-block the nums.
 * this function block the char " or the char ' by default
 * but if you call to her with string she block those keys.
 **********************************************************************/
function Block_Illegal_Chars(chars_to_block)
{
   
	if (chars_to_block != null) 
	{
	chars_to_block=chars_to_block.toUpperCase();
		for (var i=0; i< chars_to_block.length;i++) 
		{
			if (event.keyCode==chars_to_block.charCodeAt(i))
			{
			event.returnValue =false;
			}
		}
	}
	// Yaniv #3631
	// THIS IS THE OLD IF: 
	// else if ((event.keyCode==222) || (event.shiftKey && event.keyCode==54))
	// it was changed from the following reasons- ^ (54) key shouldn't be blocked anymore.
	// 222 key ( ' and " ) should block only "
	else if ((event.keyCode==222) || (event.shiftKey && event.keyCode==54))
			{
				event.returnValue =false;
			};
}



//added by yehuda to prevent the ("<>&") chars
function Block_Illegal_Chars1(chars_to_block)
{
   
	if (chars_to_block != null) 
	{
	chars_to_block=chars_to_block.toUpperCase();
		for (var i=0; i< chars_to_block.length;i++) 
		{
			if (event.keyCode==chars_to_block.charCodeAt(i))
			{
			event.returnValue =false;
			}
		}
	}
	else if ((event.keyCode==222) || (event.shiftKey && event.keyCode==54) || (event.shiftKey && event.keyCode==55)||(event.shiftKey && event.keyCode==188)||(event.shiftKey && event.keyCode==190) )
			{
				event.returnValue =false;
			};
}

/**********************************************************************
 functions change_status_button(pic_name,status,pic_src)
 **********************************************************************/
function change_status_button(pic_name,status,pic_src)
{
	var ThisStatus
	eval ('status_of_'+pic_name+' ='+status+';');
	animation(pic_name,pic_src)
}

/**********************************************************************
 functions animation
 **********************************************************************/
function animation(pic_name,pic_src)
 {
 
document[pic_name].src=pic_src


 }

/**********************************************************************
 functions animation_Status
 **********************************************************************/
function animation_Status(pic_name,pic_src)
 {
	var ThisStatus
	eval ('ThisStatus = status_of_'+pic_name+';');
	if (ThisStatus == true)
		{document[pic_name].src=pic_src}
 }


/*****************************************************************
  function makes all the document disable 
  parameter: the form object
  example:
   if the form in the document is defined with the name FormName so
   the function should be called this way : 
           disableAllDocumentElements(document.FormName)
*******************************************************************/
function disableAllDocumentElements(formObj)
{

  for(i=0;i<formObj.elements.length  ;i++) //making all elements in the form disabled during submiting
      formObj.elements[i].disabled=true;
 
  for(i=0;i<document.images.length ; i++)    //preventing  all images to response to the event onclick
     document.images[i].onclick="return false";
  
  for(i=0;i<document.links.length;i++)       //preventing all links from responsing
  {
	//document.links[i].href = 'JavaScript:cancelLink();';
	document.links[i].onclick = cancelLink;
  } 
}

/***************************************************
Function which do NOTHING used to disable links
***************************************************/
function cancelLink () { return false; }      



/***************************************************
 trim for javascript functions 

// Add a function called trim as a method of the prototype 
// object of the String constructor.
// Use a regular expression to replace leading and trailing 
// spaces with the empty string
****************************************************/

String.prototype.trim = function()
{
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

/***************************************************
If form contains a multiple select (double select list)
select_all_multiple() function should be called before 
submit form action.
****************************************************/
function select_all_multiple()
{
	var hidden_obj;
	var sel_collect = document.all.tags('select')
	for (i=0; i<sel_collect.length; i++)
		if (sel_collect(i).multiple && sel_collect(i).name.substring(sel_collect(i).name.length-1,sel_collect(i).name.length) != '2')
		{
			hidden_obj =  eval('document.all.hidden'+sel_collect(i).name.substring(6,sel_collect(i).name.length-1)+'Values')
			hidden_obj.value = '';
			for(j=0; j<sel_collect(i).length; j++)
			{
				//sel_collect(i).options[j].selected = true;
				hidden_obj.value = hidden_obj.value + sel_collect(i).options[j].value + ',';
			}	
			hidden_obj.value = hidden_obj.value.substring(0,hidden_obj.value.length-1);
			//alert(sel_collect(i).name + '--'+hidden_obj.value);			
		}		
	 
}

/**********************************************************************
 functions Block_Non_Digits_Chars ()
 **********************************************
 *Block_Non_Digits_Chars()-block the not nums, but user still can edit text
 *example: 
 **********************************************************************/

function Block_Non_Digits_Chars()
{
	//alert(event.keyCode);
	if ((event.keyCode <48) || (event.keyCode >57))
		if ((event.keyCode !=35) && (event.keyCode !=36)&& (event.keyCode !=46)&& (event.keyCode !=45)&& (event.keyCode !=8))
			event.returnValue =false;
	/*  48-57: Numbers
		46	 : DEL
		45	 : INS
		8	 : BackSpace
		36	 : HOME
		35	 : END
	*/		
}

/**********************************************************************
 functions Block_Illigal_Paste_Chars ()
 **********************************************
 *Block_Illigal_Paste_Chars()-block the single and double quote signs when paste event occures.
 *example: 
 **********************************************************************/

function Block_Illigal_Paste_Chars() 
{
	var my_str;
	
	my_str=window.clipboardData.getData("Text");
	if (my_str.indexOf("'")>-1 || my_str.indexOf('"')>-1) 
	{
		event.returnValue = false;
	}

}

/**********************************************************************
 functions Block_Illigal_Drop_Chars ()
 **********************************************
 *Block_Illigal_Drop_Chars()-block the single and double quote signs when paste event occures.
 *example: 
 **********************************************************************/

function Block_Illigal_Drop_Chars(fieldname,length) 
{
	var my_str;
	
	my_str=event.dataTransfer.getData("Text");
	if (my_str.indexOf("'")>-1 || my_str.indexOf('"')>-1 ||  eval("document.all." + fieldname + ".value.length")+my_str.length> length)
	{
		event.returnValue = false;
	}

}


/**********************************************************************

ConfirmAction - Show are you sur message to the user and return true/false
                According to the user selections.
                
                Action - Name of the action to present to the user. default = 'delete'
                Entity - Name of the entity that the action refer to.
						 This string will be present to the user. default = 'item'                

 **********************************************************************/
function ConfirmAction(Action,Entity,Message,Scroll)
{
	if (!Message)
	{
		if (!Action) Action = 'delete';
		if (!Entity) Entity = 'item';
		Message = 'Are you sure you want to ' + Action + ' this ' + Entity + '?';
	};
	var width;
	if (Scroll=='yes')
		width = 325;
	else
		width = 305;
		
	var ret = window.showModalDialog('/common/message.asp?theMessage=' + Message + '&Buttons=yes,no&vertscroll=' + Scroll,
									 window,'status:no;dialogWidth:'+width+'px;dialogHeight:205px;help:0;');
	if (ret=='yes') {return (true) } else {return(false)};
};



/**********************************************************************
	function OpenNotification(Message,pause,status)
	display a message in a pop up with an ok button
		Message - The message string
		Pause   - If to close the window after the timeout that is specified in the preferences.
				  1 = Close (default); 0 = Wait for the user to press OK.
		Status  - 1 = Negative message (red letters); 
				  else = Positive message (blue letters - Default)
 **********************************************************************/

function OpenNotification(Message,pause,status)
{
	if (!(pause))  {pause ='0'} else pause ='1'; //change the vars to string (0/1)
	if (!(status)) {status='0'} else status='1';
	window.showModalDialog('/common/message.asp?theMessage=' + Message + 
						   '&Buttons=ok&status='+status+
						   '&pause='+pause
						   ,window,'status:no;dialogWidth:305px;dialogHeight:205px;help:0;');
}

/**********************************************************************
 functions SetRequiered(pic_name,required)
 set the stat of the icon in put_lable
 **********************************************************************/
 
function SetRequiered(pic_name,required)
{
	if (required)
	{
		document[pic_name].src='/images/requedit.gif'
	}
	else
	{
		document[pic_name].src='/images/reik2.gif'			
	};
}





/**********************************************************************
	function FnChkDragStr(RegExpMaskInstr, allowQte)
	to be used captureing the 'onDrop' event 
	- e.g.: onDrop="FnChkPstStr('[^-. \\d]', false);" will allow only -0.123456789 chars
	
	Params-
	'RegExpMaskInstr' 	- a string that contains regular expression of all permitted chars. 
						  don't enter qoute (") sign in this expression.
	'allowQte'			- true/false - qoutes(") enabled.
	
	Output- 
		If the dragged data string contains only chars from the mask- String.  
			else - nothing. 						  

 **********************************************************************/

function FnChkDragStr(RegExpMaskInstr, allowQte)
{
	var sInputTEXT = event.dataTransfer.getData("TEXT")
	var r = new RegExp (RegExpMaskInstr)
	if (sInputTEXT != null) {
		var sInputTEXT2 = sInputTEXT;
		if (allowQte) {
			sInputTEXT2= sInputTEXT.replace('"','');
			sInputTEXT= sInputTEXT.replace('"','');
			}
		else	{
			sInputTEXT= sInputTEXT.replace('"','');
			}
			
		if (sInputTEXT2 == sInputTEXT.replace(r, '')) {
				event.returnValue=true;
				return;
		}
		else	{
				event.returnValue=false;
				return;
		}
	}
}



/**********************************************************************
	function FnChkPstStr(RegExpMaskInstr, allowQte)
	check the clipboard data to fit the 'RegExpMaskInstr' mask.
	to be used captureing the 'onPaste' event 
	- e.g.: onPaste="FnChkPstStr('[^-. \\d]', false);" will allow only -0.123456789 chars
	
	Params-
	'RegExpMaskInstr' 	- a string that contains regular expression of all permitted chars. 
						  don't enter qoute (") sign in this expression.
	'allowQte'			- true/false - qoutes(") enabled.
	
	Output- 
		If the dragged data string contains only chars from the mask- String.  
			else - nothing. 						  

 **********************************************************************/

function FnChkPstStr(RegExpMaskInstr, allowQte)
{
    sInputTEXT = clipboardData.getData("TEXT")

	var r = new RegExp (RegExpMaskInstr)
	
	var sInputTEXT2 = sInputTEXT;
	if (allowQte) {
			sInputTEXT2= sInputTEXT.replace('"','');
			sInputTEXT= sInputTEXT.replace('"','');
	}
	else	{
			sInputTEXT= sInputTEXT.replace('"','');
	}
	
	if (sInputTEXT2 == sInputTEXT.replace(r, '')) {
			event.returnValue= true; 
			return;
	}
	else 	{
			event.returnValue=false;
			return;
	}
}




function FnChkKeyPrs(RegExpMaskInstr,allowQte, AllowShiftKey)
{
	var sAnchorCode = event.keyCode;
	//capture " and allow. then exit
	if ( sAnchorCode == 222 & event.shiftKey & allowQte) {event.returnValue = true; return;}
	//capture " and disallow. then exit
	if ( sAnchorCode == 222 & event.shiftKey & !allowQte){event.returnValue = false; return;} 

	//capture : and allow. then exit
	var template = /:/  ;
 	if ( sAnchorCode == 186 & event.shiftKey & template.test(RegExpMaskInstr) ) {event.returnValue = true; return;} 

	// capture and allow delete+backspace(8,46), tab(9),  arrows (35-40) and keyboard CTRL-X, CTRL-C and CTRL-V
	if (sAnchorCode == 8 || sAnchorCode == 9 || sAnchorCode == 46 ||  sAnchorCode >= 35 &&  sAnchorCode <= 40 || sAnchorCode==67 && event.ctrlKey || sAnchorCode==86 && event.ctrlKey || sAnchorCode==88 && event.ctrlKey) {
		event.returnValue = true;
		return;
	}
	else {
		if (sAnchorCode >=96 && sAnchorCode <=105) sAnchorCode= sAnchorCode -48;
		
	    sAnchorStr = String.fromCharCode(sAnchorCode);

		if (sAnchorCode == 109 || sAnchorCode == 189) 	sAnchorStr = '-';
		if (sAnchorCode == 110 || sAnchorCode == 190) 	sAnchorStr = '.';
		if (sAnchorCode == 191 || sAnchorCode == 111)   sAnchorStr = '/';
		
		var r = new RegExp (RegExpMaskInstr)
			if ((sAnchorStr == sAnchorStr.replace(r, ''))  && (!(!AllowShiftKey && event.shiftKey))) {
					event.returnValue = true;
					return;
			}
			else 	{
					event.returnValue = false;
					return;
			}
	}

}
/******************************************************************************************************************
	popuppage
******************************************************************************************************************/	
function popuppage(page,w,h)
{
	window.open(page,'','height='+h+',width='+w+',status=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,left=100,top=0');
}

/******************************************************************************************************************
	funtion AddToFav enables
******************************************************************************************************************/	
function AddToFav(url)
{
    browserName = navigator.appName;
	browserVer = parseInt(navigator.appVersion);
	if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) 
	{
      		window.external.AddFavorite(url,"e-Med.co.il");
    }
	return false;
} 
function ChangeWinStatus(strStatus)
{
	window.status = strStatus;
}

function DisableRightClick()
{
	document.onmousedown= Closepop; 
	document.oncontextmenu = function(){return false}
}

function ClosePopup(command, args)
{
	if(command=='hide'){Popuplayer.style.visibility="hidden";}
}
function ClickOnBanner(PageToOpen,LinkNum,CatID,Size)
{
	var UrlToOpen=PageToOpen + '?LinkNum='+ LinkNum + "&catid="+CatID;
	if (Size) UrlToOpen+="&size=" + Size;
	window.open(UrlToOpen,'BannerPopup')
}
function ClickOnJumpFlash(UrlToOpen)
{
	UrlToOpen="http://" + UrlToOpen;
	window.open(UrlToOpen,'BannerPopup')
}
function repositionDiv(){
    var obj = document.getElementById('Popuplayer'); // creating reference to object.
    obj.style.top = (100 + document.body.scrollTop/1) + 'px';
    //obj.style.left = (10 + document.body.scrollLeft/1) + 'px';
}
function setEvents(){
    if(document.all){
        document.getElementById('Popuplayer').style.position='absolute'; // Setting position of div to absolute
        window.onscroll=repositionDiv; // Adding onscroll event.
        window.onresize=repositionDiv; // Adding onscroll event.
    }
}
function ShowLoginForm()
{
	LoginDetDiv.style.display='block';
}
function ShowUpdateUserLink()
{
	updateUserTD.style.display='block';
	updateUserTDDown.style.display='block';
}
function LoadObject(containerID)
{
    var obj=document.getElementById(containerID);
	var tmpHTML=obj.innerHTML;
	obj.innerHTML='';
	obj.innerHTML = tmpHTML;
}
function IsIE8() {
    var returnValue = false;
    if (navigator.appName == 'Microsoft Internet Explorer') {
        returnValue = navigator.userAgent.indexOf("MSIE 8") > -1;
    }
    return returnValue;
}
function ShowHugeBanner(fileName) {
    var HostedObject = document.getElementById("HugeBanner");
    if (document.getElementById('Huge_Banner') == null) {
        if (typeof (fileName) == 'undefined') {
            fileName = logo[0].object.Movie.replace(".swf", "_Huge.swf");
        }
        HostedObject.innerHTML = GetFlashHTMLObject("Huge_Banner", 660, 200, fileName);
    }
    document.all.UpBanner.style.display = 'none';
    HostedObject.style.display = 'block';
}
function HideHugeBanner() {
    var HostedObject = document.getElementById("HugeBanner");    
    HostedObject.style.display = 'none';
    document.all.UpBanner.style.display = 'block';
}

function ShowArticleBanner(fileName) 
{
    var HostedObject = document.getElementById("spanContainer");
    if (typeof(Inside_Huge_Banner) == 'undefined') 
    {
        if (typeof (fileName) == 'undefined') 
        {
            fileName = insideFlash.object.Movie.replace(".swf", "_Huge.swf");
        }
        HostedObject.innerHTML += GetFlashHTMLObject("Inside_Huge_Banner", 300, 500, fileName);
        Inside_Huge_Banner.style.display = 'none';
    }
    insideFlash.style.display = 'none';
    if (Inside_Huge_Banner.length > 0) {
        Inside_Huge_Banner[0].style.display = 'block';
    }
    else {
        Inside_Huge_Banner.style.display = 'block';
    }
}
function HideArticleBanner() {
    if (Inside_Huge_Banner.length > 0) {
        Inside_Huge_Banner[0].style.display = 'none';
    }
    else {
        Inside_Huge_Banner.style.display = 'none';
    }
    insideFlash.style.display = 'block';
}
function ExpandBanner(HostedType, fileName) {

    switch (HostedType) {
        case "Huge":
            ShowHugeBanner(fileName);
            break;
        case "Article":
            ShowArticleBanner(fileName);
            break;
    }          
}
function CollapsBanner(HostedType, fileName) {

    switch (HostedType)
    {
        case "Huge":
            HideHugeBanner();
            break;
        case "Article":
            HideArticleBanner();
            break;    
    }
}
function GetFlashHTMLObject(id, w, h, movie) {

    var rt = '<OBJECT id="' + id + '" name="' + id + '" ' +
    'codeBase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" ' +
    'classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="' + w + '" height="' + h + '" ' +
    'type="application/x-shockwave-flash"><PARAM NAME="Movie" ' +
    'VALUE="' + movie + '"><PARAM NAME="Src" ' +
    'VALUE="' + movie + '">' +
    '    <embed ' +
    'src="' + movie + '" play="true" width="' + w + '" height="' + h + '" id="' + id + '" quality="high" ' +
    'name="' + id + '" allowScriptAccess="sameDomain" ' +
    'pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  ' +
    '></embed></OBJECT>'
    return rt;
}

function DoSearch(page, order, sql, CatID, hosted) {

    if (typeof (hosted) == "undefined")
        hosted = document;
    if (typeof (CatID) != "undefined")
        hosted.frmAdvancedSearch.CatID.value = CatID;
    if (typeof (sql) != "undefined")
        hosted.frmAdvancedSearch.AdvSQL.value = sql;
    hosted.frmAdvancedSearch.order.value = order;
    hosted.frmAdvancedSearch.page.value = page;
    hosted.frmAdvancedSearch.submit();
}
