<!--
// check all
function checkAll(field){
	for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

// uncheck all
function uncheckAll(field){
	for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// onclick check for spotlight button
function check_spotlightads(curr_spot,max_spot,ad_array){
	var rem_spot = max_spot-curr_spot;
	var max = document.multi_action_form.selected_record.length;
	var total=0;
	var isSpotlighted = 0;
	var isPassTotal = 0;
	var checked = 0;

	if(document.multi_action_form.selected_record.length){
		for (i=0; i<max ;i++ ){
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) {
				// if checkbox s already spotlighted disable button..cannot spotlight a spotlighted ad
				for (j=0;j<ad_array.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == ad_array[j]){
						isSpotlighted =1;
						document.multi_action_form.spotlight.disabled=true;
						break;
					}
				}
				// break for loop- button is already disabled
				if (isSpotlighted == 1){
					break;
				}
				// total checked boxes taht are not spotloghted
				else{
					total = total+1;
				}

				// if more buttons are checked that can be spotlighted are greater than the remaining spotlight spots disable
				if(total > rem_spot){
					document.multi_action_form.spotlight.disabled=true;
					isPassTotal = 1;
				}
			} // end if
		} // end for
	}
	// one check box
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true) {
			// if checkbox s already spotlighted disable button..cannot spotlight a spotlighted ad
			for (j=0;j<ad_array.length ;j++ ){
				if (document.multi_action_form.selected_record.value == ad_array[j]){
					isSpotlighted =1;
					document.multi_action_form.spotlight.disabled=true;
					break;
				}
			}
			total = total+1;

			// if more buttons are checked that can be spotlighted are greater than the remaining spotlight spots disable
			if(total > rem_spot){
				document.multi_action_form.spotlight.disabled=true;
				isPassTotal = 1;
			}
		}
	}

	if(isSpotlighted == 0 && isPassTotal == 0){
		document.multi_action_form.spotlight.disabled=false;
	}

} // end function

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// onclick check for highlight button
function check_prioritisedads(curr_pri,max_pri,ad_array_pri){

	var rem_pri = max_pri-curr_pri;
	var max = document.multi_action_form.selected_record.length;
	var total=0;
	var isHighlighted = 0;
	var isPassTotal = 0;
	var checked = 0;
	if(document.multi_action_form.selected_record.length){
		for (i=0; i<max ;i++ ){
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) {
				// if checkbox s already highlighted disable button..cannot highlight a highloghted ad
				for (j=0;j<ad_array_pri.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == ad_array_pri[j]){
						isHighlighted =1;
						document.multi_action_form.prioritise.disabled=true;
						break;
					}
				}
				// break for loop- button is already disabled
				if (isHighlighted == 1){
					break;
				}
				// total checked boxes taht are not highlighted
				else{
					total = total+1;
				}

				// if more buttons are checked that can be highlighted are greater than the remaining highlight spots disable
				if(total > rem_pri){
					isPassTotal = 1;
					document.multi_action_form.prioritise.disabled=true;
				}
			} // end if
		} // end for
	}
	// one check box
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true) {
			// if checkbox s already highlighted disable button..cannot highlight a highloghted ad
			for (j=0;j<ad_array_pri.length ;j++ ){
				if (document.multi_action_form.selected_record.value == ad_array_pri[j]){
					isHighlighted =1;
					document.multi_action_form.prioritise.disabled=true;
					break;
				}
			}
			total = total+1;
			// if more buttons are checked that can be highlighted are greater than the remaining highlight spots disable
			if(total > rem_pri){
				isPassTotal = 1;
				document.multi_action_form.prioritise.disabled=true;
			}
		} // end if
	} //end else
	if(isHighlighted == 0 && isPassTotal == 0){
		document.multi_action_form.prioritise.disabled = false;
	}
} // end function


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// onclick check for email button - for dealership sectoon
function check_emailButton(notActiveArray){

	// check to see that button is already disabled
	var deactivate = 0;



	// if 2 or more checkbocxex
	if( document.multi_action_form.selected_record.length){
		var max = document.multi_action_form.selected_record.length; // length of checkbox array


		for (i=0; i<max ;i++ ){		 // for each checkbox
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) {
				// if checkbox is checked

				// check through list of notactive ads. if ad is not active disable button
				for (j=0;j<notActiveArray.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == notActiveArray[j]){

						deactivate = 1;

						document.multi_action_form.emailAdList.disabled=true;

						break; // break for loop
					}	// end if
				} // end for

			}// end if

		}// end for
	}
	// only 1 checkbox
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true){
			// check through list of notactive ads. if ad is not active disable button
			for (j=0;j<notActiveArray.length ;j++ ){

				if (document.multi_action_form.selected_record.value == notActiveArray[j]){
					deactivate = 1;

					document.multi_action_form.emailAdList.disabled=true;

					break; // break for loop
				}	// end if
			} // end for

		} // end if

	} // end else 1 checkbox

	// disable button if deactivate = 1
	if (deactivate==0){
		document.multi_action_form.emailAdList.disabled=false;

	} // end if

}// end function check_emailButton2

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// onclick check for email button and deactivate ad button
function check_buttonsPS(notActiveArray){
	// check to see that button is already disabled
	var deactivate = 0;


	// if 2 or more checkbocxex
	if( document.multi_action_form.selected_record.length){
		var max = document.multi_action_form.selected_record.length; // length of checkbox array

		for (i=0; i<max ;i++ ){		 // for each checkbox
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) { // if checkbox is checked

				// check through list of notactive ads. if ad is not active disable button
				for (j=0;j<notActiveArray.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == notActiveArray[j]){
						deactivate = 1;

						document.multi_action_form.emailAdList.disabled=true;
						document.multi_action_form.deactivatePS.disabled=true;
						break; // break for loop
					}	// end if
				} // end for

			}// end if

		}// end for
	}
	// only 1 checkbox
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true){
			// check through list of notactive ads. if ad is not active disable button
			for (j=0;j<notActiveArray.length ;j++ ){
				if (document.multi_action_form.selected_record.value == notActiveArray[j]){
					deactivate = 1;

					document.multi_action_form.emailAdList.disabled=true;
					document.multi_action_form.deactivatePS.disabled=true;
					break; // break for loop
				}	// end if
			} // end for

		} // end if

	} // end else 1 checkbox

	// disable button if deactivate = 1
	if (deactivate==0){
		document.multi_action_form.emailAdList.disabled=false;
		document.multi_action_form.deactivatePS.disabled=false;
	} // end if
}// end function check_buttonsPS


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_buttons(dealerStatus, maxAds, maxSpotlightAds, currentSpotlightAds, spotlightArray, maxHighlightAds, currentHighlightAds,highlightArray,notActiveArray,activeArray,inactiveArray){

	var buttonStatus = 1;
	var highlightButtonStatus = 1;
	var spotligtButtonStatus = 1;
	// check status of account
	if (dealerStatus == 'inactive' || dealerStatus == 'expired' || dealerStatus=='new'){
		buttonStatus = 0;
	}

	// maximum number of ads = 0
	else if (maxAds == 0){
		buttonStatus = 0;
	}

	// disable all buttons if db criteria are not met
	if(buttonStatus == 0){
		document.multi_action_form.prioritise.disabled=true;
		document.multi_action_form.spotlight.disabled=true;
		document.multi_action_form.activate.disabled=true;
		document.multi_action_form.deactivate.disabled=true;
		document.multi_action_form.standardise.disabled=true;
		document.multi_action_form.emailAdList.disabled=true;
	}
	// go through form action specific criteria
	else{
		// disable highlight button if ax highligh= 0 or maxhighloght<=currhighlight else chheck_prioritise(highlight)
		if ((maxHighlightAds == 0)||(maxHighlightAds <= currentHighlightAds)){
			document.multi_action_form.prioritise.disabled=true;
		}
		else{
			check_prioritisedads(currentHighlightAds, maxHighlightAds, highlightArray);
		}

		// disable spotlight button if max spotlight ads = 0 or <= currentspotlight else check_spotlight
		if (maxSpotlightAds == 0 || (maxSpotlightAds <= currentSpotlightAds)){
			document.multi_action_form.spotlight.disabled=true;
		}
		else{
			check_spotlightads(currentSpotlightAds, maxSpotlightAds, spotlightArray);
		}
		// check email button
		check_emailButton(notActiveArray);
		check_activateButton(activeArray,maxAds);
		check_deactivateButton(inactiveArray);
	}
} // check_butons


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check of email
function Go(formname){
	if(formname.agreement.checked == 1){
		document.formname.submit();
		return true;
	}
	else{
		alert('You must agree to CARibZOOMZOOM terms of use and refund policy before continuing');
		return false;
	}
}

// check to see that checkboxs is checked before for subission returs alert if no fbutton is checked and cancels submission
function checkCheckboxes(frm){
	var checked = 0;

	if (frm.selected_record.length){
		for(i=0;i<frm.selected_record.length;i++){
			if (eval("document.multi_action_form.selected_record["+i+"].checked") == true){
				checked=1;
			}// end if
		}// end for
	}
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true){
			checked = 1;
		}
	}

	if(checked==1){
		return true;
	}
	else{
		alert("You must select an Ad first.");
		return false;

	}

}

// changes action of form - used with email multiple ads
function changeEmailFormAction(formname,url){
	formname.action = url;

}
// popup for print window
function popitup(url) {
	newwindow=window.open(url,'name','height=800,width=675,scrollbars=yes,resizable=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}


// checks to see if selected record is active if yss disable button
function check_activateButton(activeArray,maxAds){

	// check to see that button is already disabled
	var deactivate = 0;
	var total = 0;
	


	// if 2 or more checkbocxex
	if( document.multi_action_form.selected_record.length){
		var max = document.multi_action_form.selected_record.length; // length of checkbox array

		for (i=0; i<max ;i++ ){		 // for each checkbox
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) { // if checkbox is checked

				// check through list of notactive ads. if ad is active disable button
				for (j=0;j<activeArray.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == activeArray[j]){
						deactivate = 1;

						document.multi_action_form.activate.disabled=true;

						break; // break for loop
					}	// end if
				} // end for
				
				// if button was not disabled increment total				
				if(deactivate == 0){
					total = total+1;
					
					// if total + currnet active greater than max disable button
					if((total + activeArray.length)> maxAds){
						deactivate = 1;
						document.multi_action_form.activate.disabled=true;
					} // end if
				} // end if

			}// end if checked

		}// end for 
	}
	// only 1 checkbox
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true){
			// check through list of notactive ads. if ad is not active disable button
			for (j=0;j<activeArray.length ;j++ ){
				if (document.multi_action_form.selected_record.value ==activeArray[j]){
					deactivate = 1;

					document.multi_action_form.activate.disabled=true;

					break; // break for loop
				}	// end if
			} // end for
			
			// if button was not disabled increment total				
				if(deactivate == 0){
					total = total+1;
					// if total + currnet active greater than max disable button
					if((total + activeArray.length)> maxAds){
						deactivate = 1;
						document.multi_action_form.activate.disabled=true;
					} // end if
				} // end if		

		} // end if

	} // end else 1 checkbox

	// disable button if deactivate = 1
	if (deactivate==0){
		document.multi_action_form.activate.disabled=false;

	} // end if


}








// checks to see if selected record is inactive if yss disable button
function check_deactivateButton(inactiveArray){

	// check to see that button is already disabled
	var deactivate = 0;


	// if 2 or more checkbocxex
	if( document.multi_action_form.selected_record.length){
		var max = document.multi_action_form.selected_record.length; // length of checkbox array

		for (i=0; i<max ;i++ ){		 // for each checkbox
			if (eval("document.multi_action_form.selected_record[" + i + "].checked") == true) { // if checkbox is checked

				// check through list of notactive ads. if ad is not active disable button
				for (j=0;j<inactiveArray.length ;j++ ){
					if (document.multi_action_form.selected_record[i].value == inactiveArray[j]){
						deactivate = 1;

						document.multi_action_form.deactivate.disabled=true;

						break; // break for loop
					}	// end if
				} // end for

			}// end if

		}// end for
	}
	// only 1 checkbox
	else{
		if (eval("document.multi_action_form.selected_record.checked") == true){
			// check through list of notactive ads. if ad is not active disable button
			for (j=0;j<inactiveArray.length ;j++ ){
				if (document.multi_action_form.selected_record.value ==inactiveArray[j]){
					deactivate = 1;

					document.multi_action_form.deactivate.disabled=true;

					break; // break for loop
				}	// end if
			} // end for

		} // end if

	} // end else 1 checkbox

	// disable button if deactivate = 1
	if (deactivate==0){
		document.multi_action_form.deactivate.disabled=false;

	} // end if


}
//-->
