function flip(element){
	if($('#'+element+'_search').css('display')=='none'){
		$('#'+element+'_search').slideDown();
		$('#'+element+'_image').attr('src','images/catminus.gif');
	}else{
        $('#'+element+'_search').slideUp();
        $('#'+element+'_image').attr('src','images/catplus.gif');
	}
}

function flip_open(){

	if($('#advanced_search').css('display')=='none'){
		$('#advanced_search').slideDown();
		$('#flip_image').attr('src','images/catminus.gif');
	}else{
        $('#advanced_search').slideUp();
        $('#flip_image').attr('src','images/catplus.gif');
	}
}

function flip_open2(){

	if($('#admin_search').css('display')=='none'){
		$('#admin_search').slideDown();
		$('#flip_image2').attr('src','images/catminus.gif');
	}else{
        $('#admin_search').slideUp();
        $('#flip_image2').attr('src','images/catplus.gif');
	}

}
function flip_open3(){
	if($('#resume_search').css('display')=='none'){
		$('#resume_search').slideDown();
		$('#flip_image3').attr('src','images/catminus.gif');
	}else{
        $('#resume_search').slideUp();
        $('#flip_image3').attr('src','images/catplus.gif');
	}
}
function flip_open_new(div_id,image_id){
	if($('#'+div_id).css('display')=='none'){
		$('#'+div_id).slideDown();
		$('#'+image_id).attr('src','images/catminus.gif');
	}else{
        $('#'+div_id).slideUp();
        $('#'+image_id).attr('src','images/catplus.gif');
	}
}
function closePopup(){
	document.getElementById('the_form').style.display='none';
}

//resume
function resumeAddLine(resume_section,columns){
	var count_element=document.getElementById('resume_count_'+resume_section);

	var additional_element=document.getElementById('additional_resume_'+resume_section);
	var the_count=count_element.value;
	count_element.value++;
	the_return='<TABLE cellpadding=2 cellspacing=0 class="searchmaintable" width="75%"><TR>';
	for(x=0;x<columns;x++){
		the_return+='<TD width="'+Math.floor(100/columns)+'%"><INPUT TYPE=text name="resume['+resume_section+']['+the_count+']['+x+']"></TD>';
	}
	the_return+='</TR></TABLE>';
	additional_element.innerHTML+=the_return;
}

//news
function listNews(){
	http.open("GET", "?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&startdate="+document.getElementById('search_start_date').value+"&type="+document.getElementById('search_type').value+"&enddate="+document.getElementById('search_end_date').value+"&subject="+document.getElementById('search_subject').value, true);
	http.onreadystatechange = listNewsResponse;
	http.send(null);
}
function listNewsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('item_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

function editNews(passed_id){
	http.open("GET", "?mode=AJAX&action=edit&id="+passed_id, true);
	http.onreadystatechange = editNewsResponse;
	http.send(null);
}
function editNewsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
			tinyMCE.idCounter=0;
			tinyMCE.execCommand('mceAddControl', true, 'body');
		}else{
			alert('Something is wrong!');
		}
	}
}

function deleteNews(passed_id){
	http.open("GET", "?mode=AJAX&action=delete&id="+passed_id, true);
	http.onreadystatechange = deleteNewsResponse;
	http.send(null);
}
function deleteNewsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			listNews();
		}else{
			alert('Something is wrong!');
		}
	}
}
//news
function listProjects(){
	http.open("GET", "?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&type="+document.getElementById('search_type').value+"&name="+document.getElementById('search_name').value, true);
	http.onreadystatechange = listProjectsResponse;
	http.send(null);
}
function listProjectsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('item_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

function listAdministrators(){
	http.open("GET", "?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&type="+document.getElementById('search_type').value+"&name="+document.getElementById('search_name').value, true);
	
	
	http.onreadystatechange = listAdministratorsResponse;
	http.send(null);
}
function listAdministratorsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('item_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}


function deleteModelPhoto(picId,modelId){
    var confirm = window.confirm('Are you sure you want to delete this image?');
    if(confirm){
        window.location="photo_upload.php?action=delete&picId="+picId+"&modelId="+modelId;
    }
}
function deleteNijah_ModelPhoto(picId,modelId){
    var confirm = window.confirm('Are you sure you want to delete this image?');
    if(confirm){
        window.location="photo_upload.php?action=deleteNijah&picId="+picId+"&modelId="+modelId;
    }
}

function editProject(passed_id){
	http.open("GET", "?mode=AJAX&action=edit&id="+passed_id, true);
	http.onreadystatechange = editProjectResponse;
	http.send(null);
}
function editProjectResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}



function editAdmin(passed_id){
	http.open("GET", "?mode=AJAX&action=edit&id="+passed_id, true);
	http.onreadystatechange = editProjectResponse;
	http.send(null);
}
function editAdminResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}

function deleteProject(passed_id){
	http.open("GET", "?mode=AJAX&action=delete&id="+passed_id, true);
	http.onreadystatechange = deleteProjectResponse;
	http.send(null);
}
function deleteProjectResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			listProjects();
		}else{
			alert('Something is wrong!');
		}
	}
}

function deleteAdmin(passed_id){
	http.open("GET", "?mode=AJAX&action=delete&id="+passed_id, true);
	http.onreadystatechange = deleteProjectResponse;
	http.send(null);
}
function deleteAdminResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			listAdministrators();
		}else{
			alert('Something is wrong!');
		}
	}
}

//search options
function SearchOptionResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('item_table').innerHTML=http.responseText;
			if(alertmessage!="") alert(alertmessage);
		}else{
			alert('Something is wrong!');
		}
	}
}

function saveSearchOption(passed_item){
	alertmessage="Item Saved";
	http.open("GET", "search_options.php?mode=AJAX&action=update&id="+passed_item+"&name="+document.getElementById('name_edit_'+passed_item).value+"&category="+document.getElementById('category_filter').value, true);
	http.onreadystatechange = SearchOptionResponse;
	http.send(null);
}

function addSearchOption(){
	alertmessage="";
	http.open("GET", "search_options.php?mode=AJAX&action=insert&name="+document.getElementById('name').value+"&category="+document.getElementById('category_filter').value, true);
	http.onreadystatechange = SearchOptionResponse;
	http.send(null);
}

function deleteSearchOption(passed_item){
	alertmessage="";
	http.open("GET", "search_options.php?mode=AJAX&action=delete&id="+passed_item+"&category="+document.getElementById('category_filter').value, true);
	http.onreadystatechange = SearchOptionResponse;
	http.send(null);
}

function showSearchOptions(){
	alertmessage="";
	http.open("GET", "search_options.php?mode=AJAX&action=show&category="+document.getElementById('category_filter').value, true);
	http.onreadystatechange = SearchOptionResponse;
	http.send(null);
}

//system settings
function updateAccount(){
	http.open("GET", "system_account.php?mode=AJAX&action=save&email="+document.getElementById('email').value+"&lines="+document.getElementById('lines').value+"&username="+document.getElementById('username').value+"&password="+document.getElementById('password').value+"&id="+document.getElementById('system_id').value, true);
	http.onreadystatechange = updateAccountResponse;
	http.send(null);
}
function updateAccountResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			alert('Account Updated!');
		}else{
			alert('Something is wrong!');
		}
	}
}

function newAccount(){
	http.open("GET", "system_account.php?mode=AJAX&action=new&email="+document.getElementById('email').value+"&lines="+document.getElementById('lines').value+"&username="+document.getElementById('username').value+"&password="+document.getElementById('password').value+"&id="+document.getElementById('system_id').value, true);
	http.onreadystatechange = newAccountResponse;
	http.send(null);
}
function newAccountResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			alert('New Account Created!');
		}else{
			alert('Something is wrong!');
		}
	}
}

//representatives
function listRepresentatives(){
	http.open("GET", "representatives.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&name="+document.getElementById('search_name').value+"&email="+document.getElementById('search_email').value+"&state="+document.getElementById('search_state').value+"&country="+document.getElementById('search_country').value, true);
	http.onreadystatechange = listRepresentativesResponse;
	http.send(null);
}
function listRepresentativesResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('representative_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

function editRepresentative(passed_representative){
	http.open("GET", "representatives.php?mode=AJAX&action=edit&id="+passed_representative, true);
	http.onreadystatechange = editRepresentativeResponse;
	http.send(null);
}
function editRepresentativeResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}

function deleteRepresentative(passed_representative){
	http.open("GET", "representatives.php?mode=AJAX&action=delete&id="+passed_representative, true);
	http.onreadystatechange = deleteRepresentativeResponse;
	http.send(null);
}
function deleteRepresentativeResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			listRepresentatives();
		}else{
			alert('Something is wrong!');
		}
	}
}

//industry professionals
function listIndustryProfessionals(){
	http.open("GET", "industry_professionals.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&name="+document.getElementById('search_name').value+"&email="+document.getElementById('search_email').value+"&state="+document.getElementById('search_state').value+"&country="+document.getElementById('search_country').value, true);
	http.onreadystatechange = listIndustryProfessionalsResponse;
	http.send(null);
}
function listIndustryProfessionalsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('IndustryProfessional_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

//industry professionals
function listIndustryProfessionalsExport(){
	http.open("GET", "industry_professionals.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&name="+document.getElementById('search_name').value+"&email="+document.getElementById('search_email').value+"&state="+document.getElementById('search_state').value+"&country="+document.getElementById('search_country').value, true);
	http.onreadystatechange = listIndustryProfessionalsResponseExport;
	http.send(null);
}
function listIndustryProfessionalsResponseExport(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('IndustryProfessional_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}


function approveIndustryProfessional(passed_IndustryProfessional){
	http.open("GET", "pending_industry_professionals.php?mode=AJAX&action=approve&id="+passed_IndustryProfessional, true);
	http.onreadystatechange = listPendingIndustryProfessionalsResponse;
	http.send(null);
}

function denyIndustryProfessional(passed_IndustryProfessional){
	http.open("GET", "pending_industry_professionals.php?mode=AJAX&action=deny&id="+passed_IndustryProfessional, true);
	http.onreadystatechange = listPendingIndustryProfessionalsResponse;
	http.send(null);
}

function listPendingIndustryProfessionals(){
	http.open("GET", "pending_industry_professionals.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount, true);
	http.onreadystatechange = listPendingIndustryProfessionalsResponse;
	http.send(null);
}
function listPendingIndustryProfessionalsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('IndustryProfessional_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

function postQuoteRep(the_id){
	http.open("GET", "representatives.php?mode=AJAX&action=post_quote&id="+the_id, true);
	http.onreadystatechange = QuoteResponse;
	http.send(null);
}
function postQuote(the_id){
	http.open("GET", "industry_professionals.php?mode=AJAX&action=post_quote&id="+the_id, true);
	http.onreadystatechange = QuoteResponse;
	http.send(null);
}
function QuoteResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			alert('Quote Posted As News!');
		}else{
			alert('Something is wrong!');
		}
	}
}

function viewIndustryProfessional(passed_IndustryProfessional){
	http.open("GET", "pending_industry_professionals.php?mode=AJAX&action=view&id="+passed_IndustryProfessional, true);
	http.onreadystatechange = viewIndustryProfessionalResponse;
	http.send(null);
}
function viewIndustryProfessionalResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}

function editIndustryProfessional(passed_IndustryProfessional){
	http.open("GET", "industry_professionals.php?mode=AJAX&action=edit&id="+passed_IndustryProfessional, true);
	http.onreadystatechange = editIndustryProfessionalResponse;
	http.send(null);
}
function editIndustryProfessionalResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}

function deleteIndustryProfessional(passed_IndustryProfessional){
	http.open("GET", "industry_professionals.php?mode=AJAX&action=delete&id="+passed_IndustryProfessional, true);
	http.onreadystatechange = deleteIndustryProfessionalResponse;
	http.send(null);
}
function deleteIndustryProfessionalResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			listIndustryProfessionals();
		}else{
			alert('Something is wrong!');
		}
	}
}

//model notes
function modelNotes(passed_Model){
	http.open("GET", "model_search.php?mode=AJAX&action=notes&id="+passed_Model, true);
	http.onreadystatechange = modelNotesResponse;
	http.send(null);
}
function modelNotesResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('the_form').innerHTML = http.responseText;
			top_value=document.body.scrollTop;
			left_value=document.body.scrollLeft;
			if(top_value<1){top_value=document.documentElement.scrollTop;}
			if(left_value<1){left_value=document.documentElement.scrollLeft;}
			top_value+=80;
			left_value+=200;
			document.getElementById('the_form').style.left=left_value+'px';
			document.getElementById('the_form').style.top=top_value+'px';
			document.getElementById('the_form').style.display='block';
		}else{
			alert('Something is wrong!');
		}
	}
}

function editModel(model_id){
	the_width=970;
	the_height=500;
	the_top=50;
	the_left=100;
	window.open('model_add.php?id='+model_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,resizable=yes,top='+the_top+',left='+the_left);
}
function showModelFamily(model_id){
	the_width=200;
	the_height=300;
	the_top=50;
	the_left=100;
	window.open('list_family.php?id='+model_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,resizable=yes,top='+the_top+',left='+the_left);
}
function showModel(model_id){
	the_width=950;
	the_height=500;
	the_top=50;
	the_left=100;
	window.open('model_add.php?editable=no&id='+model_id,'_blank','width='+the_width+',height='+the_height+',scrollbars=yes,resizable=yes,top='+the_top+',left='+the_left);
}


//checkusername
function checkUsername(){
	if(document.getElementById('model_first_name').value!='' && document.getElementById('model_last_name').value!=''){
		var passed_name=document.getElementById('model_first_name').value.substring(0,3)+document.getElementById('model_last_name').value.substring(0,3);
		http.open("GET", "model_add.php?mode=AJAX&action=check_username&username="+passed_name, true);
		http.onreadystatechange = checkUsernameResponse;
		http.send(null);
	}
}
function checkUsernameResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('model_username').value = http.responseText.replace(/^\s+|\s+$/g,"");
		}else{
			//alert('Something is wrong!');
		}
	}
}
/*
function checkUsername(){
	if(document.getElementById('model_first_name').value!='' && document.getElementById('model_last_name').value!=''){
		var passed_name=document.getElementById('model_first_name').value.substring(0,3)+document.getElementById('model_last_name').value.substring(0,3);
		http.open("GET", "model_add.php?mode=AJAX&action=check_username&username="+passed_name+"&model_id="+document.getElementById('id').value, true);
		http.onreadystatechange = checkUsernameResponse;
		http.send(null);
	}
}*/
function checkUsernameResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('model_username').value = http.responseText.replace(/^\s+|\s+$/g,"");
		}else{
			//alert('Something is wrong!');
		}
	}
}
//list models
function listModels(page){
	theform=document.getElementById('hidden_form');
	http.open("POST", "model_search.php", true);
	http.onreadystatechange = listModelsResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	parameters="mode=AJAX&action=show";
	for(var x=0;x<theform.elements.length;x++){
		parameters+="&"+theform.elements[x].name+"="+encodeURI(theform.elements[x].value);
	}
	http.send(parameters+"&page="+page);
}
function listModelsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('model_table').innerHTML=http.responseText;
		}else{
			alert('Something is wrong!');
		}
	}
}

//select models
function select_all_checkboxes(){
	theform=document.getElementById('request_form');
	var got_value=false;
	for(var x=0;x<theform.elements.length;x++){
		if(theform.elements[x].type=="checkbox"){
			if(!got_value){
				final_checked=theform.elements[x].checked;
				got_value=true;
			}
			theform.elements[x].checked=!final_checked;
		}
	}
}

//email models
function emailModels(){
	theform=document.getElementById('request_form');
	http.open("POST", "model_search.php", true);
	http.onreadystatechange = requestModelsResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	parameters="mode=AJAX&action=email_by_array";
	for(var x=0;x<theform.elements.length;x++){
		if(theform.elements[x].type=="checkbox" && theform.elements[x].checked){
			parameters+="&"+theform.elements[x].name+"="+encodeURI(theform.elements[x].value);
		}
	}
	http.send(parameters);
}

function emailAllModels(){
	theform=document.getElementById('hidden_form');
	http.open("POST", "model_search.php", true);
	http.onreadystatechange = requestModelsResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	parameters="mode=AJAX&action=email_by_query";
	for(var x=0;x<theform.elements.length;x++){
		parameters+="&"+theform.elements[x].name+"="+encodeURI(theform.elements[x].value);
	}
	http.send(parameters);
}

//request models
function requestModels(){
	theform=document.getElementById('request_form');
	http.open("POST", "model_search.php", true);
	http.onreadystatechange = requestModelsResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	parameters="mode=AJAX&action=request_by_array";
	for(var x=0;x<theform.elements.length;x++){
		if(theform.elements[x].type=="checkbox" && theform.elements[x].checked){
			parameters+="&"+theform.elements[x].name+"="+encodeURI(theform.elements[x].value);
		}
	}
	http.send(parameters);
}
function requestModelsOpen(){
    var model_info='';
    var model_info_dis='';
    $(':checkbox:checked','#request_form').each(function(i,obj){
        model_info=$(obj).attr('model_info').toString().split('|');
        model_info_dis+=model_info[1]+"("+model_info[0]+")  ";
    });
    $('#requested_models_display').html(model_info_dis);
    $('#model_resuest_div').css('top',($(window).scrollTop()+100));

    $('#model_resuest_div').slideDown();
}
function requestModelsSubmit(){
    //model_info="'.$row['id'].'|'.$row['first_name'].'|'.$row['age'].'|'.$row['state'].'"
    var parameters="mode=AJAX&action=request_by_new";
    var model_check=0;
    var contact_name = $('#contact_name').val();
    var contact_number = $('#contact_number').val();
    var request_reason = $('#request_reason').val();
    if(contact_name=="" || contact_number=="" || request_reason==""){
        alert('Please fill out all fields!');
        return false;
    }
    $(':checkbox:checked','#request_form').each(function(i,obj){
        parameters+="&"+$(obj).attr('name')+"="+$(obj).val();
        model_check++;
    });
    parameters+="&data[contact_name]="+contact_name+"&data[contact_number]="+contact_number+"&data[request_reason]="+request_reason;
    if(model_check==0){
        alert('Please select a model!');
        return false;
    }
    $.ajax({
        type: "POST",
        url: "model_search.php",
        data: parameters,
        cache: false,
        success: function(msg){

            alert( "Resquest Successful!");
            $('#contact_name').val('');
            $('#contact_number').val('');
            $('#request_reason').val('');
            $('#model_resuest_div').slideUp();
        }
    });




}
function requestAllModels(){
	theform=document.getElementById('hidden_form');
	http.open("POST", "model_search.php", true);
	http.onreadystatechange = requestModelsResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	parameters="mode=AJAX&action=request_by_query";
	for(var x=0;x<theform.elements.length;x++){
		parameters+="&"+theform.elements[x].name+"="+encodeURI(theform.elements[x].value);
	}
	http.send(parameters);
}
function requestModelsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			alert('Your Model Requests Have Been Sent!');
		}else{
			alert('Something is wrong!');
		}
	}
}

//model requests
function listModelRequests(){
	http.open("GET", "model_requests.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&company="+document.getElementById('search_company').value+"&model_id="+document.getElementById('search_model_id').value, true);
	http.onreadystatechange = listModelRequestsResponse;
	http.send(null);
}
function listModelRequestsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('ModelRequest_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

//access logs
function listAccessLogs(){
	http.open("GET", "access_log.php?mode=AJAX&action=show&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&username="+document.getElementById('search_username').value+"&level="+document.getElementById('search_level').value, true);
	http.onreadystatechange = listAccessLogsResponse;
	http.send(null);
}
function listAccessLogsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('AccessLog_table').innerHTML=http.responseText;
		}else{
			alert('Something is wrong!');
		}
	}
}

//login logs
function listLoginLogs(){
	http.open("GET", "login_log.php?mode=AJAX&action=show&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&username="+document.getElementById('search_username').value+"&level="+document.getElementById('search_level').value, true);
	http.onreadystatechange = listLoginLogsResponse;
	http.send(null);
}
function listLoginLogsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('LoginLog_table').innerHTML=http.responseText;
		}else{
			alert('Something is wrong!');
		}
	}
}

//email logs
function resendEmail(id){
    http.open("GET", "email_log.php?mode=AJAX&id="+id+"&action=resend", true);
	http.onreadystatechange = resendEmailResponse;
	http.send(null);
}
function resendEmailResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			alert(http.responseText);
		}else{
			alert('Something is wrong!');
		}
	}
}
function listEmailLogs(){
    document.getElementById('EmailLog_table').innerHTML="<center><br><br><br><img src='images/ajax-loader.gif'><br><br><br></center";
    http.open("GET", "email_log.php?mode=AJAX&page="+thePage+"&action=show&reset_count="+resetCount+"&model_id="+document.getElementById('search_model_id').value+"&startdate="+document.getElementById('search_start_date').value+"&enddate="+document.getElementById('search_end_date').value+"&email="+document.getElementById('search_email').value+"&type="+document.getElementById('search_type').value, true);
	http.onreadystatechange = listEmailLogsResponse;
	http.send(null);
}
function listEmailLogsResponse(){
	if (http.readyState == 4){
		if(http.status==200){
			responseArray=http.responseText.split('|');
			if(resetCount=="YES"){
				document.getElementById('page_control').innerHTML=responseArray[0];
				resetCount='NO';
			}
			document.getElementById('EmailLog_table').innerHTML=responseArray[1];
		}else{
			alert('Something is wrong!');
		}
	}
}

//membership packages
function packageResponses(){
	if (http.readyState == 4){
		if(http.status==200){
			document.getElementById('package_table').innerHTML=http.responseText;
			if(alertmessage!="") alert(alertmessage);
		}else{
			alert('Something is wrong!');
		}
	}
}
function savePackage(passed_package){
	alertmessage="Package Saved";
	http.open("GET", "membership_packages.php?mode=AJAX&action=update&id="+passed_package+"&name="+document.getElementById('name_edit_'+passed_package).value+"&months="+document.getElementById('months_edit_'+passed_package).value+"&price="+document.getElementById('price_edit_'+passed_package).value, true);
	http.onreadystatechange = packageResponses;
	http.send(null);
}
function addPackage(){
	alertmessage="";
	http.open("GET", "membership_packages.php?mode=AJAX&action=insert&name="+document.getElementById('name').value+"&months="+document.getElementById('months').value+"&price="+document.getElementById('price').value, true);
	http.onreadystatechange = packageResponses;
	http.send(null);
}
function deletePackage(passed_package){
	alertmessage="";
	http.open("GET", "membership_packages.php?mode=AJAX&action=delete&id="+passed_package, true);
	http.onreadystatechange = packageResponses;
	http.send(null);
}


//generic stuff
function getHTTPObject(){
	var C=null;
	try{
		C=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{C=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(sc){C=null;}
	}
	if(!C &&typeof XMLHttpRequest!="undefined"){C=new XMLHttpRequest();}
	return C;
}


//picture stuff
var showPhotos='yes';
function changecss(theClass,element,value) {
	var cssRules;
	if(document.all) {cssRules = 'rules';}
	else if(document.getElementById) {cssRules = 'cssRules';}

	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {document.styleSheets[S][cssRules][R].style[element] = value;}
		}
	}
}
function nextImage(passed_id){
	var counter=document.getElementById('counter['+passed_id+']');
	var photos=document.getElementById('photos['+passed_id+']').value;

	var photoArray=photos.split(",");

	if(counter.value!=(photoArray.length-1)){
		counter.value++;
		document.getElementById('photo_preview_'+passed_id).src='viewimage.php?type=thumbdata&id='+photoArray[counter.value];
		document.getElementById('photo_preview_link_'+passed_id).href="javascript:photoPopup("+photoArray[counter.value]+");";
	}
}
function prevImage(passed_id){
	var counter=document.getElementById('counter['+passed_id+']');
	var photos=document.getElementById('photos['+passed_id+']').value;

	var photoArray=photos.split(",");

	if(counter.value>0){
		counter.value--;
		document.getElementById('photo_preview_'+passed_id).src='viewimage.php?type=thumbdata&id='+photoArray[counter.value];
		document.getElementById('photo_preview_link_'+passed_id).href="javascript:photoPopup("+photoArray[counter.value]+");";
	}
}
function showHidePhotos(){
	if(showPhotos=='no'){
		changecss(".hidden_image","display","none");
		changecss(".nonhidden_image","display","block");
		showPhotos='yes';
	}else{
		changecss(".hidden_image","display","block");
		changecss(".nonhidden_image","display","none");
		showPhotos='no';
	}
}
function photoPopup(photo_id){
    //if (photoPopup!='undefined' && !photoPopup.closed) photoPopup.close();
	my_window=window.open('viewimage.php?id='+photo_id+'&mode=page','model_photo','width=500,height=700,scrollbars=no,top=25,left=100',true);
    my_window.focus();
}
function showhideAdvSearch(obj){

    var table=$(obj).parent().parent();
    var div=$('TR:eq(1)',table).children('td').children('div');

    if($(div).css('display')=='none'){
        $(div).slideDown();
    }else{
        $(div).slideUp();
    }


}

function requestDetails(id){
    $.ajax({
        type: "POST",
        url: "model_requests.php",
        data: 'request_id='+id,
        cache: false,
        success: function(html){
            $('#model_resuest_div').html(html);
            $('#model_resuest_div').slideDown();
        }
    });
}


var parameters='';
var theform='';
var alertmessage='';
var resetCount='YES';
var thePage=1;
var http = getHTTPObject();
