var DL_bNS4=(document.layers);
var DL_bNS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
var DL_bDOM=(document.getElementById);
var DL_bIE=(document.all);
var DL_bIE4=(DL_bIE && !DL_bDOM);
var DL_bMac = (navigator.appVersion.indexOf("Mac") != -1);
var DL_bIEMac=(DL_bIE && DL_bMac);
var DL_bIE4Mac=(DL_bIE4 && DL_bMac);
var DL_bNS =(DL_bNS4 || DL_bNS6);
var one_commission_request = 0;

function windowWidth() {
	if (window.innerWidth != null){ return window.innerWidth; }
	if (document.body.clientWidth != null) { return document.body.clientWidth;  }
	return (0);
}

function createPopup(url, name) {
	var newwindow=window.open(url,name,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=670,height=600,left=20,top=20');
	if (newwindow.focus) {
		newwindow.focus();
	}
}

function barePopup(URL) {
day = new Date();
id = day.getTime();
var dyURL = 'http://'+window.location.host+'/'+URL;
eval("page" + id + " = window.open(dyURL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=670,height=600');");
}

function updateParent_1arg(data) {

	if(! opener) {
		alert('This window was opened directly, nothing is going to happen.');
		return false;
	}
	if(! opener.updateParent_callback ) {
		alert('The window that opened this window is not setup to handle things.');
		return false;
	}
	opener.updateParent_callback(data);
	self.close();

	return false;
}

function updateParent(num,title,mode) {
    if(mode == null) {
    	mode = '&';
    } else {
    	if(mode == 2) {
    		mode = '?';
    	} else {
    		mode = '&';
    	}
    }
	//opener.document.getElementById('replink').style.display = 'none';
	opener.document.getElementById('old_photo_id').value = num.toString();
	//opener.document.getElementById('txt_old_title').innerHTML = title.toString();
	//opener.document.getElementById('txt_old_sid').innerHTML = 'ID:' + num.toString();
	//titlediv.innerHTML = title.toString();
	//iddiv.innerHTML = 'ID: ' + num.toString();
	var photoidstr = num.toString();
	//var imgSRC = '/thumbs/' + photoidstr.charAt(2) + '/' + photoidstr.charAt(1) + '/' + photoidstr.charAt(0) + '/small/' + photoidstr + '.jpg';
	//opener.document.getElementById('old_img_holder').innerHTML = "<img id='old_img' border='1' style='' alt='...' src='"+imgSRC+"'>";
	var reloadurl = opener.window.location.href;
	opener.window.location = reloadurl + mode + "oldimg="+photoidstr;
	/*if(typeof(opener.addReplaceImage) == 'function') {
		opener.addReplaceImage(num);
	} else {
		alert("could not find add replace function");
	}*/
	//var imgobj = opener.document.getElementById('ufrepimg');
	//var keywords = opener.document.getElementById('ufkeywords1');
	//var desc = opener.document.getElementById('ufdescription1');
	//keywords.disabled = true;
	//desc.disabled = true;
	//opener.document.getElementById('replace').style.display = 'block';
	opener.bypass = 1;
	self.close();
	return false;
}


function validateSearchQuery(searchobjname) {
	var searchq = document.getElementById(searchobjname);
	if (!searchq) return true;
	var searchtext = searchq.value;
	var searchtext2 = searchtext.replace(/(\w)\+/g,'$1 +');
	searchtext2 = searchtext2.replace(/\+\s+(\w)/g,'+$1');
	searchtext2 = searchtext2.replace(/(\w)\-/g,'$1 -');
	searchtext2 = searchtext2.replace(/\-\s+(\w)/g,'-$1'); // '
	searchq.value = searchtext2;
}

function windowHeight() {
	if (window.innerHeight != null){ return window.innerHeight; }
	if (document.body.clientHeight != null) { return document.body.clientHeight;  }
	return (0);
}

function objGetScreenLeft(oElement)
{
	var  lA = window.screenY? window.screenY: window.screenTop;
	return objGetRealLeft(oElement) + lA;
}

function findPosition( oLink ) {
	if( oLink.offsetParent ) {
		for( var posX = 0, posY = 0; oLink.offsetParent; oLink =
				oLink.offsetParent ) {
			posX += oLink.offsetLeft;
			posY += oLink.offsetTop;
		}
		this.x = posX;
		this.y = posY;
		return this;
	} else {
		this.x = oLink.x;
		this.y = oLink.y;
		return this;
	}
}
function objGetRealLeft(oElement)
{
	var nXPos = oElement.offsetLeft;
	var oParentEl = (DL_bIE4Mac) ? oElement.parentElement : oElement.offsetParent;

	while (oParentEl != null)
	{
		if(DL_bIE4Mac)
		{
			if(oParentEl.tagName=="SPAN")
			{
				oParentEl = oParentEl.parentElement;
			}
			if(oParentEl.tagName=="HTML")
			{
				break;
			}
		}

		nXPos += oParentEl.offsetLeft;
		oParentEl = (DL_bIE4Mac) ? oParentEl.parentElement : oParentEl.offsetParent;
	}
	return nXPos;

}


function objGetScreenTop(oElement)
{
	var  tA = window.screenY? window.screenY: window.screenTop;
	return objGetRealTop(oElement) + tA;
}
function objGetRealTop(oElement)
{
	var nYPos = oElement.offsetTop;
	var oParentEl = (DL_bIE4Mac) ? oElement.parentElement : oElement.offsetParent;
	while (oParentEl != null)
	{
		if(DL_bIE4Mac)
		{
			if(oParentEl.tagName=="SPAN")
			{
				oParentEl = oParentEl.parentElement;
			}
			if(oParentEl.tagName=="HTML")
			{
				break;
			}
		}
		nYPos += oParentEl.offsetTop;
		oParentEl = (DL_bIE4Mac) ? oParentEl.parentElement : oParentEl.offsetParent;
	}
	return nYPos;
}

function confirmSubmit()
{
var agree=confirm("Are you sure?");
if (agree)
	return true ;
else
	return false ;
}


function confirmEmail(email,which)
{
if (email.toString()=="BLANK") { alert("You need to specify a " + which + " email address before proceeding, thanks."); return false; }
if (one_commission_request > 0) { alert("Please only submit once"); return false; }
var str = "The email address you supplied is: " + email + "  IF your payment information is INCORRECT you will NOT receive your commission!! Please review it closely before proceeding. If you are SURE this is correct please proceed, otherwise cancel and EDIT your payment information, thanks.";
var agree=confirm(str);
if (agree)
	one_commission_request++;
else
	return false;
if (one_commission_request != 1)  return false;
return true;
}

function confirmAddress(addrs)
{
if (addrs.toString()=="BLANK") { alert("You need to specify an address before proceeding, thanks."); return false; }
if (one_commission_request > 0) { alert("Please only submit once"); return false; }
var str2 = "The address you supplied is: " + addrs + "  IF your payment information is INCORRECT you will NOT receive your commission!! Please review it closely before proceeding. If you are SURE this is correct please proceed, otherwise click to EDIT your payment information, thanks.";
var agree2=confirm(str2);
if (agree2)
	one_commission_request++;
else
	return false;
if (one_commission_request != 1)  return false;
return true;
}

function $(id) { return document.getElementById(id); }

function setAttribute(el,attr_name,value) {
    var i,attr;
    if(!el) return false;
    if(el.getAttributeNode(attr_name)) {
        for(i=0; i < el.attributes.length; i++) {
            attr = el.attributes[i];
            if(attr.name == attr_name) {
                attr.value = value;
                if(attr.value != value)
                    el.setAttribute(attr_name,value);
                return;
            }
        }
    } else {
        el.setAttribute(attr_name,value);
        return;
    }
}

function getAttribute(el,attr_name) {
    var i;
    if(!el.attributes) return false;
    for(i=0; i < el.attributes.length; i++) {
        if(el.attributes[i].nodeName.toLowerCase() == attr_name.toLowerCase()) {
            return el.attributes[i].nodeValue;
        }
    }
    return false;
}

String.prototype.trim = function(pattern) {
	return this.lTrim(pattern).rTrim(pattern);
}
String.prototype.lTrim = function(pattern) {
	if(pattern == null) {
		pattern = /\s/;
	}
	else if(typeof(pattern).toString().toLowerCase() == 'string') {
		pattern = new RegExp(pattern);
	}
	var i = 0;
	while(i < this.length-1 && pattern.test(this.charAt(i))) i++;
	return this.substring(i,this.length);
}
String.prototype.rTrim = function(pattern) {
	if(pattern == null) {
		pattern = /\s/;
	} else if(typeof(pattern).toString().toLowerCase() == 'string') {
		pattern = new RegExp(pattern);
	}
	var i=this.length-1;
	while(i >= 0 && pattern.test(this.charAt(i))) i--;
	return this.substring(0,i+1);
}
// thanks IE6
Array.prototype.indexOf = function() {
	for(var i=0; i < this.length; i++) {
		if(this[i] == arguments[0]) return i;
	}
	return -1;
}

function loadCss(url) {
	var hd = document.getElementsByTagName('head')[0];
	var css = document.createElement('link');
	setAttribute(css, 'rel', 'stylesheet');
	setAttribute(css, 'type', 'text/css');
	setAttribute(css, 'href', url);
	hd.appendChild(css);
}

var loadScript = (function() {
	
	function exists(parts) {
		var node = window;
		for(var i=0; i < parts.length; i++) {
			if(!node[parts[i]]) {
				return false;
			}
			node = node[parts[i]];
		}
		return true;
	}
	
	return (function(url, objSig, cb) {
	
		var parts = objSig.split('.');
		
		if(exists(parts)) {
			if(cb) cb();
			return;
		}
	
		var hd = document.getElementsByTagName('head')[0];
		var sc = document.createElement('script');
		var intr;
		
		sc.type = "text/javascript";
		sc.src = url;
		hd.appendChild(sc);
		
		intr = window.setInterval(function() {
			if(!exists(parts)) return;
			window.clearInterval(intr);
			if(cb) cb();
		}, 10);
	});
})();

var loadScripts = (function() {
							
	function doLoad(index, urls, objSigs, cb) {
		loadScript(urls[index], objSigs[index], function() {
			if(index==urls.length-1) {
				if(cb) cb();
				return;
			}
			doLoad(index+1, urls, objSigs, cb);
		});
	}
							
	return (function(urls, objSigs, cb) {
		doLoad(0, urls, objSigs, cb);
	});
})();

