var ahblxmlhttp = createRequest();
function createRequest() {
	var obj;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        obj = new XMLHttpRequest();
    }
    return obj;
}

/***********************************************************
* portfolio remove functions
***********************************************************/
function portfolioRemove(id) {
	check = confirm('Are you sure you want to remove this portfolio image from the system?');
	if( check ) {
		ahblxmlhttp.open('get','ajax_portfolio_delete.php?id='+id);
		ahblxmlhttp.onreadystatechange = portfolioRemoveResponse;
		ahblxmlhttp.send(null);
	}
}
function portfolioRemoveResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
	       	document.getElementById('portfolio_items').innerHTML = response;
       	}
    }
}

/***********************************************************
* portfolio select functions
***********************************************************/
function portfolioSelect(element) {
	var id = document.getElementById('portfolio-select').value;
	ahblxmlhttp.open('get','ajax_portfolio.php?element='+element+'&id='+id);
	ahblxmlhttp.onreadystatechange = portfolioSelectResponse;
   	ahblxmlhttp.send(null);
}
function portfolioSelectResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
	       	document.getElementById('portfolio-images').innerHTML = response;
       	}
    }
}

/***********************************************************
* section portfolio change image functions
***********************************************************/
function changeSectionPortfolioImage(num,id) {
	ahblxmlhttp.open('get','ajax.php?action=changeSectionImage&num='+num+'&id='+id);
	ahblxmlhttp.onreadystatechange = changeSectionPortfolioImageResponse;
   	ahblxmlhttp.send(null);
}
function changeSectionPortfolioImageResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
			var portfolio = response.split("|");
			document.getElementById('section-portfolio-enlarged-image').src=portfolio[0];
			document.getElementById('section-portfolio-details').innerHTML = portfolio[1];
			document.getElementById('section-portfolio-enlarged-link').href=portfolio[3];
			var thumb;
			for( var i=1; i<6; i++ ) {
				if( portfolio[2] == i ) {
					thumb = document.getElementById('section-portfolio-image-'+i).src;
					thumb = thumb.replace('_bw','_t');
					document.getElementById('section-portfolio-image-'+i).src = thumb;
				}
				else {
					thumb = document.getElementById('section-portfolio-image-'+i).src;
					thumb = thumb.replace('_t','_bw');
					document.getElementById('section-portfolio-image-'+i).src = thumb;
				}
			}
       	}
    }
}

/***********************************************************
* portfolio change image functions
***********************************************************/
function changePortfolioImage(num,id) {
	ahblxmlhttp.open('get','ajax.php?action=changePortfolioImage&num='+num+'&id='+id);
	ahblxmlhttp.onreadystatechange = changePortfolioImageResponse;
   	ahblxmlhttp.send(null);
}
function changePortfolioImageResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
			var portfolio = response.split("|");
			document.getElementById('portfolio-enlarged-image').src=portfolio[0];
			if( portfolio[1] ) {
				document.getElementById('portfolio-description-holder').innerHTML = '<div id="portfolio-description">'+portfolio[1]+'</div>';
			}
			else {
				document.getElementById('portfolio-description-holder').innerHTML = '';
			}
			var max = portfolio[3];
			var thumb;
			for( var i=1; i<=max; i++ ) {
				if( portfolio[2] == i ) {
					thumb = document.getElementById('portfolio-image-'+i).src;
					thumb = thumb.replace('_bw','_t');
					document.getElementById('portfolio-image-'+i).src = thumb;
				}
				else {
					thumb = document.getElementById('portfolio-image-'+i).src;
					thumb = thumb.replace('_t','_bw');
					document.getElementById('portfolio-image-'+i).src = thumb;
				}
			}
       	}
    }
}

/***********************************************************
* portfolio show list function
***********************************************************/
function disciplineList(id) {
	ahblxmlhttp.open('get','ajax.php?action=disciplineList&id='+id);
	ahblxmlhttp.onreadystatechange = disciplineListResponse;
   	ahblxmlhttp.send(null);
}
function disciplineListResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
			var portfolio = response.split("|");
       		var newList = portfolio[1] + portfolio[2];
       		document.getElementById('list-discipline-'+portfolio[0]).innerHTML = newList;
       	}
    }
}
function categoryList(id) {
	ahblxmlhttp.open('get','ajax.php?action=categoryList&id='+id);
	ahblxmlhttp.onreadystatechange = categoryListResponse;
   	ahblxmlhttp.send(null);
}
function categoryListResponse() {
	if(ahblxmlhttp.readyState == 4){
		// this is the content of the called page
        var response = ahblxmlhttp.responseText;

       	//process the response
       	if( response ) {
			var portfolio = response.split("|");
       		var newList = portfolio[1] + portfolio[2];
       		document.getElementById('list-category-'+portfolio[0]).innerHTML = newList;
       	}
    }
}