// JavaScript Document

//jQuery.noConflict();

	function isValidChar(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("[^A-Za-z0-9 ]"); 
					  var At=objValue.value.charAt(0);
					  if(isNaN(objValue.value.charAt(0))==0)
					  {
						  
						  return false;
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{ 
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if 
							
							return false; 
					  }
				}
				return true;
			
		}

function isValidZip(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("[^A-Za-z0-9- ]"); 
					  var At=objValue.value.charAt(0);
					  if(isNaN(objValue.value.charAt(0))==0)
					  {
						  
						  return false;
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{ 
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if 
							
							return false; 
					  }
				}
				return true;
			
		}

		function isInteger(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";					
					  var charpos = objValue.value.search("[^0-9]"); 
					  if(objValue.value.length > 0 &&  charpos >= 0) 
					  { 
						if(!strError || strError.length ==0) 
						{ 
							return false;
						 // strError = "Only digits allowed "; 
						} 
						
						return false; 
					  }
				}
				return true;
		}
                
                function isFloat(objValue){
                                if(objValue.value!="")
				{
					  var  strError	="";					
					  var charpos = objValue.value.search("[^0-9.]"); 
					  if(objValue.value.length > 0 &&  charpos >= 0) 
					  { 
						if(!strError || strError.length ==0) 
						{ 
							return false;
						 // strError = "Only digits allowed "; 
						} 
						
						return false; 
					  }
				}
				return true;
                }

                function floatValueCheckLimit(floatVal,beforeDecimal,afterDecimal){
                        var amt = floatVal.split(".");
                        if(amt.length>2){
                                return false;
                        }else{
                                var temp = +amt[0];
                                var b_dec = temp+'';
                                if(amt.length==1){
                                        if(b_dec.length > beforeDecimal){ 
                                                return false;
                                        }
                                }else{
                                        if(b_dec.length > beforeDecimal){ 
                                                return false;
                                        }
                                        if(amt[1].length > afterDecimal){
                                                return false;
                                        }
                                }
                                return true;
                        }
                }
		
		function isProperText(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z ]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Only alphabetic characters allowed !!"; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}
		
		function isValidEmailFormat1(objValue)
		{
			
			if(objValue.value!="")
			{
				var  strError	="";
				 if(!validateEmailv2(objValue.value)) 
           		 { 
				     strError ="Enter a valid Email Address!! "; 
					
					 return false;
				}

			}
			return true;
		}
		
		function isDateMMDDYY(objValue)
		{
			if(objValue.value!="")
			{
				if (isDate(objValue.value)==false){
				
				return false
			}

				
			}
			return true;
		}
		
		function isDateDDMMYY(objValue)
		{
			if(objValue.value!="")
			{
			 	if (isDate2(objValue.value)==false)
				{
					
					return false			
				}
				
			}
			return true;
		}
		
		function isValidCellNo(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";
				var charpos = objValue.value.search(/\d{3}\-\d{3}\-\d{4}/); 
			  
				  if(objValue.value.length > 0 &&  charpos ==-1) 
				 { 
					if(!strError || strError.length ==0) 
					{ 
					  strError = "phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx."; 
					}
					
					return false; 
             	 }//if 
             
				
			}
			return true;
		}
	
		function isValidEmailFormat(email){
			
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))
			{
				return (true);
			}
			return false;
		}
                
                function isValidEmail(email){
			
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
			{
				return (true);
			}
			return false;
		}
			
                function trim(stringToTrim) {
                                return stringToTrim.replace(/^\s+|\s+$/g,"");
                }
                function ltrim(stringToTrim) {
                        return stringToTrim.replace(/^\s+/,"");
                }
                function rtrim(stringToTrim) {
                        return stringToTrim.replace(/\s+$/,"");
                }
	
		
	function isValidEmailFormat_old(email)
	{
		if(email.length <= 0)
		{
		  return true;
		}
		
		var splitted = email.match("^(.+)@(.+)$");
		if(splitted == null) return false;
		
		if(splitted[1] != null )
		{
		 
			var regexp_user=/^\"?[\w-_\.]*\"?$/;
		  if(splitted[1].match(regexp_user) == null) return false;
		}
		if(splitted[2] != null)
		{
		  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		  if(splitted[2].match(regexp_domain) == null) 
		  {
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		  }// if
		  return true;
		}
			return false;
	}


var dtCh= "/";
var minYear=1900;
var maxYear=2200;

function isInteger2(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger2(stripCharsInBag(dtStr, dtCh))==false){
		
		return false
	}
return true
}




function isDate2(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger2(stripCharsInBag(dtStr, dtCh))==false){
	
		return false
	}
return true
}

//FOR HIDE AND SHOW 
function toggleSearch(whichLayer)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
		
		if(style2.display == "block"){
			style2.display = "none";
		}else{
			style2.display = "block";
		}
	}
}
//COMPARE PASSWORDS FIELDS
function chkPWD(first, second) {
	var el, msg = '';
		if (first.value == '' || /^\s+$/.test(first.value)) {
		msg = 'Please enter a password.';
		el = first;
		}
		else if (second.value == '' || /^\s+$/.test(second.value)) {
		msg = 'Please re-enter your password.';
		el = second;
		}
		else if (second.value != first.value) {
		msg = 'Please ensure that your password & confirmed password are the same.';
		el = second;
		}
		if (msg) {
		alert(msg);
		el.focus();
		el.select();
		return false;
		}
	return true;
}

//Check file extenstion ( 'jpg','jpeg','bmp','JPG','JPEG','BMP','png','PNG','gif','GIF')
function validImage(obj) {
            
                var filename = obj.value;
                var filelength = parseInt(filename.length) - 4;
                var fileext = filename.substring(filelength,filelength + 4); 
                //Check file extenstion ( 'jpg','jpeg','bmp','JPG','JPEG','BMP')
                if ( fileext != ".jpg" && fileext != "jpeg"  && fileext != ".bmp" && fileext!= ".JPG" && fileext!= "JPEG" && fileext!= ".BMP" && fileext!= ".png" && fileext!= ".PNG" && fileext!= ".gif" && fileext!= ".GIF" )
                { 
                                return false;
                }
    return true;

}


//Check file extention

    //extArray = new Array(".jpg", ".png", ".bmp"); //example file extentions
    extArray = new Array(".csv");
    
    function limitAttach(file) {
	    allowSubmit = false;
	    file	= file.value;
	    
	    if (!file) return;
		    while (file.indexOf("\\") != -1)
			    file = file.slice(file.indexOf("\\") + 1);
			    ext = file.slice(file.indexOf(".")).toLowerCase();
			    
			    for (var i = 0; i < extArray.length; i++) {
			    	if (extArray[i] == ext) { allowSubmit = true; break;
			    }
		    }
	    if (allowSubmit) return true;
	    else
	    alert("Please only upload files that end in types:  "
	    + (extArray.join("  ")) + "\nPlease select a new "
	    + "file to upload and submit again.");
	    return false;
    }

function validate_meta_tags(title_id,keywords_id,description_id,page_title_id) {
  var mtitle =  document.getElementById(title_id).value;
  mtitle = mtitle.trim();
  
  var keywords =  document.getElementById(keywords_id).value;
  keywords = keywords.trim();
  
  var description =  document.getElementById(description_id).value;
  description = description.trim();
  
  var error = false; 
  
  if(page_title_id!=undefined && page_title_id !='') {
    page_title = document.getElementById(page_title_id).value;
    page_title = page_title.trim();
    if(page_title == '' || page_title == null) {
      display_error("title_err","Please enter Page Title");
      error = true;
    } else {
      display_error("title_err"," ");
    }
  }
  
  if(mtitle == '' || mtitle == null) {
    display_error("mtitle_err","Please enter Meta Title for page");
    document.getElementById(title_id).focus();
    error = true;
  } else if (mtitle.length > 80) {
    display_error("mtitle_err","Meta Title cannot be more than 80 characters");
    error = true;
  } else {
    display_error("mtitle_err"," ");
  }
  
  if(keywords == '' || keywords == null) {
    display_error("keyword_err","Please enter Keywords for page");
    document.getElementById(keywords_id).focus();
    error = true;
  } else if (keywords.length > 300) {
    display_error("keyword_err","Keywords cannot be more than 300 characters");
    document.getElementById('StaticpageDescription').focus();
    error = true;
  } else {
    display_error("keyword_err"," ");
  }
  
  
  if(description == '' || description == null) {
    display_error("desc_err","Please enter Description for page");
    document.getElementById(description_id).focus();
    error = true;
  } else if (description.length > 250) {
    display_error("desc_err","Description cannot be more than 250 characters");
    error = true;
  } else {
    display_error("desc_err"," ");
  }
  
  if(error) {
    return false;
  }
}
function display_error(span_id, message) {
  document.getElementById(span_id).style.paddingLeft = "10px";
  document.getElementById(span_id).style.color = "#C71502";
  document.getElementById(span_id).innerHTML = message;
}

function display_other_state(element,id) {
  var value = element.value;
  if(value=='00') {
    document.getElementById('other_state').style.display="";
  } else {
    document.getElementById('other_state').style.display="none";
    document.getElementById(id).value="";
  }
}

function google_transfer(language) {
  if(language!="" && language!=null && language!=undefined) {
    var url = "http://translate.google.com/translate?tl="+language+"&hl=en&u=http://harrison.com";
    window.location = url;
  }
}

function footer_slider() {
  jQuery('#slider_footer').plusSlider({
		displayTime: 5000, // The amount of time the slide waits before automatically moving on to the next one. This requires the default option 'autoPlay: true'
		paginationTitle: true, // Checks for attribute 'data-title' on each slide and names the pagination accordingly
		pagination:false,
		autoPlay: true,
		arrow:false,
		sliderType: 'fader', // Choose whether the carousel is a 'slider' or a 'fader'
		width: 158, // Overide the default CSS width
		height: 141,
		createArrows: false,
    speed: 3000,
    nextText:false,
    prevText:false
	});
  jQuery("#compare_link").hover(function(){
    jQuery(this).attr('src','/img/btn_compare_hover.png');
  },function(){
    jQuery(this).attr('src','/img/btn_compare.png');
  });	
}

function homepage_slider() {
  jQuery('#slider12').plusSlider({
			displayTime: 5000, // The amount of time the slide waits before automatically moving on to the next one. This requires the default option 'autoPlay: true'
			paginationTitle: true, // Checks for attribute 'data-title' on each slide and names the pagination accordingly
			pagination:false,
			autoPlay: true,
			arrow:false,
			sliderType: 'fader', // Choose whether the carousel is a 'slider' or a 'fader'
			width: 946, // Overide the default CSS width
			height: 338,
			createArrows: false,
      speed: 3000
		});
}


  (function(jQuery) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    jQuery.preloadImages = function() {
      var args_len = arguments.length;
      for (var i = args_len; i--;) {
        var cacheImage = document.createElement('img');
        cacheImage.src = arguments[i];
        cache.push(cacheImage);
      }
    }
  })(jQuery)
   
  jQuery.preloadImages("/img/new-tab.gif");
   
   
  jQuery.preloadImages_fnc = function() {
  	var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
  	for(var i = a.length -1; i > 0; i--) {
  		jQuery("<img>").attr("src", a[i]);
  	}
  }

function header_images_color() {
    jQuery("a#skype_no").fancybox({
		'opacity'		: true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none',
		'scrolling'   : 'no'
	});
	jQuery("#example4 img").hover(function(){
    jQuery(this).attr('src','/img/btn_chat_hover.png');
  },function(){
    jQuery(this).attr('src','/img/btn_chat.png');
  });
  jQuery("#email_link img").hover(function(){
    jQuery(this).attr('src','/img/btn_email_hover.png');
  },function(){
    jQuery(this).attr('src','/img/btn_email.png');
  });
  jQuery("#skype_no img").hover(function(){
    jQuery(this).attr('src','/img/btn_cno_hover.png');
  },function(){
    jQuery(this).attr('src','/img/btn_cno.png');
  });
}


function submitform()
{
	var myTextdata = document.getElementById('data').value;
	var myTextzip = document.getElementById('textfield').value;
	
	if(myTextzip =='')
	{

		alert("Please Enter the Zip code");
		return false;
	}
	else
	{
		window.location = "/dealers/dealersView/"+myTextdata+"/"+myTextzip;
	}

}
function submitnews()
{
	var myTextdata = document.getElementById('email').value;
	
	if(myTextdata=="Email Address"){
  return false;
  }else
  {
  document.getElementById('emailid').value=myTextdata;
	document.submitnewsletter.submit();
  }
  	if(myTextdata==" "){
  return false;
  }
  else
  {
  	document.getElementById('emailid').value=myTextdata;
	document.submitnewsletter.submit();
  }
}

function check_unique(spec_id,pull_down) {
  var prev_val = jQuery("#spec_id_prev").val();
  if(prev_val.indexOf(spec_id+"-")!=-1 && spec_id!="") {
    jQuery("#spec"+pull_down).val("");
    alert("Please select other product");
    exit;
  }
}
function get_product(spec_id,pull_down) {
  check_unique(spec_id,pull_down);
  if(spec_id!="" && spec_id!=null && spec_id!=undefined) {
    if(jQuery("#spec_id_prev").val()=="" || jQuery("#spec_id_prev").val()==null) {
      spec_id = spec_id+"-"+pull_down;
      jQuery("#spec_id_input").val(spec_id);
    } else {
      var prev_val = jQuery("#spec_id_prev").val();
      if(prev_val.indexOf("-"+pull_down)!=-1) {
        var prev_val= prev_val.replace("-"+pull_down,'');
      }
      var val_new = prev_val+","+spec_id+"-"+pull_down;
      jQuery("#spec_id_input").val(val_new);     //add here all forms
    }
    jQuery('#spec_form').submit();
  } else {
    var prev_val =  jQuery("#spec_id_prev").val();
    if(prev_val!="" && prev_val!=undefined) {
      if((prev_val.indexOf(spec_id))!= -1) {
        var remove = spec_id+"-"+pull_down;
        var val_new= prev_val.replace(remove,'');
        a = val_new.replace('/[,,]/',",");
        jQuery("#spec_id_input").val(a);
        jQuery('#spec_form').submit();
      }
    }
  }
}


jQuery(document).ready(function(){
	footer_slider();
	if (window.location.pathname !="/") {
    header_images_color();
  }
  homepage_slider();
  
  
  jQuery(".facebook").hover(function(){
    jQuery('.box_name_fb').css({'color':'#facd10'});
  },function() {
    jQuery('.box_name_fb').css({'color':'#fff'});
  });
  jQuery(".youtube").hover(function(){    
    jQuery('.box_name_yt').css({'color':'#facd10'});    
  },function() {
    jQuery('.box_name_yt').css({'color':'#fff'});
  });
  jQuery(".twitter").hover(function(){    
    jQuery('.box_name_tw').css({'color':'#facd10'});    
  },function() {
    jQuery('.box_name_tw').css({'color':'#fff'});
  });   
  jQuery(".dealer_ft").hover(function(){    
    jQuery('.box_name_dl').css({'color':'#facd10'});    
  },function() {
    jQuery('.box_name_dl').css({'color':'#fff'});
  });
  
  
  jQuery(".article_1").hover(function(){    
    jQuery('.title_1').css({'color':'#facd10'});    
  },function() {
    jQuery('.title_1').css({'color':'#E0E0E0'});
  });
  jQuery(".article_2").hover(function(){    
    jQuery('.title_2').css({'color':'#facd10'});    
  },function() {
    jQuery('.title_2').css({'color':'#fff'});
  });
  jQuery(".article_3").hover(function(){    
    jQuery('.title_3').css({'color':'#facd10'});    
  },function() {
    jQuery('.title_3').css({'color':'#fff'});
  });
  jQuery(".article_4").hover(function(){    
    jQuery('.title_4').css({'color':'#facd10'});    
  },function() {
    jQuery('.title_4').css({'color':'#fff'});
  });
  
  
  //alert(home_page);
  //if(home_page==true) {
    //homepage_slider();
  //}
});
