/*
(C) Copyright MarketLive. 2007. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning:This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

$(document).ready(function() {	

    $('#state').change(function(){ 
	 var stateValue = $('#state').attr('value'); 
     makeCityList(stateValue, ""); 
  });

      $('#state2').change(function(){ 		  
	 var stateValue = $('#state2').attr('value');
     makeCityList(stateValue, "manageCity"); 
  });
  
    $('#search').click(function(){ 
	 var stateValue = $('#state').attr('value'); 
 	 var cityValue = $('#city').attr('value'); 
	 var nameValue = $('#schoolName').attr('value'); 
	 searchSchools(stateValue, cityValue, nameValue);
  });

  
  
    $('#searchBySourceCode').click(function(){ 
	 var sourceCode = $('#sourceCode').attr('value');  	
	 searchSchoolsBySourceCode(sourceCode);
  });

	sizeIt();
}); 

function makeCityList(stateValue, param) {	 
   var dataString = "state="+stateValue;  
   if (param != "")
   {
	   dataString = dataString + "&param=" + param;
   }
   //alert("dataString="+dataString); 	  
	$.ajax({
	    type: "POST",
	    url: '/getcity.do?preview=frenchtoast', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
			//alert("response="+response);
		    if(response != null){
				$('#city').children().remove().end().append('<option value="0">Select City</option>') ; 
				$('#city').append(response);		                   
		    } //end if	
		}//end function
	});

} 
  
function searchSchools(stateValue, cityValue, nameValue) {	 
   var dataString = "state="+stateValue + "&city="+cityValue + "&name=" + nameValue;  
	$.ajax({
	    type: "POST",
	    url: '/adminManageSchools.do?preview=frenchtoast&method=search', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				//alert("output="+response);
				$("#schoolsTable").children().remove(); 
				$('#schoolsTable').append('<tr><th>School Name</th><th>Source Code</th><th>City</th><th>State</th><th>Zip Code</th><th>Action</th><th>Dress Code</th></tr>'); 
				$('#schoolsTable').append(response);
		    } //end if	
		}//end function
	});

} 




function searchSchoolsBySourceCode(sourceCodeValue) {	 
   var dataString = "sourceCode="+sourceCodeValue;  
	$.ajax({
	    type: "POST",
	    url: '/adminManageSchools.do?preview=frenchtoast&method=searchBySourceCode', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				//alert("source code output="+response);
				$("#schoolsTable").children().remove(); 
				$('#schoolsTable').append('<tr><th>School Name</th><th>Source Code</th><th>City</th><th>State</th><th>Zip Code</th><th>Action</th><th>Dress Code</th></tr>'); 
				$('#schoolsTable').append(response);
		    } //end if	
		}//end function
	});

} 


function removeAndSearchByName(idToRemove, stateValue, cityValue, nameValue) {	 
   var dataString = "id=" + idToRemove + "&state="+stateValue + "&city="+cityValue + "&name=" + nameValue;  
	$.ajax({
	    type: "POST",
	    url: '/adminManageSchools.do?preview=frenchtoast&method=removeAndSearchAgain', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				//alert("output="+response);
				$("#schoolsTable").children().remove(); 
				$('#schoolsTable').append('<tr><th>School Name</th><th>Source Code</th><th>City</th><th>State</th><th>Zip Code</th><th>Action</th><th>Dress Code</th></tr>'); 
				$('#schoolsTable').append(response);
		    } //end if	
		}//end function
	});

} 

function removeAndSearchBySourceCode(idToRemove, sourceCodeValue) {	 
   var dataString = "id=" + idToRemove + "&sourceCode="+sourceCodeValue;  
	$.ajax({
	    type: "POST",
	    url: '/adminManageSchools.do?preview=frenchtoast&method=removeAndSearchBySourceCodeAgain', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				//alert("source code output="+response);
				$("#schoolsTable").children().remove(); 
				$('#schoolsTable').append('<tr><th>School Name</th><th>Source Code</th><th>City</th><th>State</th><th>Zip Code</th><th>Action</th><th>Dress Code</th></tr>'); 
				$('#schoolsTable').append(response);
		    } //end if	
		}//end function
	});

} 


function removePOC(idToRemove) {	 
   var dataString = "ContactID=" + idToRemove;  
	$.ajax({
	    type: "POST",
		url: '/adminSchoolContactList.do?preview=frenchtoast&method=delete', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				location.reload();			
		    } //end if	
		}//end function
	});

} 


function showDressCodeList(schoolID, param) {	 
   var dataString = "SchoolID=" + schoolID + "&method=" + param;  
	$.ajax({
	    type: "POST",
		url: '/adminSchoolDressCode.do?preview=frenchtoast&', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				var index = response.indexOf('No Dress Codes found', 0);

				if (index<0) { // The Dress-Codes Header and Table is displayed only if results are there.
				$("#dressCodeTable").children().remove();
					$('#dressCodeTable').append('<tr><td><H1>Dress Codes</H1></td></tr>');
				$('#dressCodeTable').append('<tr><th>Dress Code Name</th><th>Dress Code Desc</th><th>Dress Code Type</th><th>Gender</th><th>Active</th><th>Action</th></tr>'); 
				$('#dressCodeTable').append(response);
				} else{
					$("#dressCodeTable").children().remove();
					$('#dressCodeTable').append('<tr><td></td></tr>');
				} //end if - index check

		    } //end if	
		}//end function
	});
}

function removeDressCode(type, idToRemove) {	 
   var dataString = "dressCodeID=" + idToRemove + "&dressCodeType=" + type; 
	$.ajax({
	    type: "POST",
		url: '/adminSchoolDressCode.do?preview=frenchtoast&method=remove&', //hardcoded for FrenchToast
	    data: dataString,
	    success: function(response) {
		    if(response != null){
				$("#dressCodeTable").children().remove();
				$('#dressCodeTable').append('<tr><th>Dress Code Name</th><th>Dress Code Desc</th><th>Dress Code Type</th><th>Gender</th><th>Active</th><th>Action</th></tr>'); 
				$('#dressCodeTable').append(response);
		    } //end if
		}//end function
	});

} 
 

