﻿var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTSvar xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXESxi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLEfunction xhrRequest(type) {	if (!type) {		type = 'html';	}	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP	var xhrsend = xi.length;	// GO THROUGH AVAILABLE xi VALUES	for (var i=0; i<xi.length; i++) {		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK		if (xi[i] == 1) {			xi[i] = 0;			xhrsend = i;			break;		}	}	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE	xi[xhrsend] = 0;	// SET UP THE REQUEST	if (window.ActiveXObject) {		try {			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			try {				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");			} catch (e) {}		}	} else if (window.XMLHttpRequest) {		xhr[xhrsend] = new XMLHttpRequest();		if (xhr[xhrsend].overrideMimeType) {			xhr[xhrsend].overrideMimeType('text/' + type);		}	}	return (xhrsend);}/*function sampleAjax() {	var xhri = xhrRequest('html');	var qry = '';	var url = '';	xhr[xhri].open('POST', url, true);	xhr[xhri].onreadystatechange = function () {			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {				xi[xhri] = 1;				xhr[xhri] = null;			} else {				try {					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;					//alert(alertStr);				}				catch (e) {					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";					//alert(alertStr);				}			}		};	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	xhr[xhri].send(qry);}*///// SCROLLING//function stop_scroll() {	clearInterval(scroller);}function toggle_arrow(side) {	if (!side) side = window.event; // fix for IE	if (side == 'left') {		if (document.getElementById('arrowleft').src.substr(document.getElementById('arrowleft').src.lastIndexOf('/')) == '/arrowleft.gif') {			document.getElementById('arrowleft').src = 'images/arrowleftw.gif';		} else {			document.getElementById('arrowleft').src = 'images/arrowleft.gif';		}	} else {		if (document.getElementById('arrowright').src.substr(document.getElementById('arrowright').src.lastIndexOf('/')) == '/arrowright.gif') {			document.getElementById('arrowright').src = 'images/arrowrightw.gif';		} else {			document.getElementById('arrowright').src = 'images/arrowright.gif';		}	}}//// SCROLLING PHOTOGRAPHS//function scroll_left() {	scroller = setInterval(function() {		var temp_var = js_ids.shift();		js_ids.push(temp_var);		temp_var = js_filenames.shift();		js_filenames.push(temp_var);		temp_var = js_titles.shift();		js_titles.push(temp_var);		var out_string = '<table cellpadding="8px"><tr>';		for (var i=0; i<=(js_ids.length - 1); i++) {			out_string += '<td><a onclick="display(\'' + js_ids[i] + '\')"><img class="sample" src="portfolio/thumbs/' + js_filenames[i] + '" alt="' + js_titles[i] + '" title="' + js_titles[i] + '" height="40px" /></a></td>';		}		out_string += '</tr></table>';		document.getElementById('samples').innerHTML = out_string;	}, 500);}function scroll_right() {	scroller = setInterval(function() {		temp_var = js_ids.pop();		js_ids.unshift(temp_var);		temp_var = js_filenames.pop();		js_filenames.unshift(temp_var);		temp_var = js_titles.pop();		js_titles.unshift(temp_var);		var out_string = '<table cellpadding="8px"><tr>';		for (var i=0; i<=(js_ids.length - 1); i++) {			out_string += '<td><a href="#" onclick="display(\'' + js_ids[i] + '\')"><img class="sample" src="portfolio/thumbs/' + js_filenames[i] + '" alt="' + js_titles[i] + '" title="' + js_titles[i] + '" height="40px" /></a></td>';		}		out_string += '</tr></table>';		document.getElementById("samples").innerHTML = out_string;	}, 500);}//// SCROLLING VIDEOS//function scroll_left_v() {	scroller = setInterval(function() {		var temp_var = js_ids.shift();		js_ids.push(temp_var);		temp_var = js_thumbnames.shift();		js_thumbnames.push(temp_var);		temp_var = js_filenames.shift();		js_filenames.push(temp_var);		temp_var = js_titles.shift();		js_titles.push(temp_var);		var out_string = '<table cellpadding="8px"><tr>';		for (var i=0; i<=(js_ids.length - 1); i++) {			out_string += '<td><a onclick="display_video(\'' + js_ids[i] + '\')"><img class="sample" src="portfolio/video_thumbs/' + js_thumbnames[i] + '" alt="' + js_titles[i] + '" title="' + js_titles[i] + '" height="40px" /></a></td>';		}		out_string += '</tr></table>';		document.getElementById('samples').innerHTML = out_string;	}, 500);}function scroll_right_v() {	scroller = setInterval(function() {		temp_var = js_ids.pop();		js_ids.unshift(temp_var);		temp_var = js_filenames.pop();		js_filenames.unshift(temp_var);		temp_var = js_titles.pop();		js_titles.unshift(temp_var);		var out_string = '<table cellpadding="8px"><tr>';		for (var i=0; i<=(js_ids.length - 1); i++) {			out_string += '<td><a onclick="display_video(\'' + js_ids[i] + '\')"><img class="sample" src="portfolio/video_thumbs/' + js_filenames[i] + '" alt="' + js_titles[i] + '" title="' + js_titles[i] + '" height="40px" /></a></td>';		}		out_string += '</tr></table>';		document.getElementById("samples").innerHTML = out_string;	}, 500);}//// DISPLAY PHOTOGRAPH//function display(id) {	if (!id) id = window.event; // fix for IE	var xhri = xhrRequest('html');	var qry = 'js=y&id=' + id;	var url = 'php/display_item.php';	xhr[xhri].open('POST', url, true);	xhr[xhri].onreadystatechange = function () {			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {				document.getElementById('viewport').innerHTML = xhr[xhri].responseText;				xi[xhri] = 1;				xhr[xhri] = null;			} else {				try {					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;					//alert(alertStr);				}				catch (e) {					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";					//alert(alertStr);				}			}		};	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	xhr[xhri].send(qry);}//// DISPLAY video//function display_video(id) {	if (!id) id = window.event; // fix for IE	var xhri = xhrRequest('html');	var qry = 'js=y&id=' + id;	var url = '/php/display_video.php';	xhr[xhri].open('POST', url, true);	xhr[xhri].onreadystatechange = function () {			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {				document.getElementById('viewport').innerHTML = xhr[xhri].responseText;				xi[xhri] = 1;				xhr[xhri] = null;			} else {				try {					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;					//alert(alertStr);				}				catch (e) {					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";					//alert(alertStr);				}			}		};	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	xhr[xhri].send(qry);}function insert_movie() {	var thisElement = document.getElementById('this_video');	var vname = thisElement.name;	var vwidth = thisElement.width;	var vheight = thisElement.height;	document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' + vwidth + '" height="' + vheight + '">');	document.write('<param name="src" value="portfolio/video/' + vname + '" />');	document.write('<param name="controller" value="true" />');	document.write('<param name="target" value="myself" />');	document.write('<param name="autoplay" value="false" />');	document.write('<!--[if !IE]>-->');	document.write('<object type="video/quicktime" data="/portfolio/video/' + vname + '" width="' + vwidth + '" height="' + vheight + '">');	document.write('<param name="autoplay" value="false" />');	document.write('<param name="target" value="myself" />');	document.write('<param name="controller" value="true" />');	document.write('</object>');	document.write('<!--<![endif]-->');	document.write('</object>');}//// MESSAGE VALIDATION//function validate_contact(form) {	if (!form) form = window.event; // fix for IE	var n_valid = false;	var e_valid = false;	var m_valid = false;	n_valid = validate_name(form.name);	e_valid = validate_email(form.email);	m_valid = validate_message(form.message);	if ((n_valid == false) || (e_valid == false) || (m_valid == false)) {		return false;	} else {		return true;	}}function validate_name(nameElement) {	if (!nameElement) nameElement = window.event; // fix for IE	if (nameElement.value == '') {		document.getElementById("name_error").style.visibility = "visible";		document.getElementById("name_error").style.display = "block";		nameElement.focus();		nameElement.select();		return false;	} else {		document.getElementById("name_error").style.visibility = "hidden";		document.getElementById("name_error").style.display = "none";		return true;	}}function validate_email(emailElement) {	if (!emailElement) emailElement = window.event; // fix for IE	if (emailElement.value == '') {		document.getElementById("email_error").style.visibility = "visible";		document.getElementById("email_error").style.display = "block";		document.getElementById("email_error").innerHTML = "Please enter your email address"		emailElement.focus();		emailElement.select();		return false;	} else {		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;		if(reg.test(emailElement.value) == false) {			document.getElementById("email_error").style.visibility = "visible";			document.getElementById("email_error").style.display = "block";			document.getElementById("email_error").innerHTML = "The email address you entered does not appear to be valid!"			emailElement.focus();			emailElement.select();			return false;		} else {			document.getElementById("email_error").style.visibility = "hidden";			document.getElementById("email_error").style.display = "none";			document.getElementById("email_error").innerHTML = ""			return true;		}	}}function validate_message(messageElement) {	if (!messageElement) messageElement = window.event; // fix for IE	if (messageElement.value == '') {		document.getElementById("message_error").style.visibility = "visible";		document.getElementById("message_error").style.display = "block";		messageElement.focus();		messageElement.select();		return false;	} else {		document.getElementById("message_error").style.visibility = "hidden";		document.getElementById("message_error").style.display = "none";		return true;	}}//// Backoffice//function changeCategory(thisId) {	var thisSelect = document.getElementById('category_'+thisId);	var newCat = thisSelect.options[thisSelect.selectedIndex].value;	if (newCat == '_new') {		newCat = prompt('Enter new category name:','');	}	if (newCat == null || newCat == '') {		for (var i=0; i<thisSelect.options.length; i++) {			if (thisSelect.options[i].value == document.getElementById('prevCat_'+thisId).value) {				var prevIndex = i;			}		}		thisSelect.selectedIndex = prevIndex;		thisSelect.options[prevIndex].selected = true;	} else {		//alert("changing " + thisId + " to " + newCat);		document.getElementById('catmsg_'+thisId).innerHTML = "saving...";		var xhri = xhrRequest('html');		var qry = 'js=y&id=' + thisId + '&category=' + newCat;		var url = '/php/bo_change_category.php';		xhr[xhri].open('POST', url, true);		xhr[xhri].onreadystatechange = function () {				if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {						var response = xhr[xhri].responseText;						//alert(response);						if (response.search("success") >= 0) {							document.getElementById('catmsg_'+thisId).innerHTML = "saved";							var allSelects = document.getElementsByTagName('select');							for (var i=0; i<allSelects.length; i++) {								thisSelect = allSelects[i];								if (thisSelect.id.indexOf('category_') === 0) {									newCatExists = false;									for (var j=0; j<thisSelect.options.length; j++) {										if (thisSelect.options[j].value == newCat) newCatExists = true;									}									if (newCatExists == false) {										var newOption = document.createElement('option');										newOption.value = newCat;										newOption.text = newCat;										var newCatBefore = thisSelect.options[thisSelect.options.length - 1];										thisSelect.add(newOption,newCatBefore);									}									if (thisSelect.id == 'category_'+thisId) {										for (var j=0; j<thisSelect.options.length; j++) {											if (thisSelect.options[j].value == newCat) {												thisSelect.selectedIndex = j;												thisSelect.options[j].selected = true;											}										}									}								}							}						} else if (response.search("error") >= 0) {							//alert('That category ('+newCat+') already exists!');							for (var i=0; i<thisSelect.options.length; i++) {								if (thisSelect.options[i].value == document.getElementById('prevCat_'+thisId).value) {									var prevIndex = i;								}							}							thisSelect.selectedIndex = prevIndex;							thisSelect.options[prevIndex].selected = true;						} else if (response.search("novars") >= 0) {							alert('You entered an invalid category ('+newCat+')');							for (var i=0; i<thisSelect.options.length; i++) {								if (thisSelect.options[i].value == document.getElementById('prevCat_'+thisId).value) {									var prevIndex = i;								}							}							thisSelect.selectedIndex = prevIndex;							thisSelect.options[prevIndex].selected = true;						} else {							alert('unable to process response ('+response+')');							for (var i=0; i<thisSelect.options.length; i++) {								if (thisSelect.options[i].value == document.getElementById('prevCat_'+thisId).value) {									var prevIndex = i;								}							}							thisSelect.selectedIndex = prevIndex;							thisSelect.options[prevIndex].selected = true;						}					xi[xhri] = 1;					xhr[xhri] = null;					document.getElementById('catmsg_'+thisId).innerHTML = "";				} else {					try {						var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;						//alert(alertStr);					}					catch (e) {						var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";						//alert(alertStr);					}				}			};		xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		xhr[xhri].send(qry);	}}function changeCategoryNoSave(thisId) {	var thisSelect = document.getElementById('category['+thisId+']');	var newCat = thisSelect.options[thisSelect.selectedIndex].value;	if (newCat == '_new') {		newCat = prompt('Enter new category name:','');	}	if (newCat == null || newCat == '') {		for (var i=0; i<thisSelect.options.length; i++) {			if (thisSelect.options[i].value == document.getElementById('prevCat['+thisId+']').value) {				var prevIndex = i;			}		}		thisSelect.selectedIndex = prevIndex;		thisSelect.options[prevIndex].selected = true;	} else {		var allSelects = document.getElementsByTagName('select');		for (var i=0; i<allSelects.length; i++) {			thisSelect = allSelects[i];			if (thisSelect.id.indexOf('category[') === 0) {				newCatExists = false;				for (var j=0; j<thisSelect.options.length; j++) {					if (thisSelect.options[j].value == newCat) newCatExists = true;				}				if (newCatExists == false) {					var newOption = document.createElement('option');					newOption.value = newCat;					newOption.text = newCat;					var newCatBefore = thisSelect.options[thisSelect.options.length - 1];					thisSelect.add(newOption,newCatBefore);				}				if (thisSelect.id == 'category['+thisId+']') {					for (var j=0; j<thisSelect.options.length; j++) {						if (thisSelect.options[j].value == newCat) {							thisSelect.selectedIndex = j;							thisSelect.options[j].selected = true;						}					}				}			}		}	}}function imageDelete(id) {	var r = confirm("Are you sure you want to delete this image? Deletions cannot be undone.");	if (r == true) {		var xhri = xhrRequest('html');		var qry = 'js=y&id=' + id;		var url = '/php/bo_delete_image.php';		xhr[xhri].open('POST', url, true);		xhr[xhri].onreadystatechange = function () {				if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {					if (xhr[xhri].responseText.search("success") >= 0) {						location.reload();					} else {						alert("Sorry, an error occurred while deleting the image.");						//alert(xhr[xhri].responseText);					}					xi[xhri] = 1;					xhr[xhri] = null;				} else {					try {						var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;						//alert(alertStr);					}					catch (e) {						var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";						//alert(alertStr);					}				}			};		xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		xhr[xhri].send(qry);	}}
