











function LPad(ContentToSize,PadLength,PadChar)
			  {
			
			     var PaddedString=ContentToSize;
			     for(i=ContentToSize.length+1;I<=PadLength;i++)
			     {
			         PaddedString=PadChar+PaddedString;
			     }
			     return PaddedString;
			  }


$(document).ready(function(){

	/*$('input[type=checkbox],input[type=radio]').prettyCheckboxes();*/
			//remove opencms from all the urls
			$("a[href*='/opencms/']").each(function () { 
				//alert($(this).attr("href").replace('/opencms/','/'));
				var newurl=$(this).attr("href").replace('/opencms/','/');
				$(this).attr("href",newurl);
			});
			
			$('.slide').hide();
			
			$('.nav2 ul ul').hide(0);
			$('.nav2 ul li').hover(function(){
				$(this).find('ul').show(0);
			}, function(){
				$(this).find('ul').hide(0);			
			});
			
			
			$('img.clicktocall').hover(function(){
				$(this).attr('src', '/opencms/system/modules/com.on.template/resources/css/img/el/click_hover.png');
				
			}, function(){
				$(this).attr('src', '/opencms/system/modules/com.on.template/resources/css/img/click.png');
						
			});
	
			$('#talk').hide(0);
			
			$('#clicktocall h3').toggle(function(){
				$('#talk').show(100);
			}, function(){
				$('#talk').hide(100);
			})
			


			$('.product:last, .block:last').addClass('last');


			$('#contact_list2').hide(0);
			
			$('#dsubmit').toggle(function(){
				$('#contact_list2').show(0);
			}, function(){
				$('#contact_list2').hide(0);
			})
			
			$('.slider span').toggle(function() {
				$(this).parent().find('.slide').show();
			}, function() {
				$(this).parent().find('.slide').hide();
			})
			
			$('#product .actions .more').click(function() {
				$('#product .body').slideDown(200, "easeInCirc");
				
			})
			
			$('#product .delete').click(function() {
				$('#product .body').hide(200, "easeOutCirc");
			})
			
			$('#faq_category').change(function() {
				window.location = $(this).find('option:selected').val();
			})
			
			
			$('#goon input').change(function(){
				if ($(this).val()==''){
					$('#clock').empty().hide();
				}
			})
			
			
			 var src = $('#ecode').attr('title');
			
				$('#ecode').tooltip({
				 delay: 0,
				 showURL: false,
				 bodyHandler: function() {
					return $("<img/>").attr("src", src);
				
				}
				 }); 				 
				
			
			
			/*enableDrag();*/
			
			$(".carouselholder").jCarouselLite({
		        btnNext: ".next",
		        btnPrev: ".prev",
		        circular:false,
		        visible: 4,
		        mouseWheel: true,
		        easing: "easeOutCirc",
		        scroll:1,
		        speed: 300
		    });
		
	
	
	$('.ui-dialog-titlebar-close, #product .body .detail .delete, ').tooltip();	
			
	/*$('.next, .prev').click(function(){
					enableDrag();
			})
			
			Drag 'n Drop Compared Products
			function enableDrag(){
				$('.carouselholder .description').draggable({ 
					helper: 'clone',
					revert: 'invalid',
					cursor: 'move',
					zIndex: 3000,
					appendTo: 'body'
	 			});
				
				
			}*/
			
			/*$('#compared').droppable({
				accept: 'li:not(".active") .description',
				drop: function(ev, ui){
					showItem(ui.draggable);
				}
			});
			
			var del = "<div class='delete'>&nbsp;</div>"; 
			$compare = $('#compared');
			function showItem($item) {
				if ($('#compared .description').length<3){
					
					$.post("http://192.168.244.71/opencms/system/modules/com.on.template/elements/addProductToCompare.jsp", {productUrl: $item.find('input').val()} ,function(){
						alert($item.find('input').val());					
					} );

					
					$item.parent().parent().addClass('active');
					
					$item.clone().fadeOut(function() {	
					$item.clone().appendTo($compare).fadeTo(200, .3 , function() {
						$(this).animate({ opacity: 1 }, 400);
						$(this).append("<div class='delete'>&nbsp;</div>");
						$(this).find('.delete').click(function(){
							$.post("http://192.168.244.71/opencms/system/modules/system/modules/com.on.template/elements/addProductToCompare.jsp", {id: $(this).parent().attr('id')} ,function(){
								$item.parent().parent().removeClass('active');				
							} );
							$item.parent().parent().removeClass('active');
							$(this).parent().fadeOut(200).hide(500, function(){
									$(this).remove();
							});
						})
					});
				});
				}
			}*/
			
			
			
			
			
			
			
			
			
			
			
			
			
			function isCompareable(prod){
				
				var ok='true';
				$('#compared .description').each(function(i){
					if ($(this).find('input').val()==prod){
						ok='false';
						return false;
					}else{
						ok='true';
						return;
					}
				
				})
				if(ok=='false'){
				 return false;
				}else{
					if ($('#compared .description').length<3){
						return true;
					}else{
						return false;
					}
				}
			}
			
			
			
			function isScompareable(prod){
			var ok='true';
				$('#scompared .description').each(function(i){
					if ($(this).find('input').val()==prod){
						ok='false';
						return false;
					}else{
						ok='true';
						return;
					}
				
				})
				if(ok=='false'){
				 return false;
				}else{
				 	if ($('#scompared .description').length<3){
						return true;
					}else{
						return false;
					}
				}
			}


			
			
			$('.compare').click(function(){
				var path=$(this).parent().find('input').val();
				if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
				if (isCompareable(path)){
					
					$(this).parent().addClass('active');
					$.post("/opencms/system/modules/com.on.template/elements/addProductToCompare.jsp", {productUrl: $(this).parent().find('input').val()} ,function(){
						getCompared();					
					} );	
				}
			})
			
			$('.compare2').click(function(){
				var path=$(this).parent().parent().find('input').val();
				if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
			if (isCompareable(path)){
				$('#featured li').each(function(){
					if ($(this).find('input').val()==path){
						$(this).addClass('active');
					}
				})
			
				$.post("/opencms/system/modules/com.on.template/elements/addProductToCompare.jsp", {productUrl: $(this).parent().parent().find('input').val()} ,function(){
					getCompared();					
				} );	
			}
			})
			
			
			getCompared();
			function getCompared(){
				$.post("/opencms/el/compared.html" ,function(data){
						
							$('#compare #compared').empty();
							$('#compare #compared').append(data);	
							$('#compare .delete').tooltip();
						$('#compared .description .delete').click(function(){
							var title = $(this).parent().find('img').attr('alt');
							
							$('#showroom li .buy').each(function(i){
								if ($(this).attr('alt')==title){
									$(this).parent().removeClass('active');
								}
							})
							
							$(this).parent().fadeOut(600);
							
							removeCompared($(this).parent().attr('id'));
							
						})	
								
				} );
			}
			
			
			
			
			
			function removeCompared(id){
				$.post("/opencms/system/modules/com.on.template/elements/addProductToCompare.jsp", {id: id } ,function(){	
					
						getCompared();					
				} );
			}
			
			
			
			function compare(){
				$.post("/opencms/el/comparison.html" ,function(data){
					if (data !=''){
						$('#compare_dialog').html(data);
						$('#compare_dialog').dialog('open');
						
					}
					return false;
				} );
			}
			
			
			$('#add_to_compare').click(function(){
				if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
				compare();
			})
			
			
			
			
			
			
			
			
			
			
			
			/*Soho compare*/
			$('.scompare').click(function(){
			if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
			if (isScompareable($(this).parent().find('input').val())){
				$(this).parent().addClass('active');
				$.post("/opencms/system/modules/com.on.template/elements/addSohoToCompare.jsp", {sohoUrl: $(this).parent().find('input').val()} ,function(){
					getSohoCompared();					
				} );	
			}
			})
			
			$('.scompare2').click(function(){
				var path=$(this).parent().parent().find('.description input').val();
				if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
				if (isScompareable(path)){
				
				$('#featured li').each(function(){
					if ($(this).find('input').val()==path){
						$(this).addClass('active');
					}
				})
				$.post("/opencms/system/modules/com.on.template/elements/addSohoToCompare.jsp", {sohoUrl: $(this).parent().parent().find('input').val()} ,function(){
					getSohoCompared();					
				} );	
				}
			})
			
			
			getSohoCompared();
			function getSohoCompared(){
				$.post("/opencms/el/scompared.html" ,function(data){
						
							$('#scompare #scompared').empty();
							$('#scompare #scompared').append(data);	
							$('#scompare .delete').tooltip();
						$('#scompared .description .delete').click(function(){
							var title = $(this).parent().find('img').attr('alt');
							
							$('#showroom li .description img').each(function(i){
								if ($(this).attr('alt')==title){
									$(this).parent().parent().parent().parent().removeClass('active');
								}
							
							})
							
							$(this).parent().fadeOut(600);
							
							removeSohoCompared($(this).parent().attr('id'));
							
						})	
								
				} );
			}
			
			
			
			
			
			function removeSohoCompared(id){
				$.post("/opencms/system/modules/com.on.template/elements/addSohoToCompare.jsp", {sid: id } ,function(){	
					
						getSohoCompared();					
				} );
			}
			
			
			
			function scompare(){
				$.post("/opencms/el/scomparison.html" ,function(data){
					if (data !=''){
						$('#compare_dialog').html(data);
						$('#compare_dialog').dialog('open');
						
					}
					return false;
				} );
			}
			
			
			$('#add_to_scompare').click(function(){
				if (parseInt($('#product .body').css('height'))>0){
					$('#product .body').slideUp(50);
				}
			
				scompare();
			})
			
			
			/*Soho compare*/
			
			
			
			
			
			
			
			
			
			
			
			$('#compare_dialog').dialog({
				autoOpen: false,
				width: 1100,
				modal: true,
				position: ['center', 20]

			});
			
			
			
			
			$('#showroom .product').hover(function(){
				$(this).find('.loader').animate({
					width: 180
				  }, 400, 'easeInOutCubic');
			}, function(){
				$(this).find('.loader').animate({
					width: 0
				  }, 100);
			})
			
			
			$('#compare li .box .compare, #compare li .box .scompare').hover(function(){
				$(this).addClass('hover');
			}, function(){
				$(this).removeClass('hover');
			})
	
	
			
			
			function pad(number, length){
			   var str = "" + number;
			   while(str.length<length){
			      str = '0'+str;
			   }
			   return str;
			}
			
		
			$('.hours, .minutes').val('00');
			
			$('.up').click(function(){
				var timeval = parseInt($(this).parent().prev().find('input').val(), 10);
				var new_timeval = timeval+1;
				new_timeval = pad(new_timeval,2);
				if ($(this).parent().prev().find('input').attr('class')=='minutes'){
					if(new_timeval=='60'){
						new_timeval='00';
					}
				}else{
					if(new_timeval=='24'){
						new_timeval='00';
					}
				}
									
					$(this).parent().prev().find('input').val(new_timeval);
						
				
				
			})
			
			$('.down').click(function(){
				var timeval = parseInt($(this).parent().prev().find('input').val(), 10);
				if (timeval>0){
					var new_timeval = timeval-1;
					new_timeval = pad(new_timeval,2);
					$(this).parent().prev().find('input').val(new_timeval);
				}
				
			})
			
			/*Web Self Care  */
			
			
			
			function handleEnter(event, i_form) {
			 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
			 if (keyCode == 13) {
			   i_form.submit();
			 }
			}
			
			function handleEnter2(event) {
			
			 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
			 if (keyCode == 13) {
			   checkNetAvailability();
				return;
			 }
			}
			
			function enterWSC(){
			    
			    var userField=document.getElementsByName('username');
			    var user = '';
			    if ( userField.length == 2 )
			     user = userField[1].value;
			    else user = userField[0].value; 
			    var pass=document.getElementById('password').value;
			    
			    if ( user=='' || pass==''){
			        
			            alert(document.getElementById('userpassLabel').value);
			        
			        return;
			    }//
			
			    document.wsc.submit()
			}
			
			/*Web Self Care  */
			
			
			
			
})


