function changePic(pic) {
	document.getElementById('largepic').src = pic.href.replace(/thumbnails\//g, "");
	document.getElementById('largepiclink').href = pic.href.replace(/thumbnails\//g, "");
}

/// disable submit button
function submitIt() {
    theForm.submit.click();
    return false;
} 
var theForm;
var requestSubmitted = false;  
function disableButton(btn,form) {
	if (!requestSubmitted){
		var submitMessage = "  Please Wait...  ";
		btn.value = submitMessage;
		theForm = form;
		btn.disabled = true;
		requestSubmitted = true;
		setTimeout("submitIt()", 250);
   } else {
        return false;
   }
}

/// Upload Progress Bar
function uploadProgress(){
	document.all("formDiv").style.display = "none";
	document.all("progressDiv").style.display = "";
	window.setTimeout("StartAnimation()",100);
}
function StartAnimation()
{
			document.images['progress_indicator'].src = document.images['progress_indicator'].src;
}
/// Tribesoft Open Popup Window

var hK;
function hkOpen(winurl,winname,winfeatures)
{
	hK = window.open(winurl,winname,winfeatures);
 	setTimeout('hK.focus();',250);
}

////
/// Check File Extension
///
function checkFileExt(obj,msg,ext,req){
// If Field Is Empty
if (req == "yes" || obj.value != "") {
file = obj.value
var file_ext = file.substring(file.lastIndexOf('.')+1, file.length);
//alert("file ext: " + file_ext)
var arr_ext = ext.split(',');
var matched = false;
for (var i=0; i<arr_ext.length; i++)
{
	//alert("file ext: " + file_ext + "\t array: " + arr_ext[i]);
	if(file_ext.toLowerCase() == arr_ext[i].toLowerCase())
	{
		matched = true;
	}
}

if (matched == false){
	alert(msg + "\nOnly these files types are allowed: " + ext);
	obj.focus();
	return false;
}
}
return true;
}

///
///Check Check Box
// If not, it displays the error message,
// focuses the control	and returns false
// 
function checkBox(obj, msg, req)
	{
	if (req == "yes") {
		if (obj.checked==false)
		{ 	alert(msg);
			obj.focus();
			return false;
		}
		}
		return true;
	}
	
	//
	// Check For Numbers
	// If not, it displays the error message,
	// focuses the control	and returns false
	// 
function checkNumbers(obj,msg,req) {
		if (!checkNumChar(obj,req)){
			//alert(hkGoodNumbers);
			msg += '\nBe sure you are only using numbers';
			alert(msg);
			obj.focus();
			return false;
		};
		return true;
	};
	
function checkNumChar(obj,req) {
var valid = 1
var hkGoodNumbers = "0123456789,."
var i = 0

if (obj.value=="" && req == "yes") {
valid = 0
}

for (i =0; i <= obj.value.length -1; i++) {
if (hkGoodNumbers.indexOf(obj.value.charAt(i)) == -1) {
valid = 0
}
}
return valid
}

//
	// Check For Numbers
	// If not, it displays the error message,
	// focuses the control	and returns false
	// 
function checkQty(obj,msg,req) {
		if (!checkQtyChar(obj,req)){
			//alert(hkGoodNumbers);
			msg += '\nBe sure you are only using whole numbers';
			alert(msg);
			obj.focus();
			return false;
		};
		return true;
	};
	
function checkQtyChar(obj,req) {
var valid = 1
var hkGoodNumbers = "0123456789"
var i = 0

if (obj.value=="" && req == "yes") {
valid = 0
}

for (i =0; i <= obj.value.length -1; i++) {
if (hkGoodNumbers.indexOf(obj.value.charAt(i)) == -1) {
valid = 0
}
}
return valid
}
	
	//
	//
	// this function checks to see if the valid form of email address has been entered,
	// If not, it displays the error message,
	// focuses the control	and returns false
	// 

	function checkEmail(obj,msg,req) {
	if (req == "yes" || obj.value != ""){
			if (!checkEmailChar(obj)){
			alert(msg);
			obj.focus();
			return false;
		}
		}
		return true;
	};

	function checkEmailChar(obj) {
		invalidChars=" /:,;";
		for (i=0; i<invalidChars.length;i++){
			badChar = invalidChars.charAt(i);
				if (obj.value.indexOf(badChar,0) !=-1) {
					return false;
				};
		};
		atPos = obj.value.indexOf("@", 1);
		if (atPos == -1){
					return false;
		};
		if (obj.value.indexOf("@",atPos+1)!= -1){
					return false;
		};
		dotPos = obj.value.indexOf(".", atPos);
		if (dotPos <=0){
					return false;
		};
		if (dotPos+3 > obj.value.length){
					return false;
		};

		return true;
	};

	// 
	// this function checks to see if a radio-button has not been selected
	// If not, it displays the error message,
	// focuses the control	and returns true
	// 

	function checkRadio(obj,msg, req)	{
	if (req == "yes"){
	var itemchecked = false;
		for(var j = 0 ; j < obj.length ; ++j)
		{	if(obj[j].checked)
			{	itemchecked = true;
				break;
			};
		};
		if(!itemchecked)
		{ 	alert(msg);
			obj[0].focus()
			return false;
		}
		}
		return true;

	};

	// 
	// this function checks to see if a pull-down has not been selected
	// past the first item OR if the value option selected is '0' or '',
	// If not, it displays the error message,
	// focuses the control	and returns false
	// 
	function checkPullDown(obj,msg,req) {
	if (req == "yes") {
		if (obj.selectedIndex==0 || obj.options[obj.selectedIndex].value=='0' || obj.options[obj.selectedIndex].value=='') {
			alert(msg);
			obj.focus();
			return false;
		}
		}
		return true;
	};

	// 
	// this function checks to see whether a text input or textarea
	// is blank or is all white space.
	// If so, it displays the error message,
	// focuses the control	and returns false
	// 
	function checkText(obj,msg,req) {
		var str = obj.value+'';
		var allWhite = true;
		//var whiteTrail;
		for(var c=0; c<str.length; c++) {
			if (!isWhite(str.charAt(c))) allWhite=false;
		//	if (c=str.length) && (isWhite(str.charAt(str.length)))
		};
if (req == "yes"){
		if (allWhite || str=='') {
			obj.value="";
			alert(msg);
			obj.focus();
			return false;
		}
		}
			remove_XS_whitespace(obj);
		return true;
	};
	// 
	// this function checks to see whether a text input or textarea
	// is blank or is all white space.
	// If it is all white space, it cleans it out and return true
	// 
	function cleanNonRequiredText(obj) {
		var str = obj.value+'';
		var allWhite = true;
		for(var c=0; c<str.length; c++) {
			if (!isWhite(str.charAt(c))) {
				allWhite=false; 
			};
		}
		if (allWhite || str=='') {
			obj.value="";
			return true;
		}else{
			remove_XS_whitespace(obj);
			return false;		
		};
	};

	// 
	// this function checks to see whether a text input or textarea
	// is blank or is all white space.
	// If so, it displays the error message,
	// focuses the control	and returns true
	// It also checks the number of chars and displays the too many
	// chars message if that is exceeded
	// 
	function checkTextArea(obj,msg,max,msgmax,req) {
	
	if (req == "yes" || obj.vaulue != ""){
		var str = obj.value+'';
		if (str.length>max) {
			alert(msgmax + ' [There are currently '+str.length+' characters]');
			obj.focus();
			return false;
		};
		}
		var allWhite = true;
		for(var c=0; c<str.length; c++) {
			if (!isWhite(str.charAt(c))) allWhite=false;
		}
		if (allWhite || str=='') {
			obj.value="";
			alert(msg);
			obj.focus();
			return false;
		};
		return true;
	};
	// 
	// this function checks to see whether a text input 
	// contains " or '.
	// If so, it displays the error message,
	// focuses the control	and returns false
	// 
	function checkQuoteMark(obj, msg)
	{
		if ((obj.value.indexOf('"') >= 0) || (obj.value.indexOf("'") >= 0))
		{ 	alert(msg);
			obj.focus();
			return false;
		};
		
		return true;
	};

	function checkMax(obj,max,msgmax) {
		var str = obj.value+'';
		if (str.length>max) {
			alert(msgmax + ' [There are currently '+str.length+' characters]');
			obj.focus();
			return false;
		};
		return true;
	};
	
	// 
	// These functions check to see if the text field 
	// contains a valid date
	// If not, they display an error message,
	// focus the control and return false.
	// 
	// Declaring valid date character, minimum year and maximum year
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	function isInteger(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 checkDate(obj,req){
	
	if (req == "yes" || obj.value != "") {
		sDateString = obj.value
		var daysInMonth = DaysArray(12)
		var pos1=sDateString.indexOf(dtCh)
		var pos2=sDateString.indexOf(dtCh,pos1+1)
		/// Use This for the States
		var strMonth=sDateString.substring(0,pos1)
		var strDay=sDateString.substring(pos1+1,pos2)
		/// Use This for Europe
		//var strMonth=sDateString.substring(pos1+1,pos2)
		//var strDay=sDateString.substring(0,pos1)
		
		var strYear=sDateString.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){
			alert("The date format should be : dd/mm/yyyy")
			obj.focus()
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month")
			obj.focus()
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day")
			obj.focus()
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			obj.focus()
			return false
		}
		if (sDateString.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(sDateString, dtCh))==false){
			alert("Please enter a valid date")
			obj.focus()
			return false
		}
		}
	return true
	}
	
	function isWhite(ch) {
		if (ch==' ' || ch=='	' || ch=="\n" || ch=="\r") return true;
		return false;
	};


function remove_XS_whitespace(obj)
{
  var tmpStr = "";
  var obj_length = obj.value.length;
  var obj_length_minus_1 = obj.value.length - 1;
  for (i = 0; i < obj_length; i++)
  {
    if (obj.value.charAt(i) != ' ')
    {
      tmpStr += obj.value.charAt(i);
    }
    else
    {
      if (tmpStr.length > 0)
      {
        if (obj.value.charAt(i+1) != ' ' && i != obj_length_minus_1)
        {
          tmpStr += obj.value.charAt(i);
        }
      }
    }
  }
  obj.value = tmpStr;
};



///
/// This functions checks for a standard american phone number

var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
function checkPhone(obj,type,req)
{
if (req == "yes" || obj.value != "") {
var OK = re.exec(obj.value);
if (!OK)
{	
	alert("Please input a properly formatted " + type + " number 555-555-1212");
	obj.focus();
	return false;
}
}
 return true;
}



function compareDate(date1,date2,msg)
{
	// date1 and date2 must be validated before send, required format is "mm/dd/yyyy"
	var X1 = date1.value
	X1 = X1.split('/')
	X1 = -((-X1[2]*100-X1[0])*100-X1[1])
	// -((-X2[2]*100-X2[1])*100-X2[0]) use this formula for "dd/mm/yyyy"
	var X2 = date2.value
	X2 = X2.split('/')
	X2 = -((-X2[2]*100-X2[0])*100-X2[1])
	// -((-X2[2]*100-X2[1])*100-X2[0]) use this formula for "dd/mm/yyyy"
	if (X1<=X2)
		return true;	
	else
		alert(msg);
		date2.focus();
		return false;
}


/// Bike Ajax ///
var xmlhttp = false;

try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	xmlhttp = new XMLHttpRequest();

function request(page, objID) {
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", page);
	xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
				obj.innerHTML = xmlhttp.responseText;
		}
	xmlhttp.send(null);
}

function selectMake() {
	//var sMake = document.getElementById("sMake").value;
	var sMake = document.searchForm.Make.value;
	document.getElementById('iSubTwoID').innerHTML = '';
	request('/sys/incAjaxGet.asp?iSelect=iSubOne&sMake='+sMake, 'iSubOneID');
	//alert('/sys/incAjaxGet.asp?iSelect=iSubOne&sMake='+sMake);
}

function selectModel() {
	var sMake = document.searchForm.Make.value;
	var iSubOne = document.searchForm.iSubOne.value;
	document.getElementById('iSubThreeID').innerHTML = '';
	//alert(sMake+" "+iSubOne);
	//alert('/sys/incAjaxGet.asp?iSelect=iSubTwo&sMake='+sMake+'&iSubOne='+iSubOne+', iSubTwoID');
	request('/sys/incAjaxGet.asp?iSelect=iSubTwo&sMake='+sMake+'&iSubOne='+iSubOne, 'iSubTwoID');
}

function selectYear() {
	var sMake = document.searchForm.Make.value;
	var iSubOne = document.searchForm.iSubOne.value;
	var iSubTwo = document.searchForm.iSubTwo.value;
	request('/sys/incAjaxGet.asp?iSelect=iSubThree&sMake='+sMake+'&iSubOne='+iSubOne+'&iSubTwo='+iSubTwo, 'iSubThreeID');
}

function check() {
	var iCat = document.getElementById("sMake").value;
	
	if (iCat == 0) return true;
}
/// Bike Ajax ///


//// Cross Selling Scripts
//// Cross Selling Scripts
function DisabledOption( sSourceName, sDestinationName, sFormName )
    {
		objSourceElement = eval( "document." + sFormName + "." + sSourceName );
		objTargetElement = eval( "document." + sFormName + "." + sDestinationName );

        var aryTempSourceOptions = new Array();
        var x = 0;

        //looping through source element to find selected options
        for (var i = 0; i < objSourceElement.length; i++) {
            if (objSourceElement.options[i].selected) {
                //need to move this option to target element
                var intTargetLen = objTargetElement.length++;
                objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
                objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;

            }
            else {
                //storing options that stay to recreate select element
                var objTempValues = new Object();
                objTempValues.text = objSourceElement.options[i].text;
                objTempValues.value = objSourceElement.options[i].value;
                aryTempSourceOptions[x] = objTempValues;
                x++;
            }
        }

        //resetting length of source
        objSourceElement.length = aryTempSourceOptions.length;
        //looping through temp array to recreate source select element
        for (var i = 0; i < aryTempSourceOptions.length; i++) {
            objSourceElement.options[i].text = aryTempSourceOptions[i].text;
            objSourceElement.options[i].value = aryTempSourceOptions[i].value;
            objSourceElement.options[i].selected = false;

        }
    }


	  function EnabledOption( sSourceName, sDestinationName, sFormName )
    {
		objSourceElement = eval( "document." + sFormName + "." + sSourceName );
		objTargetElement = eval( "document." + sFormName + "." + sDestinationName );

        var aryTempSourceOptions = new Array();
        var x = 0;

        //looping through source element to find selected options
        for (var i = 0; i < objSourceElement.length; i++) {
            if (objSourceElement.options[i].selected) {
                //need to move this option to target element
                var intTargetLen = objTargetElement.length++;
                objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
                objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;

            }
            else {
                //storing options that stay to recreate select element
                var objTempValues = new Object();
                objTempValues.text = objSourceElement.options[i].text;
                objTempValues.value = objSourceElement.options[i].value;
                aryTempSourceOptions[x] = objTempValues;
                x++;
            }
        }

        //resetting length of source
        objSourceElement.length = aryTempSourceOptions.length;
        //looping through temp array to recreate source select element
        for (var i = 0; i < aryTempSourceOptions.length; i++) {
            objSourceElement.options[i].text = aryTempSourceOptions[i].text;
            objSourceElement.options[i].value = aryTempSourceOptions[i].value;
            objSourceElement.options[i].selected = false;

        }
    }

function UpdateValues( sDisplayName, sFieldName, sFormName ){
	objPullList = eval( "document." + sFormName + "." + sFieldName );
	objDisplayElement = eval( "document." + sFormName + "." + sDisplayName );
	objDisplayElement.value = "";

for (var i = 0; i < objPullList.length; i++) {
	if(i!=0){
		objDisplayElement.value+=","+objPullList.options[i].value;
		} else {
		objDisplayElement.value+=""+objPullList.options[i].value;
		}
}
}
////
function hkTabOpener(hkTabCommand,count) {
		hkTabID = "divObject" + hkTabCommand;
		hkTabObject = document.getElementById(hkTabID);
		hkTabExID = "navObject" + hkTabCommand;
		hkTabEx = document.getElementById(hkTabExID);
		hkTabExSource = hkTabEx.className.toLowerCase();
		hkClickID = "clickObject" + hkTabCommand;
		hkClickObject = document.getElementById(hkClickID);
		hkTabCount = count // Put number of objects
		
		if(hkTabObject.style.display == "none") {
			hkTabObject.style.display = "block";
			hkClickObject.style.display = "none";

			if (hkTabEx.className == "open") {
				hkTabEx.className = "close"
			}else{
				hkTabEx.className = "open"
				
			}		
			for (i = 1; i <= hkTabCount; i++){
				if (i != hkTabCommand){
					var hkTabLoop = "divObject" + i;
					
						hkTabLoopId = "divObject" + i;
						hkTabLoop = document.getElementById(hkTabLoopId);
				
						hkTabExLoopID = "navObject" + i;
						hkTabExLoop = document.getElementById(hkTabExLoopID);
						hkTabExLoopSource = hkTabExLoop.className.toLowerCase();
						
						hkTabLoop.style.display = "none";
					 	hkTabExLoop.className = hkTabExLoopSource.replace("open","close");
						
						hkClickLoopId = "clickObject" + i;
						hkClickLoop = document.getElementById(hkClickLoopId);
						hkClickLoop.style.display = "block";
						
				}
			}		
			
		}
		else {
			hkTabObject.style.display = "none";
			
			if (hkTabEx.className == "open") {
				hkTabEx.className = "close"
			}else{
				hkTabEx.className = "open"
			}
		}
	}
