$(document).ready(function(){
	
	var bodyClass = $('body').attr('class').split(" ");
	if (bodyClass!=''){
		$(bodyClass).each(function(){
			$("body."+ this + " #columnleft ul.menu li." + this).addClass("active");
			$("body."+ this + " #columnleft ul.menu li." + this).addClass("activepage");
		});
	}
	
	$("#columnleft ul.menu li a").click(function(){
		if ($(this).parent("li").hasClass("active"))
		{
			$(this).parent("li").removeClass("active");
		}
		else
		{
			$(this).parent("li").siblings("#columnleft ul.menu li").removeClass("active");
			$(this).parent("li").addClass("active");										   
		}
		//$("#columnleft ul.menu li." + bodyClass).addClass("activepage");
	});
	
	
	// CLearing Default Value in Input Boxes
	
	$("#driversearch").focus(function(){
	  ClearText('e.g. DCP-7010, HL-5240, PT-2700',this.id);
	   /*[mst-20090211:start] remove the white space from the right most data. */
	  /*ClearText('e.g. DCP-7010 ',this.id);*/
	   /*[mst-20090211:end] remove the white space from the right most data. */
	  ClearText('e.g. DCP-7010',this.id);
	  });
	
	// Warranty Registration Page
	$("#date_of_purchase").focus(function(){
	  ClearText('(example 03/03/2008)',this.id);
	  });
	
	
	// Form Select Support ->General FAQ
	/*[mst-20090305:start] remove "@" character because of using jquery version 1.3.1 */
	/*
	$("input[@name='answer_yesorno']").click(function(){ // Change function has bugs in MSIE6
	  if($("input[@name='answer_yesorno']:nth(0):checked").val())
	  	{
			$("div#selectedno").css("display","none");
			$("div#selectedyes").css("display","block");
		}
		else
		{
			$("div#selectedyes").css("display","none");
			$("div#selectedno").css("display","block");
		}
	  });
	  */
	  $("input[name='answer_yesorno']").click(function(){ // Change function has bugs in MSIE6
	  if($("input[name='answer_yesorno']:nth(0):checked").val())
	  	{
			$("div#selectedno").css("display","none");
			$("div#selectedyes").css("display","block");
		}
		else
		{
			$("div#selectedyes").css("display","none");
			$("div#selectedno").css("display","block");
		}
	  });
	  /*[mst-20090305:end] remove "@" character because of using jquery version 1.3.1 */

	   // Bigtarget 
	  $("div.contentblock p.tagline a").bigTarget({
			hoverClass: 'hover', // CSS class applied to the click zone onHover
			clickZone : 'div:eq(0)' // jQuery parent selector
		});
		$("div.featured p a").bigTarget({
			hoverClass: 'hover', // CSS class applied to the click zone onHover
			clickZone : 'div:eq(0)' // jQuery parent selector
		});
		$("#columnright .roundbox dd a").bigTarget({
			hoverClass: 'hover', // CSS class applied to the click zone onHover
			clickZone : 'div:eq(0)' // jQuery parent selector
		});
		
		// For Cframe Pages
		$("#countrySubmit").click(function(){
		var selected = $("#ctl00_header_ddlCountry option:selected");
		 var output = "";  
		 if(selected.val() != null){  
			 window.location=selected.val();
		 }  
		});
});

// VERTICALLY ALIGN FUNCTION

(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('padding-top', mh);
	});
};
})(jQuery);


// Popup Windows

function popUp(strURL,strType,strHeight,strWidth) {
			
		var strOptions="";
		if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
		if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
		if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
		if (strType=="custom") strOptions="scrollbars,status,height="+strHeight+",width="+strWidth;
		window.open(strURL, 'newWin', strOptions);
		}

/*[mst-20090408:start] add function for buying guide */
function NewWindow(mypage,wth,ht,scrol){
    var win = null;
    LeftPosition = (screen.width) ? (screen.width-wth)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-ht)/2 : 0;
    settings ='height='+ ht +',width='+ wth 
    +',top='+TopPosition+',left='+LeftPosition+',location=0,scrollbars='+scrol+',resizable';
    win = window.open(mypage,"_blank",settings)
}

function BuyingGuideNewWindow_Widget(mypage){
   NewWindow (mypage, '1024','688','No');
   return false;
}

function BuyingGuideNewWindow_Toolbox(mypage){
   NewWindow (mypage, '1024','688','No');
   return false;
}


/*[mst-20090408:end] add function for buying guide */

function ClearText(data,fieldId)
{
			
	var input = document.getElementById(fieldId); // Gets the input field based on its id.

	if(data == input.value){ // If the default value is equal to the current value.
		input.value = ''; // Empty It.
	}else{ // Else the value is not equal to the current input field value.
	input.value = input.value;
	}	// Leave it the same.
}

/*[mst-20090211:start] add new function check date format */
function check_date(obj,WatermarkText)
{
   // Regular expression used to check if date is in correct format
   //var pattern = new RegExp([0-3][0-9]-(0|1)[0-9]-(19|20)[0-9]{2});   dd/mm/yyyy format
   //var TextBox = document.getElementById(GetClientId(obj));
   var TextBox = document.getElementById(obj);
   var pattern = '[0-3][0-9]/(0|1)[0-9]/(19|20)[0-9]{2}';
   var regexp = new RegExp(pattern);
   var m = regexp.exec (TextBox.value);
   if ((TextBox.value != WatermarkText) && (TextBox.value != ''))
   {
       //var obj = 'txtpurchasedate.ClientID';
       //var txt = document.getElementById ("<%=" + obj + "%>");
       //alert ('TextBox ' + obj.value);
       //if(document.getElementById('datefield').value.match(pattern))
       if (m != null)
       {
          var date_array = TextBox.value.split('/');
          var day = date_array[0];

          // Attention! Javascript consider months in the range 0 - 11
          var month = date_array[1] - 1;
          var year = date_array[2];

          // This instruction will create a date object
          source_date = new Date(year,month,day);

          if(year != source_date.getFullYear())
          {
             //alert('Year is not valid!');
             return false;
          }

          if(month != source_date.getMonth())
          {
             //alert('Month is not valid!');
             return false;
          }
          if(day != source_date.getDate())
          {
             //alert('Day is not valid!');
             return false;
          }
       }
       else
       {
          //alert('Date format is not valid!');
          return false;
       }
   }
   return true;
}

/*[mst-20090211:end] add new function check date format */

/*[mst-20090227:start] check for numeric character only text box*/
function nonfractioninput(event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (((keyCode >= 48) && (keyCode <= 57))  || keyCode == 8 || keyCode == 9)
        return true;
	else
	    return false;
}
/*[mst-20090227:end] check for numeric character only text box*/


/*[mst-20090305:start] check for numeric character and "/" character only text box*/
function dateinput(event)
{
    
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (((keyCode >= 48) && (keyCode <= 57))  || keyCode == 8 || keyCode == 47 || keyCode == 9)
        return true;
	else
	    return false;
}
/*[mst-20090305:end] check for numeric character and "/" character only text box*/



//disable the catcha input textbox

//$(document).ready(function(){
//    $(".captcha > div > span > input").each(function(){
//        //alert('id: ' + $(this).attr('id'));
//        $(this).bind("keypress", function(e){
//             var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
//             return (keyCode != 13);
//        });
//    });
//    
//});

$(document).ready(function(){
    $(".default_button_submit").each(function(){
        $(this).bind("keypress", function(e){
             var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
             var target = e.target.tagName.toLowerCase();
             
             if( keyCode == 13 ){
                if( target == 'textarea' ) return true;
                var ctrl = $(this).find(".submitimage").attr("id");
                if( ctrl != null && ctrl != '' ){
                    //return WebForm_FireDefaultButton(e , ctrl);
                }else{
                    //find the submit button & fire the default button
                    ctrl = $("a.defaultsubmitbutton").attr("id");      
                }
                if( ctrl != null && ctrl != '' ){
                     __defaultFired = false;
                    return WebForm_FireDefaultButton(e , ctrl);
                }
                
//                ctrl = $(this).find(".button").attr("id");
//                if( ctrl != null && ctrl != '' ){
//                    //alert('button ctrl: ' + ctrl);
//                    return WebForm_FireDefaultButton(e , ctrl);
//                }
//                
//                
//                var $children = $(this).find("p > *");
//                if( $children.length == 0 ){
//                    $children = $(this).find("div > *");
//                }
//                
//                for( var i=0; i<$children.length; i++){
//                    var oField = $children[i];
//                      
//                    if( oField.className == 'button' ){
//                       //alert('classnamebutton: ' + oField.id);
//                        //alert('in button .. ');
//                        return WebForm_FireDefaultButton(e , oField.id);
//                        break;
//                    }
//                }
                return false;
             }
        });
        
    });
    
});


//limit no of email address 
function isValidEmailCount(field){
    var limitCount = 10 ;
    if( field != null && field.value != ''){
        var email = field.value;
        var emailArr = email.split(',')
        if (emailArr.length > limitCount)
            return false;
    }
    return true;
}