function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {//rewrote to use id, not name
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
//			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function $c(msg) {
	console.log(msg);
}

function popWindow(url,Wwidth,Wheight) {
small_window = window.open(url,"small_window"+Wwidth+"x"+Wheight,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + Wwidth + ',height=' + Wheight + ',screenX=0,screenY=0');
small_window.focus();
}

function menuGo(base, whichMenu) {
	if (document.menuForm[whichMenu].value) {
		base = 'http://' + base + 'admin/';
		if (whichMenu != '') {
			top.location.href = base + document.menuForm[whichMenu].value;
		}
	}
}

function menuFilter(base, whichMenu) {
	if (document.menuForm[whichMenu].value) {
		base = 'http://' + base + 'admin/';
		if (whichMenu != '') {
			location.href = base + document.menuForm[whichMenu].value;
		}
	}
}

function emailCheck (emailStr) {
	var checkTLD=0; 
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; 
	var emailPat=/^(.+)@(.+)$/; 
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; 
	var validChars="\[^\\s" + specialChars + "\]"; 
	var quotedUser="(\"[^\"]*\")"; 
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; 
	var atom=validChars + '+'; 
	var word="(" + atom + "|" + quotedUser + ")"; 
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
	var matchArray=emailStr.match(emailPat); 
	if (matchArray==null) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	var user=matchArray[1]; 
	var domain=matchArray[2]; 
	for (i=0; i<user.length; i++) { 
	if (user.charCodeAt(i)>127) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	} 
	for (i=0; i<domain.length; i++) { 
	if (domain.charCodeAt(i)>127) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	} 
	if (user.match(userPat)==null) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	var IPArray=domain.match(ipDomainPat); 
	if (IPArray!=null) { 
	for (var i=1;i<=4;i++) { 
	if (IPArray>255) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	} 
	return true; 
	} 
	var atomPat=new RegExp("^" + atom + "$"); 
	var domArr=domain.split("."); 
	var len=domArr.length; 
	for (i=0;i<len;i++) { 
	if (domArr[i].search(atomPat)==-1) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	} 
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	} 
	if (len<2) { 
	alert("Sorry, that email address doesn't look right."); 
	return false; 
	}
	return true;
}

function makeHttpRequest(url, callback_function, return_xml) 
{ 
   var http_request = false; 

   if (window.XMLHttpRequest) { // Mozilla, Safari,... 
       http_request = new XMLHttpRequest(); 
       if (http_request.overrideMimeType) { 
           http_request.overrideMimeType('text/xml'); 
       } 
   } else if (window.ActiveXObject) { // IE 
       try { 
           http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
       } catch (e) { 
           try { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } catch (e) {} 
       } 
   } 

   if (!http_request) { 
       //alert('Unfortunately, your browser doesn\'t support this feature.'); 
       return false; 
   } 
   http_request.onreadystatechange = function() { 
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
               if (return_xml) { 
                   eval(callback_function + '(http_request.responseXML)'); 
               } else { 
                   eval(callback_function + '(http_request.responseText)'); 
               } 
           } else { 
               alert('There was a problem with the request. (URL: ' + url + ' Code: ' + http_request.status + ')'); 
           } 
       } 
   } 
   http_request.open('GET', url, true); 
   http_request.send(null);
   return true;
   
}

function deleteEmails() {
	if (confirm("Do you really want to empty the list of collected emails?")) {
		makeHttpRequest('/admin/deleteEmails.php', '', false);
	}
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


