﻿<!--// 

var URL = location.host;

// object class for basic ajax functions
var ajax = function() {
	
		var landing = null;
	
		function httpRequestObject() {
			var hro = null;
		 	if (window.XMLHttpRequest) {
		    	hro = new XMLHttpRequest();
		  	} else if (window.ActiveXObject) {
		    	hro = new ActiveXObject("Microsoft.XMLHTTP");
			}
			return hro;
		}
		
	  	var http = httpRequestObject();
	  	
	  	this.getFeed = function(feedURL, dest) {
	  	    landing = dest;
	  	    http.open("GET", feedURL, true);
			http.send("");
	  	}
		
		this.populateSelect = function(loc,land) {
			landing = land;
			landing.className = "inputLoad";
			landing.options[0] = new Option("Please wait ...","Please wait ...");
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send("");
		}
		
		// this doesn't work ...
		this.postImage = function(loc,img,land) {
			landing = land;
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "multipart/form-data");
			var sendIt = img.name + "=" + img.value;
			http.send(sendIt);
		}
		
		this.postDisplay = function(loc,land) {
		//	alert("loc: " + loc);
			landing = land;
			landing.innerHTML = "<div class=\"inputLoad\" style=\"width:200px;height:40px;\">Please wait ...</div>";
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send("");
		}
		
		this.postDisplayCustMsg = function(loc,land,custMsg) {
			landing = land;
			landing.innerHTML = custMsg;
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send("");
		}
		
		this.postDisplayNoMsg = function(loc,land) {
			landing = land;
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send("");
		}
		
		this.postFormExplicit = function(form,loc,land,fields) {
			var sendIt = "";
			landing = land;
			var fieldNames = fields.split(",");
			for (j = 0; j < fieldNames.length; j++) {
				var val = ajaxGetVal(document.getElementById(fieldNames[j]));
				sendIt += fieldNames[j] + "=" + val + "&";
			}		
			http.open("POST", loc, true);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send(sendIt);
		}
		
		this.postForm = function(form,loc,land) {
			var sendIt = "";
			landing = land;						
			for (j = 0; j < form.elements.length; j++) {				
				var el = form.elements[j];
				var vael = ajaxGetVal(el);
				if (vael != "") {
					sendIt += el.name + "=" + vael + "&";
				}
			}					
			http.open("POST", loc, false);		    				
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		
			http.send(sendIt);
		}
		
		http.onreadystatechange = function(land) {
		//	alert("land: " + land + "\nreadystate: " + http.readyState + "\nresponse headers:\n" + http.getAllResponseHeaders());
			if (http.readyState == 4) {
				//alert("status: " + http.status);
				if (http.status == 200) {
				//	alert("landing.type: " + landing.type + "\nresponseText: " + http.responseText);
					var divText = http.responseText;
					var divJS = "";
					if (divText.indexOf("<!--JAVASCRIPT:") > 0) {
						var divJSStart = divText.indexOf("<!--JAVASCRIPT:");
						var divJSEnd = divText.indexOf("/JAVASCRIPT-->")
						divJS = divText.substring(divJSStart,divJSEnd).replace("<!--JAVASCRIPT:","");
						divText = divText.substring(0,divJSStart);
					}
					divText = divText.replace(/<\/?(HTML|BODY)>/ig,""); 
					//alert(divText);
					if (landing.type == "select-one" || landing.type == "select"|| landing.type == "select-multiple") {
						var a = divText.split(";");
						buildSelect(landing,a);		
						landing.className = "input";				
					} else {
						landing.innerHTML = divText;
					}
					if (divJS != "") {
						eval(divJS);
					}										
				}
			}
		}				
	}
	
// from fvalid -- useful for postForm
	function ajaxGetVal(f) {
		var val = "";
		var fType = new String(f.type);//f.type.toString();
		if (fType == "select-one" || fType == "select-multiple") {
			for (x = 0 ; x < f.options.length; x++) {
				if (f.options[x].selected == true) {
					val = (f.type == "select-one") ? f.options[x].value : val + "|" + f.options[x].value;
				}
			}
		} else if (fType == "checkbox") {
			if (f.length) {
				if (f.length > 1) { 
					for (y = 0; y < f.length; y++) {
						if (f[y].checked) {
							if (val == "") {
								val += f[y].value;
							} else {
								val += "," + f[y].value;
							}
						}
					}
				} else {
					if (f.checked) {
						val = f.value;
					}
				}
			} else {
				if (f.checked) {
					val = f.value;
				}
			}
		} else if (fType == "undefined" || fType == "radio") {
			if (f.length > 1) { 
				for (y = 0; y < f.length; y++) {
					if (f[y].checked) {
						val = f[y].value;
					}
				}
			} else {
				f.checked = true;
				val = f.value;
			}
		} else {
			val = f.value;
		}
		return val;
	}	

/// specific ajax functions
var URL = location.host;

	function loadPortCategory(id) {
	    toggleMain("div");
	    var aj = new ajax();
	    var port = "";
	    if (id == 1) {
	        port = "paint.html";
	    } else if (id == 2) {
	        port = "draw.html";
	    } else if (id == 3) {
	        port = "des.html";
	    }
	    aj.getFeed(port,document.getElementById("main_content"));
	}
	
	function loadTech() {
	    toggleMain("div");
	    var aj = new ajax();
	    var port = "tech.html";
	    aj.getFeed(port,document.getElementById("main_content"));
	}
	
	function loadContact() {
	    toggleMain("div");
	    var aj = new ajax();
	    var port = "contact.html";
	    aj.getFeed(port,document.getElementById("main_content"));
	}

	function loadMisc() {
	    if (document.all) {
	        toggleMain("div");
	        var aj = new ajax();
	        var port = "misc.html";
	        aj.getFeed(port,document.all.main_content);
	    } else if (document.getElementById) {
	        toggleMain("frame");
	        document.getElementById("main_content_frame").src= "misc.html";
	    }
	}
	
	function loadSnaps() {
	    toggleMain("div");
	    var aj = new ajax();
	    var port = "snaps.html";
	    aj.getFeed(port,document.getElementById("main_content"));
	}
	
	function toggleMain(t) {
	    if (document.all) {
	        document.all.main_content.style.visibility = (t == "frame") ? "hidden" : "visible";
	        document.all.main_content_frame.style.visibility = (t == "frame") ? "visible" : "hidden";    
	    } else if (document.getElementById) {
	        document.getElementById("main_content_frame").style.display = (t=="frame") ? "block" : "none";
	        document.getElementById("main_content").style.visibility = (t=="frame") ? "none" : "block";     
	    }
        /*
	    document.getElementById("main_content_frame").style.display = (t=="frame") ? "block" : "none";
	    
	    document.getElementById("main_content").style.visibility = (t=="frame") ? "none" : "block"; 
            
	    if (t != "frame") {
	        document.getElementById("main_content_frame").src = "blank.html";
	    }
	    */  
	}
	
	function frameAdjust() {
	    if (document.all) {
	        parent.document.all.main_content_frame.height = document.body.scrollHeight + 30; 
	    } else if (document.getElementById) {
	        parent.document.getElementById("main_content_frame").height = document.body.scrollHeight + 30;
	    }
	}
	
	function pageAdjust() {
	    if (document.all) {
	        document.body.style.height = document.all.main_content.scrollHeight + 200;   
	    }

	}

	
	