/* General use in CC */
var TD_COUNT_COL = 0;
var TD_COUNTRY = 1;
var TD_STATE = 2;
var TD_CITY = 3;
var LOCATION_LIMIT = 3;
var locationCount = 0;
var countryArr = new Array();
var stateArr = new Array();

function getAjaxServices(which){
	var serviceURL = "/services/casting_call_services.php";
	var countryCode = $("#idCcCountry").val();
	var countryCodeFirst = $("#idCcCountry option:first"); //work around for adding all selection
	
	var stateId = $("#idCcState").val();
	switch(which){
		case "state":	
			var ss = $("#idCcState");			
			var sc = $("#idCcCity");
			ss.empty();					
			sc.empty();		
			 $.ajax({
			   type: "POST",
			   url: serviceURL,
			   data: "fm_action=state&country_code=" + countryCode + "&first_option=" + countryCodeFirst.text(),
			   success: function(options){
			    	ss.append(options);
			   }
			 });
			break;
			
		case "city":
			var sc = $("#idCcCity");
			sc.empty();			
			 $.ajax({
			   type: "POST",
			   url: serviceURL,
			   data: "fm_action=city&state_id="+ stateId + "&first_option=" + countryCodeFirst.text(),
			   success: function(options){
			    	sc.append(options);
			    	$('#setCityWidth').css({'width':sc.width()+'px'});
			   }
			 });
			break;
	} //switch
} //getAjaxServices

function initGeoBlock(){
	$("#idCcCountry").change(function(){
		getAjaxServices('state');
	});	
	
	$("#idCcState").change(function(){
		getAjaxServices('city');	
	});	
	
	//getAjaxServices('state'); //DEFAULT TO US STATES
} //initGeoBlock()

function initGeoButton(){
	$("#idCcCity").change(function(){
		var locationBtn = 	$("#idCcAddButton");
		if(isSelectedGeo() && !isLocationOverLimit()){
			locationBtn.removeAttr("disabled");			
			toogleLocationBtn("enable");
		} else {
			locationBtn.attr("disabled", "disabled");				
			toogleLocationBtn("disable");
		}
	});	
}

function toogleLocationBtn(which){
	var locationBtn = 	$("#idCcAddButton");
	if(which == "enable"){
		locationBtn.removeClass("ccLocationDisableBtn");	
		locationBtn.addClass("ccLocationBtn");	
	} else {
		locationBtn.removeClass("ccLocationBtn");	
		locationBtn.addClass("ccLocationDisableBtn");	
	}
} //toogleLocationBtn

function inArray(needle, arr){
	for (i=0; i < arr.length; i++){
		thisValue = arr[i];
		if(thisValue == needle){
			return true;
			break;	
		}
	} //for	
	
	return false;
} //inArray

function removeGeo(){	
	var trNode = this.parentNode.parentNode;
	var tNode = trNode.parentNode;
	if(tNode != null){
		tNode.removeChild(trNode);
	}
	adjustGeoCount();
	if(locationCount >0){
		locationCount--;
	}
	if(!isLocationOverLimit()){
		$("#idCcAddButton").removeAttr("disabled");
		toogleLocationBtn("enable");
	} else {
		toogleLocationBtn("disable");	
	}
	
}

function presetRemoveGeo(){
	$(".removeGeo").click(removeGeo);	
}

function setGeoCount(){
	var locationTable = $el("idCcLocationTable");
	var trs = locationTable.getElementsByTagName("TR");
	locationCount = trs.length-1; //subtract first rows
}

function preconfig(){
	setGeoCount();
	presetRemoveGeo();
}

////////////////////// END - General use in all CC related /////////////////////////////////////

////////////////////// used in Post new Casting Call /////////////////////////////////////////

function initPostCastingCall(){
	initGeoBlock();	
	initCcPreview();
	doJQueryTooltips();
	initDate();
	initPaymentBox();
} //initPostCastingCall

function initPaymentBox(){
	var compOption = $("input[name='c_compensation']");
	var compBox = $("#compPayAmount");
	if(compOption[2].checked){
		compBox.show("fadeout");
	}
	
	compOption.click(function(){
		var thisVal = this.value;
///		var compBox = $("#compPayAmount");
		if(thisVal == 2){
			compBox.show("fadeout");
		} else {
			compBox.hide("fadein");	
		}
	});
}

function initNewCcForm(){
	$("#idNewCcForm").submit(function(){
		return storeGeo(false);					
	});
	
} //initNewCcForm - trigger when form sumbitted
	
	
function initAddLocation(){	
	btnLocation = $("#idCcAddButton");
	btnLocation.click(processLocation);
}

function processLocation(){
	var msg = "";	
	result = isSelectedGeo();
	if(!result){
		msg = "Country, States and City must be selected";
	}
	
	
	var geoObj = isOkToAddGeo();
	if(result && !geoObj.result){
		msg = geoObj.msg;
		result = false;
	}
	
	if(result && isLocationOverLimit()){
		msg = "Can not add more than 3 locations.";
		result = false;
	}
	if(result){
		createGeo();
		locationCount++;		
	} else {
		alert(msg);
	}
	
	if(isLocationOverLimit()){
		$("#idCcAddButton").attr("disabled", "disabled");
		toogleLocationBtn("disable");
	} else {
		toogleLocationBtn("enable");	
	}
} //processLocation()

function isLocationOverLimit(){
	return (locationCount >= LOCATION_LIMIT);
}

function isOkToAddGeo(){
	var rObj = new Object;
	var tempStateArr = new Array();
	var tempCountryArr = new Array();
	rObj.result = true;
	rObj.msg = "";
	var selectedCountry = getSelectedCountry().v;
	var selectedState = getSelectedState().v;
	var selectedCity = getSelectedCity().v;
	
	var locationTable = $el("idCcLocationTable");
	var trs = locationTable.getElementsByTagName("TR");
	//skip th - section title
	for(iTr =1; iTr < trs.length; iTr++){
		var thisCountryCode = "";
		var thisStateCode = "";
		var thisCityCode = "";
		var thisTr = trs[iTr];
		var tds = thisTr.getElementsByTagName("TD");
		if(tds.length > 0){
			thisCountryCode = tds[TD_COUNTRY].getAttribute("value");
			thisStateCode = tds[TD_STATE].getAttribute("value");
			thisCityCode = tds[TD_CITY].getAttribute("value");
		}
		
		if(selectedCountry == thisCountryCode && selectedState == thisStateCode && selectedCity == thisCityCode){
			rObj.result = false;
			rObj.msg = "Already added this location.";
			break;	
		}		
			
	} //tr loop	
	return rObj;
} //isOkToAddGeo
var locationError = false;
function storeGeo(storeAsPreview){
	var locationTable = $el("idCcLocationTable");
	var trs = locationTable.getElementsByTagName("TR");	
	var tempGeo = "";
	var delimiter = "";
	var result = false;
	
	//skip th - section title
	for(iTr =1; iTr < trs.length; iTr++){
		var thisCountryCode = "";
		var thisStateCode = "";
		var thisCityCode = "";
		var thisTr = trs[iTr];
		var tds = thisTr.getElementsByTagName("TD");
		if(tds.length > 0){
			if(storeAsPreview){
				thisCountryCode = tds[TD_COUNTRY].innerHTML;
				thisStateCode = tds[TD_STATE].innerHTML;
				thisCityCode = tds[TD_CITY].innerHTML;
			} else {
				thisCountryCode = tds[TD_COUNTRY].getAttribute("value");
				thisStateCode = tds[TD_STATE].getAttribute("value");
				thisCityCode = tds[TD_CITY].getAttribute("value");
			}
		}
		if(storeAsPreview){
			tempGeo = tempGeo + delimiter + thisCityCode + ", " + thisStateCode + ", " + thisCountryCode;
		} else {
			tempGeo = tempGeo + delimiter + thisCountryCode + "," + thisStateCode + "," + thisCityCode;	
		}
	 	delimiter = "|";
	} //tr loop
	
	if(tempGeo != ""){
		$("#idCcSelectedGeo").val(tempGeo);	
		result = true;
                validate_castingcallsTN();
	} else {	
		validate_castingcallsTN();
		if (!locationError) {
			$('#ccErrorBox').append('<b>You must select at least one location</b><br /><br />');
			locationError = true;
		}
        $('#ccErrorBox').show();
	}
	
	//alert($("#idCcSelectedGeo").val()); //for debug 
	return result;
} //storeGeo -- added selected geo to hidden


function createGeo(){
	var countryObj = getSelectedCountry();
	var stateObj = getSelectedState();
	var cityObj = getSelectedCity();
	var aa = $("#idCcLocationTable").append("<tr><td class='numberCell'>&nbsp;</td><td value='" + countryObj.v+ "'>" + countryObj.t + "</td><td value='" + stateObj.v + "'>"+ stateObj.t + "</td><td value='" + cityObj.v + "'>" + cityObj.t + "</td><td><a href='javascript:void(0)' class='removeGeo'>remove</a></td></tr>");	
		
	geoTracking(countryObj.v, stateObj.v);
	adjustGeoCount();
	$(".removeGeo").click(removeGeo);	
} //createGeo

function adjustGeoCount(){
	var locationTable = $el("idCcLocationTable");
	var trs = locationTable.getElementsByTagName("TR");	
	for(iTr =1; iTr < trs.length; iTr++){
		var thisTr = trs[iTr];	
		var tds = thisTr.getElementsByTagName("TD");
		tds[TD_COUNT_COL].innerHTML = iTr + ". ";		
	}
} //adjustGeoCount

function geoTracking(country, state){
	if(!inArray(country, countryArr)){
		countryArr.push(country);
	}
	//alert(inArray(state, stateArr) + " " + state);
	if(!inArray(state, stateArr)){
		stateArr.push(state);
	}
} //geoTracking()


function getSelectedCountry(){
	var result = new Object;
	result.v = "";
	result.t = "";
	selectedObj = $("#idCcCountry option:selected");
	if(selectedObj.val() != ""){
		result.v = selectedObj.val();	
		result.t = selectedObj.text();	
	}
	return result;
} //getSelectedCountry()

function getSelectedState(){	
	var result = new Object;
	result.v = "";
	result.t = "";
	selectedObj = $("#idCcState option:selected");
	if(selectedObj.val() != ""){
		result.v = selectedObj.val();	
		result.t = selectedObj.text();	
	}
	return result;
}

function getSelectedCity(){
	var result = new Object;
	result.v = "";
	result.t = "";
	selectedObj = $("#idCcCity option:selected");
	if(selectedObj.val() != ""){
		result.v = selectedObj.val();	
		result.t = selectedObj.text();		
	}
	return result;
} //getSelectedCity()

function isSelectedGeo(){		
	var country = getSelectedCountry().v;
	var state = getSelectedState().v;
	var city = getSelectedCity().v;
	return (country != "" && state != "" && city != "")?true: false;	
}

////////////////////// END - used in Post new Casting Call /////////////////////////////////////////

////////////////////// used in Post new TN Casting Call /////////////////////////////////////////

function initPostCastingCallTN(){
	initGeoBlock();
	initGeoButton();
	initAddLocation();
	initNewCcTnForm();
	preconfig();
	initCcPreview();
	doJQueryTooltips();
	initDate();
	initPaymentBox();
} //initPostCastingCallTN

function initNewCcTnForm(){
	$("#idNewCcTnForm").submit(function(){
		return storeGeo(false);					
	});
	
} //initNewCcForm - trigger when form sumbitted

////////////////////// END - used in Post new TN Casting Call /////////////////////////////////////////

////////////////////// used in Post new LA Casting Call /////////////////////////////////////////

function initPostCastingCallLA(){
	initGeoBlock();
	initCcPreview();
	doJQueryTooltips();	
	initPaymentBox();
} //initPostCastingCallTN

function initNewCcLaForm(){
	$("#idNewCcLaForm").submit(function(){
		return storeGeo(false);					
	});
	
} //initNewCcForm - trigger when form sumbitted

////////////////////// END - used in Post new LA Casting Call /////////////////////////////////////////


////////////////////// START - used in Edit Casting Call for all type/////////////////////////////////////////

function initEditCastingCall(which){
	initGeoBlock();
	if(which == "tn"){		
		initEditCcForm();
		preconfig();
	}
	if(which != "la"){
		initDate();	
	}
	initCcPreview();
	doJQueryTooltips();
	initPaymentBox();
} //initEditCastingCall


function initEditCcForm(){
	$("#idEditCcForm").submit(function(){
		return storeGeo(false);					
	});
	
} //initNewCcForm - trigger when form sumbitted
////////////////////// END - used in Edit Casting Call for all type/////////////////////////////////////////



////////////////////// used in Search / Main Casting Call /////////////////////////////////////////

function initCcSearch(){
	toggleSearchOption();
	toogleSearchType();
	initGeoBlock();
	doJQueryTooltips();
	initDate();
	initPaymentBox();
} //initCcSearch

function initDate(){
	var startDate = $("#dp-normal-1");
	startDate.change(toggleDate);
}
function toggleDate(){
	var startDate = this;
	var endDate = $("#dp-normal-2");	
	if(isValidDate(startDate.value.trim())){		
		var msecsInADay = 86400000;
		var tempDate = new Date(startDate.value);
		var endDateTimestamp = new Date(tempDate.getTime() + msecsInADay);
		var m = "" + (endDateTimestamp.getMonth()+1);
			m = (m.length < 2)? "0" + m : m;			
		var d = "" + endDateTimestamp.getDate();		
			d = (d.length < 2)?"0" + d : d;			
		var y = endDateTimestamp.getFullYear();
		
		endDate.val(m + "/" + d + '/' + y);		
	}
}


function toggleSearchOption(){
	var AdvanceElm = $("#advanceSearch a");
	var fmBasic = $("#basicAction");
	var showAdvanced = $("input[name='show_advanced']");
	AdvanceElm.click(function(e){
		e.preventDefault();
		$("#advanceOption").toggle("normal");
		var currLabel = AdvanceElm.text();
		if(currLabel == "Show Advanced [+]"){
			AdvanceElm.text("Hide Advanced [-]");
			fmBasic.hide();
			showAdvanced.val(1);
		} else {
			resetAdvanceField();
			AdvanceElm.text("Show Advanced [+]");
			fmBasic.show();
			showAdvanced.val(0);
		}
	}
	);
} //toogleSearchOption

function resetAdvanceField(){
	$(".w8em").val("");
	var tnInclude = $("input[name='search_include_tn']");
	tnInclude[2].checked = true;
	
	var nudity = $("input[name='c_18']");
	for(i=0; i < nudity.length; i++){
		nudity[i].checked = false;
	}	
	
	var comp = $("input[name='c_compensation']");	
	for(i=0; i < comp.length; i++){
		comp[i].checked = false;
	}	
	
	var keyword = $("input[name='search_keyword']");
	keyword.val("");
		
	var keyword = $("input[name='search_details']");
	keyword[0].checked = false;
		
	var sortby = $("input[name='search_sortby']");	
	for(i=0; i < sortby.length; i++){
		sortby[i].checked = false;
	}	
	
	var mmId = $("input[name='search_mm_id']");
	mmId.val("");
	
	var mmName = $("input[name='search_mm_name']");
	mmName.val("");
} //resetAdvanceField()

function toogleSearchType(){
	$("input[name='search_type']").click(function(){
		$("#idSearchCasting")[0].selectedIndex = -1;
		thisVal = this.value;		
		toogleInclude(thisVal);
	});	
} //toogleSearchType

function toogleInclude(which){	
	if(which == "looking for"){
		$("#idIncludeC").css("display", "none");				
		$("#idIncludeNC").css("display", "");					
	} else {
		$("#idIncludeNC").css("display", "none");				
		$("#idIncludeC").css("display", "");									
	}
} //toogleInclude

////////////////////// END - used in Search / Main Casting Call /////////////////////////////////////////

function $el(id){
	return document.getElementById(id);	
} //for some reason JQUERY won't work with some feature, need this for some customs

function initCcPreview(){
	initDialog();
	var previewBtn = $("#ccPreview");
	previewBtn.click(doCastingPreview);
}

function initDialog(){
	$(function(){
		$('#castingPreview').dialog({					
			autoOpen: false,					
			modal: true,					
			draggable: true,					
			resizable: false,	
			overlay: {						
				backgroundColor: '#000',						
				opacity: 0.5					
			},					
			width: 800,					
			height: 600,
			buttons: {				
				"Close": function() { 
					$(this).dialog("close");
				} 
			}
		});				
				
	});
}

function doCastingPreview(){
	var fm = this.form;
	var ccTypeArr = new Array();
	var pBox = $('#castingPreview');
	var cp = this.getAttribute("cp");
	var ccSection = getCastingDesc(cp);
	var ccTypeDesc = ccSection + ((cp != 'cc')?' as':'');
	
	$('#ccSection').html(ccSection);
	$('#ccTitle').html(getCcTitle(fm));
	$('#ccTypeDesc').html(ccTypeDesc);
	$('#ccTypeValue').html(getSelectedCastingType(fm));
	$('#pComp').html(getCompensation(fm));
	$('#nudeValue').html(getNudeDesc(fm));
	$('#startDateValue').html(getDateDesc(fm.elements['c_start_date'].value));
	$('#locationValue').html(getLocationDesc(fm, cp));
	
	if(cp == 'la'){
		var durationElm = fm.elements['c_duration'];
		var duration = durationElm.options[durationElm.selectedIndex].text;
		$('#endDateValue').html('<b><u>Duration: </u></b>' + duration);
	} else {
		$('#endDateValue').html('<b><u>End Date: </u></b><br/>' + getDateDesc(fm.elements['c_end_date'].value));
	}
	
	$('#detailValue').html(getDetailsDesc(fm));
	pBox.dialog('open');		
} //doCastingPreview

function getCompensation(fm){
	var strReturn = 'Required';
	var ccCompensationMap = new Array();	
	ccCompensationMap[0] = "Negotiable";
	ccCompensationMap[1] = "TF*";
	ccCompensationMap[2] = "Paid";
	ccCompensationMap[3] = "Unpaid";
	ccCompensationMap[4] = "TFMMVIP";
	
	var comps = fm.elements['c_compensation'];
	var compIndex = '';
	for(j=0; j < comps.length; j++){				
		if(comps[j].checked == true){
			compIndex = comps[j].value;
			break;
		}
	}		
	
	if(compIndex != ''){
		strReturn = ccCompensationMap[compIndex];
		if(compIndex == 2){
			strReturn = strReturn + ' (';
				var amount = fm.elements['c_compensation_amount'].value;		
				if(amount.length > 0){
					strReturn = strReturn + amount;
				} else {
					strReturn = strReturn + 'Required Amount';
				}
				strReturn = strReturn + ')';
		}
	}
	
	return strReturn;
}

function getSelectedCastingType(fm){
	var results;
	var ccTypeArr = new Array();
	var ccTypes = fm.elements['m_casting_type[]'];
		for(j=0; j < ccTypes.options.length; j++){
			if(ccTypes.options[j].selected){
				ccTypeArr.push(ccTypes.options[j].text);
			}
		}
		
	if(ccTypeArr.length > 0){
		results = ccTypeArr.join("<br/>");
	}
	return results; 
}
function getCastingDesc(type){	
	var strReturn = '';
	switch(type){
	case 'cc':
		strReturn = "I'm casting for";
		break;
	case 'tn':
	case 'la':
		strReturn = "I'm available";
		break;
	}	
	return strReturn;
}

function getCcTitle(fm){
	var title = fm.elements['c_title'].value;
	if(title.length >200){
	title = title.substring(0, 200);
	title = title.replace(new RegExp(/<[^>]*>/), "");
	title = title.replace(new RegExp(/[<>]/), "");
	}	
	return title;
}

function getNudeDesc(fm){	
	var nudes = fm.elements['c_18'];
	var strReturn = 'Required';
	for(j=0; j < nudes.length; j++){				
		if(nudes[j].checked == true){
			switch(nudes[j].value){
			case '0':
				strReturn = 'No';
				break;
			case '1':
				strReturn = 'Yes';
				break;
			case '2':
				strReturn = 'Both';
				break;	
			}		
		}
	}
	
	return strReturn;
}

function getDateDesc(dateValue){	
	if(dateValue.length > 0){
		return $.format.date(dateValue, 'MMM dd, yyyy');
	} else {
		return 'Required';
	}
}

function getLocationDesc(fm, cp){
	var strReturn = 'Required';
	if(cp == "tn"){
		storeGeo(true); //store seleted geo into hidden fields
		var selectedGeo = $("#idCcSelectedGeo").val();
		if(selectedGeo.length > 0){
			strReturn = selectedGeo.replace(new RegExp(/\|/g), "<br/>");			
		}
	} else {
		var cityElm = fm.elements['cc_city'];
		var city = cityElm.options[cityElm.selectedIndex].text;
		var stateElm = fm.elements['cc_state'];
		var state = stateElm.options[stateElm.selectedIndex].text;
		var countryElm = fm.elements['cc_country'];
		var country = countryElm.options[countryElm.selectedIndex].text;
		strReturn = '';
		if(city.length > 0){
			strReturn += city + ", ";
		} else {
			strReturn += 'City Required, ';
		}
		
		if(state.length > 0){
			strReturn += state + ", ";
		} else {
			strReturn += 'State Required, ';
		}
		
		if(country.length > 0){
			strReturn += country;
		} else {
			strReturn += 'Country Required';
		}	
	}
	
	return strReturn;
}

function getDetailsDesc(fm){
	var strReturn = 'Required';
	var details = fm.elements['c_details'].value;
	if(details.length > 0){		
		strReturn = details.substring(0, 5000);
		if(strReturn.length > 5000){
			thisValue = strReturn.substring(0, 5000);
		}
		strReturn = strReturn.replace(new RegExp(/\n/g), '<br/>');
		strReturn = strReturn.replace(new RegExp('/<[^>]*>/'), '');
		strReturn = strReturn.replace(new RegExp('/[<>]/'), '');
				
	}	
	return strReturn;
}

function doJQueryTooltips(){
	$(".jQueryTooltips").tooltip();
}

function initCastingAlert(){	
	initAlertDelete();
	initAlertViewFilter();
} //initCastingAlert

function initAlertViewFilter(){	
	//alertViewFilter
	$("a.alertViewFilter").click(function(){
		var viewURL = "/castingcalls_alert_view_filter.php?height=450&width=540&alert_id=" + this.getAttribute("alert_id");
		tb_show('Casting Calls - Filter Details',viewURL , false);
	});
} //initAlertViewFilter

function initAlertDelete(){
	$("a.alertDelete").click(function(){
		var deleteConfirm = confirm("Are you sure you want to delete this setting?");
		if(deleteConfirm){
			var deleteURL = "/mystuff/member_casting_alerts/delete_casting/" + this.getAttribute("alert_id");
			window.location.href=deleteURL;
		}
	});	
}

function initAlertSetting(){
	$("a#alertSubmit").click(function(){
		var ahref = this.href;
		var alertName = $("input#alertName").val();
		this.href= ahref + "&alert_name=" + alertName;
	}
	);	
}

jQuery.fn.extend(
{
	trim: function(){
		return jQuery.trim(this);
	}	
}
);

function validate_castingcalls(){
    var bReturn = true;
    var strError = '';
	$('#ccErrorBox').hide();
    if (document.new_casting.c_title.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Title is required</b><br /><br />';
       bReturn = false;
    }else{
       if (document.new_casting.c_title.value.length<8){
          $('#ccErrorBox').show();
          strError += '<b>The title is too short. Please write at least 8 characters.</b><br /><br />';
          $('#ccErrorBox').focus();
          document.new_casting.c_title.focus();
          bReturn = false;
       }

    }
    //c_details validation
    if (document.new_casting.c_details.value.length==0){
       $('#ccErrorBox').show();
       //$('#casting_error').html('<b>Please add a description</b>');
       strError += '<b>Please add a description</b><br /><br />';
       //$('#ccErrorBox').focus();
       document.new_casting.c_details.focus();
       bReturn = false;
    }else{
       if (document.new_casting.c_details.value.length<50){
          $('#ccErrorBox').show();
          //document.getElementById('casting_error').innerHTML = "<b>The description is to short, write at least 50 characters</b>";
          strError += '<b>The description is too short. Please write at least 50 characters.</b><br /><br />';
          //document.new_casting.c_details.focus();
          bReturn = false;
       }

    }
    if (document.new_casting.m_casting_type.value==''){
       $('#ccErrorBox').show();
       strError += '<b>Please select an option from casting type</b><br /><br />';
       $('#ccErrorBox').focus();
       bReturn = false;
    }

    regex=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/

    if(!regex.exec(document.new_casting.c_start_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a date</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    if(!regex.exec(document.new_casting.c_end_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a end date</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate casting_type
   var bSel = false;
   $('#m_casting_type option').each(function(){
           if(($(this).attr('selected')) == true){
               bSel = true;
               return;
           }
    });
    if(!bSel){
        $('#ccErrorBox').show();
     	//$('#casting_error').html('<b>Select an artist type</b>');
        strError += '<b>Select an artist type</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate nudity
    var bRadio = false;
    $('#nudity_c18 input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a nudity type</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //validate casting_compensation
    var bRadio = false;
    $('#Ccompensation input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a casting compensation type.</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
   //Validate selected state
   
    if($('#idCcState option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a state</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate selected_city
   
    if($('#idCcCity option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a city</b><br /><br />';
        bReturn = false;
    }
    $('#casting_error').html(strError);
    $('#ccErrorBox').focus();
    return bReturn;
}
function validate_castingcallsLA(){
    var bReturn = true;
    var strError = '';
	$('#ccErrorBox').hide();
    if (document.new_la_casting.c_title.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Title is required</b><br /><br />';
       $('#ccErrorBox').focus();
       bReturn = false;
    }else{
       if (document.new_la_casting.c_title.value.length<8){
          $('#ccErrorBox').show();
          strError += '<b>The title is too short. Please write at least 8 characters</b><br /><br />';
          $('#ccErrorBox').focus();
          bReturn = false;
       }
    }
    //c_details validation
    if (document.new_la_casting.c_details.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Please add a description</b><br /><br />';
       $('#ccErrorBox').focus();
       bReturn = false;
    }else{
       if (document.new_la_casting.c_details.value.length<50){
          $('#ccErrorBox').show();
          strError += '<b>The description is too short. Please write at least 50 characters.</b><br /><br />';
          bReturn = false;
       }

    }
    if (document.new_la_casting.m_casting_type.value==''){
       $('#ccErrorBox').show();
       strError += '<b>Please select an artist type</b><br /><br />';
       bReturn = false;

    }

    regex=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/

    if(!regex.exec(document.new_la_casting.c_start_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a date</b><br /><br />';
        bReturn = false;
    }
    //Validate nudity
    var bRadio = false;
    $('#nudity_c18 input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a nudity type</b><br /><br />';
        bReturn = false;
    }
    //validate casting_compensation
    var bRadio = false;
    $('#Ccompensation input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a casting compensation type.</b><br /><br />';
        bReturn = false;
    }
    //Validate selected state
   
   if($('#idCcState option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a state</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate selected_city
   if($('#idCcCity option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a city</b><br /><br />';
        bReturn = false;
    }
    $('#casting_error').html(strError);
    $('#ccErrorBox').focus();
    return bReturn;
}
function validate_castingcallsTN(){
    var bReturn = true;
    var strError = '';
	$('#ccErrorBox').hide();
    if (document.new_tn_casting.c_title.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Title is required</b><br /><br />';
       bReturn = false;
    }else{
       if (document.new_tn_casting.c_title.value.length<8){
          $('#ccErrorBox').show();
          strError += '<b>The title is too short. Please write at least 8 characters.</b><br /><br />';
          bReturn = false;
       }
    }
    //c_details validation
    if (document.new_tn_casting.c_details.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b><b>Please add a description</b><br /><br />';
       bReturn = false;
    }else{
       if (document.new_tn_casting.c_details.value.length<50){
          $('#ccErrorBox').show();
          strError += '<b>The description is too short. Please write at least 50 characters.</b><br /><br />';
          bReturn = false;
       }
    }
    if (document.new_tn_casting.m_casting_type.value==''){
       $('#ccErrorBox').show();
       strError += '<b>Please select an option from casting type</b><br /><br />';
       bReturn = false;
    }

    regex=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/

    if(!regex.exec(document.new_tn_casting.c_start_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a date</b><br /><br />';
        bReturn = false;
    }
    //Validate casting_type
    var bSel = false;
   $('#m_casting_type option').each(function(){
           if(($(this).attr('selected')) == true){
               bSel = true;
               return;
           }
    });
    if(!bSel){
        $('#ccErrorBox').show();
        strError += '<b>Select an artist type</b><br /><br />';
        bReturn = false;
    }
    //Validate nudity
    var bRadio = false;
    $('#nudity_c18 input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a nudity type</b><br /><br />';
        bReturn = false;
    }
    //validate casting_compensation
    var bRadio = false;
    $('#Ccompensation input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a casting compensation type.</b><br /><br />';
        bReturn = false;
    }  
    //INSERT ERROR HERE
    $('#casting_error').html(strError);
    $('#ccErrorBox').focus();
    return bReturn;
}

function validate_castingcalls_edit(){
    var bReturn = true;
    var strError = '';
    if (document.edit_casting.c_title.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Title is required</b><br /><br />';
       bReturn = false;
    }else{
       if (document.edit_casting.c_title.value.length<8){
          $('#ccErrorBox').show();
          strError += '<b>The title is too short. Please write at least 8 characters.</b><br /><br />';
          bReturn = false;
       }

    }
    //c_details validation
    if (document.edit_casting.c_details.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Please add a description</b><br /><br />';
       bReturn = false;
    }else{
       if (document.edit_casting.c_details.value.length<50){
          $('#ccErrorBox').show();
          strError += '<b>The description is too short. Please write at least 50 characters.</b><br /><br />';
          bReturn = false;
       }

    }
    if (document.edit_casting.m_casting_type.value==''){
       $('#ccErrorBox').show();
       strError += '<b>Please select an option from casting type</b><br /><br />';
       bReturn = false;

    }

    regex=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/

    if(!regex.exec(document.edit_casting.c_start_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a date</b><br /><br />';
        bReturn = false;
    }
    if(!regex.exec(document.edit_casting.c_end_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a end date</b><br /><br />';
        bReturn = false;
    }
    //Validate casting_type
    var bSel = false;
   $('#m_casting_type option').each(function(){
           if(($(this).attr('selected')) == true){
               bSel = true;
               return;
           }
    });
    if(!bSel){
        $('#ccErrorBox').show();
        strError += '<b>Select an artist type</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate nudity
    var bRadio = false;
    $('#nudity_c18 input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a nudity type</b><br /><br />';
        bReturn = false;
    }
    //validate casting_compensation
    var bRadio = false;
    $('#Ccompensation input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a casting compensation type.</b><br /><br />';
        bReturn = false;
    }
    //Validate selected state
    if($('#idCcState option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a state</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate selected_city
    if($('#idCcCity option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a city</b><br /><br />';
        bReturn = false;
    }
    $('#casting_error').html(strError);
    $('#ccErrorBox').focus();
    return bReturn;
}

function validate_castingcalls_editLA(){
    var bReturn = true;
    var strError = "";
    if (document.edit_casting.c_title.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b>Title is required</b><br /><br />';
       bReturn = false;
    }else{
       if (document.edit_casting.c_title.value.length<8){
          $('#ccErrorBox').show();
          strError += '<b>The title is too short. Please write at least 8 characters.</b><br /><br />';
          bReturn = false;
       }

    }
    //c_details validation
    if (document.edit_casting.c_details.value.length==0){
       $('#ccErrorBox').show();
       strError += '<b><b>Please add a description</b><br /><br />';
       bReturn = false;
    }else{
       if (document.edit_casting.c_details.value.length<50){
          $('#ccErrorBox').show();
          strError += '<b>The description is too short. Please write at least 50 characters.</b><br /><br />';
          bReturn = false;
       }

    }
    if (document.edit_casting.m_casting_type.value==''){
       $('#ccErrorBox').show();
       strError += '<b>Please select an option from casting type</b><br /><br />';
       bReturn = false;

    }

    regex=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/

    if(!regex.exec(document.edit_casting.c_start_date.value))
    {
        $('#ccErrorBox').show();
        strError += '<b>Please choose a date</b><br /><br />';
        bReturn = false;
    }

    //Validate casting_type
    var bSel = false;
   $('#m_casting_type option').each(function(){
           if(($(this).attr('selected')) == true){
               bSel = true;
               return;
           }
    });
    if(!bSel){
        $('#ccErrorBox').show();
        strError += '<b>Select an artist type</b><br /><br />';
        bReturn = false;
    }
    //Validate nudity
    var bRadio = false;
    $('#nudity_c18 input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a nudity type</b><br /><br />';
        bReturn = false;
    }
    //validate casting_compensation
    var bRadio = false;
    $('#Ccompensation input:radio').each(function(i,val){
        if(val.checked == true){
            bRadio = true;
            return;
        }
    });
    if(!bRadio){
        $('#ccErrorBox').show();
        strError += '<b>Select a casting compensation type.</b><br /><br />';
        bReturn = false;
    }
    //Validate selected state
   var bSel = false;
    if($('#idCcState option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a state</b><br /><br />';
        $('#ccErrorBox').focus();
        bReturn = false;
    }
    //Validate selected_city
   var bSel = false;
    if($('#idCcCity option:selected').val() == ''){
        $('#ccErrorBox').show();
        strError += '<b>Please select a city</b><br /><br />';
        bReturn = false;
    }
    $('#casting_error').html(strError);
    $('#ccErrorBox').focus();
    return bReturn;
}



