// JavaScript Document
var container; 
/** input value **/
function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

$(window).load(function() {
  // Handler for .load() called.


	var slide_val;
var sliderID;
	var allSliders=$('.showcase > ul > li');
		$('.showcase > ul > li').bind("mouseenter",function()
			{
				sliderID=$(this).attr('id');
		slide_val=setTimeout(function(){
			$('.'+sliderID).css({'opacity':'1'});
			if($('#'+sliderID).attr('id')=='main-bg1'){
				$('.main-bg2,.main-bg3,.main-bg4').stop().animate({"opacity": "0"}, 100);
			}
			else if($('#'+sliderID).attr('id')=='main-bg2'){
				$('.main-bg1,.main-bg3,.main-bg4').stop().animate({"opacity": "0"}, 100);
			}
			else if($('#'+sliderID).attr('id')=='main-bg3'){
				$('.main-bg1,.main-bg2,.main-bg4').stop().animate({"opacity": "0"}, 100);
			}
			else if($('#'+sliderID).attr('id')=='main-bg4'){
				$('.main-bg1,.main-bg2,.main-bg3').stop().animate({"opacity": "0"}, 100);
			}
			else if($('#'+sliderID).attr('id')=='main-bg5'){
				$('.main-bg1,.main-bg2,.main-bg3,.main-bg4').stop().animate({"opacity": "0"}, 100);
			}
		$('#'+sliderID).find('.hover-img').stop().animate({"opacity": "0"}, 400);
		//$('#'+sliderID).find('.slide-content').animate({"min-height": "175"}, 400);//commented to stop sliding
				},200);
			});
		$('.showcase > ul > li').bind("mouseleave",function()
			{
				if(slide_val)
				clearTimeout(slide_val);
				
				$(this).find('.hover-img').stop().animate({"opacity": "1"}, 400);
				/*$('#mainbg > .main-bg1').stop().animate({"opacity": "1"}, 400); commented on 11/11/2011 to stop changeing image to default imgage on home page*/
				//$(this).find('.slide-content').animate({"min-height": "0"}, 400)//commented to stop sliding
			});

});


$(document).ready(function()
{


	// Select option
	$(function(){
	designerSelect(); 
	$('select.designer').css({'opacity':'0'});
	});
	function designerSelect(){
		$("select.designer").change(function () {
			var ds1 = "";
			var deId = this.id;
			$("#"+ deId +" option:selected").each(function () {
				ds1 = $(this).text();
			});
			$(this).prev().text(ds1);
		}).change(); /* When start develpoment please remove ".change()" of this line*/
	}

	/* Main Background :start*/
	$('div#mainbg img').width($(window).width());
	$('div#mainbg img').height($(window).height());
		$(window).resize(function()
		{
			$('div#mainbg img').width($(window).width());
			$('div#mainbg img').height($(window).height());
		});

	/* Showcase slideDiv & Background Change on Hover */

	
	/* Sign-up, Login DropDown & Logout*/
	$('.open-login-registration-form').click(function(){
		if(!$('.drop-down').is(":visible"))
		{
			$('.drop-down').fadeOut();
			//$(this).parent().children('.drop-down').fadeIn(); //commented on 6 Sept
			$('.drop-down').fadeIn();//added on 6 Sept
			$(this).parent().addClass('select');
		}
		else
		{
			$('.drop-down').fadeOut();
			$(this).parent().removeClass('select');
		}
	});
	$('.open-login-registration-form').click(function(){
		if($('.forgot-pwd').is(":visible"))
		{
			$('.forgot-pwd').fadeOut();
		}
	});
	$('#forgot-pwd').click(function(){
		if(!$('.drop-down').is(":visible"), !$('.forgot-pwd').is(":visible"))
		{
			$('.forgot-pwd').fadeIn();
			$('.drop-down').fadeOut();
		}
		else
		{
			$('.drop-down').fadeOut();
		}
	});
	$('.back-bt').click(function(){
			if(!$('.drop-down').is(":visible"))
	
			{
				$('.drop-down').fadeIn();
				$('.forgot-pwd').fadeOut();
			}
			else
			{
				$('.forgot-pwd').fadeOut();
			}
		});
	$('#send-request').click(function(){
		 if(!$('.forgot-pwd').is(":visible"))
		{
			$('.forgot-pwd').fadeOut();
			$('.open-login-registration-form').parent().removeClass('select');
		}	
		else
		{
			$('.forgot-pwd').fadeOut();
			$('.open-login-registration-form').parent().removeClass('select');
		}
		});
	
	$('#logout').click(function(){
		 if($('.top-drop-menu > ul > li:hover > a#logout + .logout').is(":visible"))
		{
			$('.top-drop-menu > ul > li:hover > a#logout + .logout').fadeOut();
			$(this).parent().removeClass('select');
		}	
		else
		{
			$('.top-drop-menu > ul > li:hover > a#logout + .logout').fadeIn();
			$(this).parent().addClass('select');
		}
		});
	
/* Sign-up, Login DropDown & Logout End*/






//home page accrodion script
			$('.collapse-region > .collapse-tab > .title a').click(function(){
							if($(this).parent().parent().next().is(":visible"))
							{
							$(this).parent().parent().next().slideUp(800);
							$(this).removeClass('minus').addClass('plus');
							$(this).parent().parent().next().children('#collapse-div').css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0.0},100);
							}
							else
							{
							$(this).parent().parent().next().slideDown(800);
							$(this).removeClass('plus').addClass('minus');
							$(this).parent().parent().next().children('#collapse-div').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0},2000);
							}
			});


//List view & Grid view
			$('.list-view > a').click(function(){
							if($('.grid-view-content').is(":visible"))
							{
								$('.list-view-content').show();
								$('.grid-view-content').hide();
								$('.thumb-view > a').removeClass('select');
								$('.list-view > a').addClass('select');
								}
			});
			$('.thumb-view > a').click(function(){
							if($('.list-view-content').is(":visible"))
							{
								$('.grid-view-content').show();
								$('.list-view-content').hide();
								$('.list-view > a').removeClass('select');
								$('.thumb-view > a').addClass('select');
								}
			});
//Left accordian menu
			$('.left-nav-accrodion > li > a').click(function(){
					   if($(this).next().is(":visible"))
					    {
						   $(this).next().slideUp();
						   $(this).removeClass('minus').addClass('plus');
						}
					   else
						{
						   $(this).next().slideDown();
						   $(this).removeClass('plus').addClass('minus');
						}
					   
			 });

			

			$(".left-top-menu ul.ul1 li a").click(function(){
				$(".drm").removeClass('select');
				$(this).addClass('select');
				
			
			});		
// MANAGE MY ACCOUNT
			$('#edit-email').click(function(){
				
				$('#name').removeAttr('disabled');
				$('#name').addClass('enabletextfield');
				$('#email').removeAttr('disabled');
				$('#email').addClass('enabletextfield');
			
				$('#change-pwd-cancel').trigger('click');
				
				$('#edit-email').hide();
				$('#save-email').show();
				$('#cancel-email').show();
				
				
			});

			$('#cancel-email').click(function(){
				
			
				$("#name").attr("disabled", "disabled"); 
				$('#name').removeClass('enabletextfield');
				$("#email").attr("disabled", "disabled"); 
				$('#email').removeClass('enabletextfield');

				$('#edit-email').show();
				$('#save-email').hide();
				$('#cancel-email').hide();
				
				
				var nm = $("#uname").val();
				$("#name").val(nm);
				
				var em = $("#uemail").val();
				$("#email").val(em);
				
				
			});

			



			
			$('#change-pwd').click(function(){
				
				frm=document.forms.mainform1;
				frm.oldpw.defaultValue='';
				
				$('#oldpw').val('');
				$('#newpw').val('');
				$('#newpw2').val('');
				$('#cancel-email').trigger('click');

				$('.acc-tab td:first-child + td + td a').hide()
				$('.content-submit, #change-pwd-row + tr, #change-pwd-row + tr + tr').show();
				$(this).parent().parent().find('.textfield').removeAttr('disabled');
				$(this).parent().parent().addClass('change-pwd');
			
			});
			
			$('#change-pwd-cancel').click(function(){
					$('#oldpw').val('******');			
					$('.content-submit, #change-pwd-row + tr, #change-pwd-row + tr + tr').hide();
					$('#change-pwd-row').find('.textfield').attr('disabled', true);
					$(this).parent().parent().parent().find('.change-pwd').removeClass('change-pwd');
					$('#change-pwd').show();
					$('#edit-email').show();
					

					

					
					/*$('.content-submit, #change-pwd-row + tr, #change-pwd-row + tr + tr').hide();
					$('.acc-tab td:first-child + td + td a ').show();
					$(this).parent().parent().parent().find('.change-pwd').removeClass('change-pwd');
					$('#change-pwd-row').find('.textfield').attr('disabled', true);*/
			});
		
			$('#change-pwd-cancel').parent().parent().parent().parent().parent().parent().find('.title').click(function(){
					$('.content-submit, #change-pwd-row + tr, #change-pwd-row + tr + tr').hide();
					$('.acc-tab td:first-child + td + td a').show();
					$(this).parent().parent().parent().find('.change-pwd').removeClass('change-pwd');
			});
			
// VIEW PAST ORDERS
			  $('.vporder-tab tr:even, .status-left .tab3 tr:odd').addClass('table-f6');
			  $('.status-left .tab3 tr:even').addClass('table-ff');

//	VIEW MY ORDER STATUS
			$('#view-order-status').click(function(){
					$('.order-status').fadeIn();
					$(this).parent().parent().parent().parent().addClass('bgf6');
			});
			
//	MANAGE ADDRESS
			$('#edit-add').click(function(){
			if($(this).parent().parent().parent().find('.textfield').attr('disabled', true))
			{
				$(this).parent().parent().parent().find('.textfield, .designer').removeAttr('disabled');
				$(this).parent().parent().parent().find('.textfield').addClass('enabletextfield');
				$(this).parent().parent().parent().find('.dd-text').addClass('selectenable');
				$('#save-add, #cancel-add').show()
				$(this).hide()
			}
			});
			
			$('#cancel-add').click(function(){
			if($(this).parent().parent().parent().find('.textfield').attr('disabled', false))
			{
				$(this).parent().parent().parent().find('.textfield, .designer').attr('disabled', true);
				$(this).parent().parent().parent().find('.enabletextfield').removeClass('enabletextfield');
				$(this).parent().parent().parent().find('.selectenable').removeClass('selectenable');
				$('#save-add, #cancel-add').hide()
				$('#edit-add').show()
				$('.error-region').hide();
			}
			});
			
//	PRODUCT VIEW PAGE
	var allFeatures=$('.opt-feature').children('li');
	allFeatures.each(function(i){
		var j=i+1;
		var numToCheck=j%3;
		if(numToCheck==0){
			$(this).css('border','none');
			$(this).addClass('right-tooltip');
		}
	});
	
	$('.imagesView').click(function(){
			if($(this).parent().parent().parent().children('#videoView').is(":visible") || $(this).parent().parent().parent().children('#downloadView').is(":visible") )
			{
				$(this).parent().parent().parent().children('#videoView').fadeOut();
				$(this).parent().parent().parent().children('#downloadView').fadeOut();
				$(this).parent().parent().parent().children('#imagesView').fadeIn();
				$(this).parent().parent().parent().find('iframe > html').fadeOut();
				$(this).parent().parent().find('.videoView').removeClass('active');
				$(this).parent().parent().find('.downloadView').removeClass('active');
				$(this).addClass('active');
			}
			});
	
	$('.videoView').click(function(){
									
			if($(this).parent().parent().parent().children('#imagesView').is(":visible") || $(this).parent().parent().parent().children('#downloadView').is(":visible"))
			{
				$(this).parent().parent().parent().children('#imagesView').fadeOut();
				$(this).parent().parent().parent().children('#downloadView').fadeOut();
				$(this).parent().parent().parent().children('#videoView').fadeIn();
				$(this).parent().parent().parent().find('iframe > html').fadeIn(500);
				$(this).parent().parent().find('.imagesView').removeClass('active');
				$(this).parent().parent().find('.downloadView').removeClass('active');
				$(this).addClass('active');
			}
			else
			{
				$(this).parent().parent().parent().children('#videoView').fadeIn()
				}
			});

	$('.downloadView').click(function(){
									
			if($(this).parent().parent().parent().children('#imagesView').is(":visible") || $(this).parent().parent().parent().children('#videoView').is(":visible"))
			{
				$(this).parent().parent().parent().children('#imagesView').fadeOut();
				$(this).parent().parent().parent().children('#videoView').fadeOut();
				$(this).parent().parent().parent().children('#downloadView').fadeIn();
				$(this).parent().parent().parent().find('iframe > html').fadeIn(500);
				$(this).parent().parent().find('.imagesView').removeClass('active');
				$(this).parent().parent().find('.videoView').removeClass('active');
				$(this).addClass('active');
			}
			else
			{
				$(this).parent().parent().parent().children('#videoView').fadeIn()
				}
			});

	/* Car computer product Hover */
	var slide_value;
	var allSlidersp=$('.product-showcase > li');
	allSlidersp.each(function(i){
		$(this).attr('id','pruductList'+i);
	});
	$('.product-showcase > li').bind("mouseenter",function()
			{
				var sliderIDP=$(this).attr('id');
		slide_value=setTimeout(function(){
		$('#'+sliderIDP).find('.detail-content').slideDown(1000);
		$('#'+sliderIDP).find('.img1').stop().animate({"opacity": "0"}, 400);
				},200);
			});
	$('.product-showcase > li').bind("mouseleave",function()
			{
				if(slide_value)
				clearTimeout(slide_value);
				$(this).find('.detail-content').slideUp(1000);
				$(this).find('.img1').stop().animate({"opacity": "1"}, 400);
		});
	
	/* Optional feature Hover */
	
	
	var optionalFeature;
	var allfeature=$('.left-top-img-prod-opt');
	allfeature.each(function(i){
		$(this).attr('id','left-top-img-prod-opt'+i);
		//alert('hi');
	});
	$('.left-top-img-prod-opt').bind("mouseenter",function()
	{
				var featureProduct=$(this).attr('id');
		optionalFeature=setTimeout(function(){
		$('#'+featureProduct).children('.product-tooltip').fadeIn();
		
				},200);
	});
	$('.left-top-img-prod-opt').bind("mouseleave",function()
			{
				if(optionalFeature)
				clearTimeout(optionalFeature);
				$(this).children('.product-tooltip').fadeOut();
		});
	
	/* Equal Height */
	setTimeout(function(){equalHeight($(".display-menu-list, .display-info-right"));},2000);
});


/* Equal Height Function*/
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}






function submitUsingJquery(url,data,div)
{
	$.ajax({  
		    type: "POST",  
		    url: url,  
		    data: data,  
		    async: false,
		    success: function(msg)
		    {  
				alert(msg);
				$('#'+div).html(msg);
			} 
		   
		}); 
}

//function to allow only numbers in text box
var event;
function onlyNumbers(inputfield, inputevent)
{	
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (inputevent) {
		key = inputevent.which;
	} else {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
    		(key==9) || (key==13) || (key==27)) {
		return true;

	// numbers
	} else if (("0123456789").indexOf(keychar) > -1) {
		return true;
		
	} else {
		return false;
	}


}

//submit form on pressing enter
function checkSubmit(e)
{
   if(e && e.keyCode == 13)
   {
      document.searchbox.submit();
   }
}


//function to open ratings review popup
function test2(id)
{
	if($('#'+id).html()!='')
	{
		var pg = $('#'+id).html();
		container = $('#'+id).html();
	}
	else
	{
		var pg = container;
	}
	$('#'+id).html('');
	
	$('#ratingpopdiv').html(pg);
	openPopDiv('ratingpopdiv');
}

//function to set list OR grid view variable on display solution page
function setview(v)
{
	$('#listview').val(v);
}


//function to increment/decrement quantity for add to cart
function setQuantity(action)
{
	var val= $('#quantity').val();
	if(action=='inc')
	{
		newval = parseInt(val)+1;
		$('#quantity').val(newval);
		$('#quantitydiv').html(newval);
		
	}
	else
	{
		if($('#quantity').val()>1)
		{
			newval = parseInt(val)-1;
			$('#quantity').val(newval);
			$('#quantitydiv').html(newval);
			
		}
	}
}


function openModalPop(id)
{
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
		  
	//Set the popup window to center
	/*$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);*/
	$(id).css('top',  -100);
	$(id).css('left', 0);

	//transition effect
	//$(id).attr('display','block'); 
	$(id).fadeIn(2000); 
}

//if close button is clicked
function closeModalPop()
{
	$('#mask').hide();
	$('.window').hide();
}

//function to show image on mouseover on image thumb on MY CART Page
function ShowPicture(id,Source) { 
$('.ImgClass').css('visibility','hidden');

if (Source=="1"){ 
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible" 
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible" 
} 
else 
if (Source=="0"){ 
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden" 
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden" 
} 
} 
