	var ajax_dir = 'http://tms.co.il/ajax/';
	var page_url = '';
	
	function setUrl( set_url ) {
		page_url = set_url;
	}
	
	var installments_opened = false;
	function showInstallments( price ) {
		if( installments_opened != false && price == installments_opened ) {
			$('#dialog').dialog('open');
			return;
		} else if ( installments_opened != false ) {
			$('#dialog').remove();
		}
		
		var dialog = document.createElement('div');
		$( dialog ).attr('id', 'dialog');
		$( dialog ).html( ECOMLang.Loading );
		$('body').prepend( dialog );
		installments_opened = price;
		$("#dialog").dialog( { title: ECOMLang.Loading, width: 520, height: 505, resizable: false } );
		$('#dialog').show();
		$("#dialog").load( 'http://tms.co.il/payments/'+price+' #installments_title, #installments_table', function() {
			var title = $("div#installments_title").html();
			$("div#installments_title").remove();
			$('#dialog').data('title.dialog', title); 
		} );
	}
		
		function set_float_banner_rules() {
			var site_width = $('#wrapper').width();
			$(window).resize( function() { float_banner_resize(); } );
			
			$(window).scroll( function() {
				var to_scroll = $('body').scrollTop() + 10;
				$('#area_4').dequeue('fx');
				$('#area_4').animate( {'top': to_scroll + 'px'}, 'normal' );
			});
		}
		
		function float_banner_resize() {
				var site_width = $('#wrapper').width();
				var window_width = $('body').width();
				if( site_width > window_width ) {
					$('#area_4').hide();
					return;
				}
				
				var tmp_width = (window_width - site_width) / 2;
				if( $('#area_4').width() <= tmp_width )
					$('#area_4').show();
				else $('#area_4').hide();
		}
		
		function set_float_banner_rules2() {
			var site_width = $('#wrapper').width();
			$(window).resize( function() { float_banner_resize2(); } );
			
			$(window).scroll( function() {
				var to_scroll = $('body').scrollTop() + 10;
				$('#area_5').dequeue('fx');
				$('#area_5').animate( {'top': to_scroll + 'px'}, 'normal' );
			});
		}
		
		function float_banner_resize2() {
				var site_width = $('#wrapper').width();
				var window_width = $('body').width();
				if( site_width > window_width ) {
					$('#area_5').hide();
					return;
				}
				
				var tmp_width = (window_width - site_width) / 2;
				if( $('#area_5').width() <= tmp_width )
					$('#area_5').show();
				else $('#area_5').hide();
		}

			function WriteError( input_name, error ) {
				var div_id = 'error_' + input_name;
				var count = 0;
				if( obj = document.getElementById( div_id ) ) {
					if( error.length != 0 ) {
						obj.innerHTML = error;
					}
					if( obj2 = document.getElementsByName( input_name )[0] ) {
						if( obj2.type != 'checkbox' && obj2.type != 'radio' && obj2.type != 'submit' ) {
							obj2.style.background = '#fbc8ba';
							count++;
						}
					}
				} else {
					alert( error + " " + input_name );
				}
			}
			
			function AJAX() {
				var xmlhttp = false;
				try {
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
				   		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				  	} catch (ee) {
				   		xmlhttp = false;
				  	}
				}
				if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
					try {
						xmlhttp = new XMLHttpRequest();
					} catch (e) {
						xmlhttp=false;
					}
				}
				if (!xmlhttp && window.createRequest) {
					try {
						xmlhttp = window.createRequest();
					} catch (e) {
						xmlhttp=false;
					}
				}
				return xmlhttp;
			}
			
            var http_request = AJAX();
            
            function GetXml( DataToSend, url, is_return, execute_function ) {
                
                if (!http_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return;
                }
                
                http_request.open('POST', url + "?rand="+ Math.random(), true);
                http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                http_request.send( DataToSend );
                http_request.onreadystatechange = function() {
					if (http_request.readyState == 4) {
						                	alert('sap');
                    	if (http_request.status == 200) {
                    		if( is_return ) {
                    			return( http_request.responseText );
                    		} else {
                    			if( execute_function == null ) {
                    				return( http_request.responseXML );
                    			} else {
                    				eval( execute_function );
                    				return;
                    			}
                    		} 
                		} else {
                       	 	alert('There was a problem with the request.');
                       	 	return;
						}
					}
				}
            }
            
            function PrintTable2() {
                    var xmldoc = http_request.responseXML;
                    var data = xmldoc.documentElement;
                    var main_div = document.getElementById('main_div');
					var sub_div =  document.createElement("div");
					sub_div.className = 'ctable';

					if(	data.childNodes.length != 0 ) {
	                    for( var i = 0; i < data.childNodes.length; i++ ) {
                        	if( data.childNodes[i].childNodes.length > 1 && data.childNodes[i].childNodes[0].nodeName == 'menu' ) {
								var table = document.createElement("table");
								table.setAttribute('width', '100%');
								table.setAttribute('cellSpacing', '0');
                       			table.setAttribute('cellPadding', '4');
								var tbody = document.createElement("tbody");
								for( var j = 0; j < data.childNodes[i].childNodes.length; j++ ) {
									var tr = document.createElement("tr");
									if( j > 0 ) {
										if( j % 2 == 0 ) {
											tr.className = 'ctable_td';
										} else {
											tr.className = 'ctable_td2';
										}
									} else {
										tr.className = 'ctable_title';
									}
									var child = data.childNodes[i].childNodes[j];
										for( var y = 0; y < child.childNodes.length; y++ ) {
											var td = document.createElement("td");
											if( child.childNodes[y].childNodes.length != 0 ) {
												td.innerHTML = child.childNodes[y].firstChild.data;
											} else {
												td.innerHTML = '';
											}
											td.align = data.childNodes[i].childNodes[0].childNodes[y].getAttributeNode("align").value;
											td.width = data.childNodes[i].childNodes[0].childNodes[y].getAttributeNode("width").value;
											tr.appendChild(td);
										}
									tbody.appendChild(tr);
								}
								table.appendChild(tbody);
								sub_div.appendChild(table);
							} else if( data.childNodes[i].childNodes.length != 0 && data.childNodes[i].nodeName == 'nav' ) {
								var table = document.createElement("table");
								table.setAttribute('width', '100%');
								table.setAttribute('cellSpacing', '0');
                       			table.setAttribute('cellPadding', '4');
								var tbody = document.createElement("tbody");
								var tr = document.createElement("tr");
								tr.className = 'ctable_pages';
								var td = document.createElement("td");
								td.innerHTML = data.childNodes[i].firstChild.data;
								td.setAttribute('align', 'center');
								tr.appendChild(td);
								tbody.appendChild(tr);
								table.appendChild(tbody);
								sub_div.appendChild(table);
							}
                        }
					main_div.innerHTML = '';
                    main_div.appendChild(sub_div);
					} else { alert('The XML file is empty!'); return 0; }
            }
            
            function alertContents() {
            			var count = 0;
                        var xmldoc = http_request.responseXML;
                        var data = xmldoc.documentElement;
                        	for( var count = 0; count < data.childNodes.length; count++ ) {
                        		if ( data.childNodes[count].childNodes.length != 0 ) {
                        			var content = data.childNodes[count].childNodes[0].data;
                        		} else {
                        			var content = '';
                        		}
                        		var element_id = data.childNodes[count].getAttribute('name');
                        		
                        		if( obj = document.getElementsByName(element_id)[0] ) {
                        		switch( obj.tagName ) {
                        			case 'INPUT':
                        				 switch( obj.type ) {
                        				 	case 'checkbox':
                        				 		var temp = document.getElementsByName(element_id);
                        				 		for (var i=0; i<temp.length; i++) {
													if ( temp[i].value == content ) {
														temp[i].checked = true;
													}
                        						}
                        				 		break;
                        				 	case 'radio':
                        				 		var temp = document.getElementsByName(element_id);
                        				 		for (var i=0; i<temp.length; i++) {
													if ( temp[i].value == content ) {
														temp[i].checked = true;
													}
                        						}
                        				 		break;
                        				 	case 'file':
                        				 		if( content != '' ) {
                        				 			if( fileobj = document.getElementById('file_' + element_id) ) {
                        				 				fileobj.innerHTML = '<a href="'+ content +'" target="_blank">ן¿½ן¿½ן¿½ ן¿½ן¿½ן¿½ן¿½ ן¿½ן¿½ן¿½ן¿½</a>';
                        				 			}
                        				 		}
                        				 		break;
                        				 	default:
                        				 		obj.value = content;
                        				 }
                        				break;
                        			case 'SELECT':
                        				for (var i=0; i<obj.length; i++) {
											if ( obj.options[i].value == content ) {
												obj.options[i].selected = true;
											}
                        				}
                        				break;
                        			case 'TEXTAREA':
                        				obj.innerHTML = content;
                        				break;
                        		}
                        		} else { alert('Cannot find input name: '+ element_id); }
                        }
            }
				
			function CatShowHide(DivName) {
				
				var obj = document.getElementById('cat_'+DivName);
				var divs = obj.getElementsByTagName('DIV');
				var spans = obj.getElementsByTagName('SPAN');
				for( var i = 0; i < divs.length; i++){
					divs[i].style.display = divs[i].style.display == "none" ? "" : "none"
				}
				for( var i = 3; i < spans.length; i++){
					spans[i].style.display = spans[i].style.display == "none" ? "" : "none"
				}
			}
				
				var start=new Date();
				start=Date.parse(start)/1000;
				var myRef="";
				var counts = 0;
				function setUrl(ref) {
					myRef=ref;	
				}
				function setCounts(mycount) {
					counts = mycount;	
				}
			
				function CountDown( ){
					var now=new Date();
					now=Date.parse(now)/1000;
					var x=parseInt(counts-(now-start),10);
					document.getElementById("myclock").innerHTML = x;
					if(x>0){
						timerID=setTimeout("CountDown()", 100)
					}else{
						location.href=myRef;
					}
				}

				function SliceSH( name, stext, htext ) {
					var sh_link = document.getElementById( name + '_sh_link' );
					if( obj = document.getElementById( name + '_sh' ) ) {
						var new_id = name + '_hs';
						while( obj = document.getElementById( name + '_sh' ) ) {
							obj.style.display = 'block';
							obj.id = new_id;
						}
						sh_link.innerHTML = htext;
					} else if( obj = document.getElementById( name + '_hs' ) ) {
						var new_id = name + '_sh';
						while( obj = document.getElementById( name + '_hs' ) ) {
							obj.style.display = 'none';
							obj.id = new_id;
						}
						sh_link.innerHTML = stext;
					} else {
						return;
					}
				}
				
				function enlargeImage( product_id ) {
					var url = "/product/"+product_id+"/enlarge";
					window.open( url, "", "resizable=1,HEIGHT=200,WIDTH=200");
				}
				
function copy_clip(meintext)
{
 if (window.clipboardData) 
   {
   
   window.clipboardData.setData("Text", meintext);
   
   }
   else if (window.netscape) 
   { 
   
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   

   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   

   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
      trans.addDataFlavor('text/unicode');
   
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   return false;
}