// JavaScript Document

function countDown(control, maxLen, counter, typeName) {
	 var len = control.value.length;
     var txt = control.value;
     var span = document.getElementById(counter);
     span.style.display = '';
     span.innerHTML = (maxLen - len) + ' characters remaining';
     if (len >= (maxLen - 10)) {
          span.style.color = 'red';
          if (len > maxLen) {
				control.value = txt.substring(0, maxLen);
				span.innerHTML = (maxLen - control.value.length) + ' characters remaining';
				//alert(typeName + ' text exceeds the maximum allowed!');
          }
     } else {
          span.style.color = '';
     }
}

function checkCity(curField, field){
	//curField is location, field is city
	var city = document.getElementById(field);
	
	if(curField.value != ""){
		curField.style.backgroundColor = "#ffffff"
		city.value = "";
		city.style.backgroundColor = "#ebebe4";
		document.getElementById("CAT_Custom_41982").style.backgroundColor = "#ebebe4";
		document.getElementById("CAT_Custom_41982").selectedIndex = 0;
	}
}

function checkLocation(curField, field){
	//curField is city, field is location
	var location = document.getElementById(field);
	
	if(curField.value != ""){
		curField.style.backgroundColor = "#ffffff"
		document.getElementById("CAT_Custom_41982").style.backgroundColor = "#ffffff";
		location.value = "";
		location.style.backgroundColor = "#ebebe4";
	}
}

function checkFeatured(field){
	if(field.checked == true){
		document.getElementById("featuredDesc").style.display = "block";
		document.getElementById("compLogo").style.display = "block";
		document.getElementById("cat_category").value = "featured";
	}else{
		document.getElementById("featuredDesc").style.display = "none";
		document.getElementById("CAT_Custom_42601").value = "";
		document.getElementById("compLogo").style.display = "none";
		document.getElementById("CAT_Custom_42550").value = "";
		//required to change the value of a type="file" input field in IE
		document.getElementById("CAT_Custom_42550").outerHTML = '<input class="cat_textbox" id="CAT_Custom_42550" type="file" value="" name="CAT_Custom_42550" />';
		document.getElementById("cat_category").value = "";
	}
	addAmount();
}

function setDatePosted(){
	var today = new Date();
	var month=new Array(12);
	month[0]="Jan";	month[1]="Feb";	month[2]="Mar";	month[3]="Apr";	month[4]="May";	month[5]="Jun";	month[6]="Jul";	month[7]="Aug";	month[8]="Sep";	month[9]="Oct";	month[10]="Nov";month[11]="Dec";
	document.getElementById("CAT_Custom_41980").value = today.getDate()+"-"+month[today.getMonth()]+"-"+today.getFullYear();
}

function changeExpire(field){
	var today = new Date();
	var addDays = parseInt(field.options[field.selectedIndex].value)
	var month=new Array(12);
	month[0]="Jan";	month[1]="Feb";	month[2]="Mar";	month[3]="Apr";	month[4]="May";	month[5]="Jun";	month[6]="Jul";	month[7]="Aug";	month[8]="Sep";	month[9]="Oct";	month[10]="Nov";month[11]="Dec";
	today.setDate(today.getDate()+addDays);
	document.getElementById("ExpiryDate").value = today.getDate()+"-"+month[today.getMonth()]+"-"+today.getFullYear();
	addAmount();
}

function addAmount(){
	var listLength = document.getElementById("CAT_Custom_42877");
	var addDays = parseInt(listLength.options[listLength.selectedIndex].value)
	
	if(isNaN(addDays)){
		addDays = 30;	
	}
	var multiplier = addDays/30;
	var cost = 0;
	if(document.getElementById("CAT_Custom_42549").checked == true){
		cost = 199*multiplier;
	}else{
		cost = 100*multiplier;
	}
	document.getElementById("Amount").value = cost;
}
