
/* document.getElementsBySelector(selector)
     
     elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"
*/
function browserinfo(){
	var browser = new Object;
	browser.name=navigator.appName;
	browser.agent=navigator.userAgent;
	browser.version=parseFloat(navigator.appVersion);
	browser.fullversion=navigator.appVersion;
	browser.screenw=screen.width;
	browser.screenh=screen.height;
	browser.clientw=document.body.clientWidth;
	browser.clienth=document.body.clientHeight;
	if(browser.name=="Microsoft Internet Explorer") browser.name = "IE";
	return browser;
}

function Wait() {
	var classname = 'wait';
	 if (!document.body.className.match(new RegExp('\\b' + classname + '\\b'))) {
      document.body.className += ' ' + classname;
	 }
}

function stopWait() {
	var classname = 'wait';
	var ec = ' ' + document.body.className.replace(/^s*|s*$/g,'') + ' ';
	var nc = ec;
	classname = classname.replace(/^s*|s*$/g,'');
	if (ec.indexOf(' '+classname+' ') != -1) {
		nc = ec.replace(' ' + classname.replace(/^s*|s*$/g,'') + ' ',' ');
	}
	document.body.className = nc.replace(/^s*|s*$/g,'');
}

function inObject(a) { 
	var o = {};
  	for(var i=0;i<a.length;i++)
  	{ o[a[i]]=''; }
 	return o;
}

function replaceString(StringName,replaceTo,replaceWith)
{ var newString = StringName;
  for(var i=0; i<replaceTo.length;i++ )
  { newString = newString.replace(replaceTo[i],replaceWith[i]); }
	return newString;
}

function toggle(obj) {
	var R = false;
	if ( obj.style.display != 'none' ) {
		obj.style.display = 'none';
	}
	else { obj.style.display = ''; R = true; }
	return R;
}

function getParentTag(el, pTagName) {
	if (el == null) { return null; }
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
		{ return el; }
	else { return getParentTag(el.parentNode, pTagName); }
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

function dump(obj, name, indent, depth) {
	var MAX_DUMP_DEPTH = 10;
	var objdet = 0;
	if(depth==undefined) depth = 0;
	if (depth > MAX_DUMP_DEPTH) {
		  output +=  indent + name + ": <Maximum Depth Reached>\n";
	}
	if (typeof obj == "object") {
			objdet = 1;
		   var child = null;
		   output = indent + name + "\n";
		   indent += "\t";
		   for (var item in obj)
		   {
				 try {
						child = obj[item];
				 } catch (e) {
						child = "<Unable to Evaluate>";
				 }
				 if (typeof child == "object") {
						output += dump(child, item, indent, depth + 1);
				 } else {
						output += indent + item + ": " + child + "\n";
				 }
		   }

	} else if(objdet==0) {
		
		if (typeof obj == "array") {
			output += "Array:\n";
				for(var x in obj) { 
				output += x + " => " + obj[x] + "\n"; 
				}
		} else if (typeof obj == "boolean") {
				if(obj==true) { output += "Bool: TRUE\n"; } else { output += "Bool: FALSE\n" ; }
		} else if (typeof obj == "string") {
				output += "String: "+obj+"\n";
		} else if (typeof obj == "number") {
				output += "Number: "+obj+"\n";
		} else { output += obj; }
	
	} else {
		output = obj;
	}
}
	   
function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getElementsBySelector(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

// NO SPAM

function makecryptLinks()
  {
    var elements = getElementsBySelector('a.no_spam');
	for (i in elements) {
		elm=elements[i].id;
		m=document.getElementById(elm).href;
		hr=m.replace(/http:\/\/www.dondepescar\.com\/?/,'');
		document.getElementById(elm).href= decode(hr);
		elements[i].innerHTML = decode(elements[i].innerHTML);
	} 
  }

function decode(s) { 
	var l=s.length, n='', d='';
    for (var i=0; i<l;++i) {
      if (s.charAt(i)=='') { continue; }
      if (s.charAt(i)=='%') {
        n = s.charAt(++i)+''+s.charAt(++i);
        d += String.fromCharCode(parseInt(n, 16));
        continue;
      } else if (s.charAt(i)=='&') {
        i+=2; n='';
        while (s.charAt(i)!=';' && i<l) {
          n +=''+s.charAt(i); i++;
        }
        d +=String.fromCharCode(parseInt(n));
        continue;
      } else {
        d +=s.charAt(i);
      }
    }
    return d;
  }
  
function GetVoidUrl() {
		return "javascript: void( function(){" +
			"document.open();" +
			"document.write('<html><head><title></title></head><body></body></html>');" +
			"document.domain = 'www.dondepescar.com';" +
			"document.close();" +
			"}() ) ;";

	if ( FCKBrowserInfo.IsIE )
	{
		if ( FCKBrowserInfo.IsIE7 || !FCKBrowserInfo.IsIE6 )
			return "" ;					// IE7+ / IE5.5
		else
			return "javascript: '';" ;	// IE6+
	}

	return "javascript: void(0);" ;		// All other browsers.
}

function createImageURL(Obj) {
	var size = ''; var nc = ''; var dir = '';
	if (Obj.width && Obj.height) { if (Obj.width>0 && Obj.height>0) size = Obj.width+'x'+Obj.height; }
	else if(!Obj.height && Obj.width) { if (Obj.width>0) size = 'w'+Obj.width; }
	else if(!Obj.width && Obj.height) { if(Obj.height>0) size = 'h'+Obj.height; }
	if (Obj.nocache == true) nc = 'NC';
	var id = Obj.id.replace(/[^0-9]/,'');
	var name = Obj.name.replace(/\s/,'-').replace(/[^a-zA-Z0-9()_\-\%]/,'');
	if (Obj.dir) dir +='dir';
	var url = 'http://www.dondepescar.com/'+dir+'img/'+nc+id+'-'+size+'/'+name+'.jpg';
	return url;
}

function createImage(Obj) {
	
	if(Obj.size&&Obj.width&&Obj.height) {
		var w1 = Obj.width;
		var h1 = Obj.height;
		var w2, h2;
		if(w1>Obj.size) { w2 = Obj.size; h2 = parseInt(h1*w2/w1); w1 = w2; h1 = h2; }
		if(h1>Obj.size) { h2 = Obj.size; w2 = parseInt(w1*h2/h1); w1 = w2; h1 = h2; }
		Obj.width = w1;
		Obj.height = h1;
	}

	var url = '/';
				  if(Obj.dir)	url += 'dir';
								url += 'img/'
			 if (Obj.nocache) 	url += 'NC';
		  if (Obj.clearCache) 	url += 'CC';
								url	+= Obj.id;
	if(Obj.width&&Obj.height) {	url += '-'+Obj.width+'x'+Obj.height; 
		   if (Obj.forceSize) 	url += '-fz'; }
		  else if (Obj.width) 	url += '-w'+Obj.width;
		 else if (Obj.height) 	url += '-h'+Obj.height;
		   else if (Obj.size) 	url += '-'+Obj.size; 
		   
		   if (Obj.forceProp) 	url += '-fp'; 
		   if (Obj.watermark) 	url += '-wm'+Obj.watermark; 
			  if (Obj.square) {	url += '-sq'; if (typeof Obj.square == "string") url += Obj.square; }
			   if (Obj.magic) 	url += '-mg'+Obj.magic;
		  						url += '/';
			  if(!Obj.noname) {
				if (Obj.name) {	url += Obj.name; Obj.alt = Obj.name; Obj.title = Obj.name; }
		  else if (Obj.title)	url += Obj.title;
			else if (Obj.alt)	url += Obj.alt;
		   else if (Obj.file)	url += Obj.file;
						else	url += Obj.id;
			if (url.search(/.jpg$/)==-1) url += '.jpg'
			   }

	if ('nocache' in Obj) 	delete Obj.nocache;
	if ('clearCache' in Obj)delete Obj.clearCache;
	if ('forceSize' in Obj) delete Obj.forceSize;
	if ('size' in Obj) 		delete Obj.size;
	if ('forceProp' in Obj) delete Obj.forceProp;
	if ('watermark' in Obj) delete Obj.watermark;
	if ('square' in Obj) 	delete Obj.square;
	if ('magic' in Obj) 	delete Obj.magic;
	if ('noname' in Obj) 	delete Obj.noname;
	if ('file' in Obj) 		delete Obj.file;
	if ('dir' in Obj) 		delete Obj.dir;
	
	Obj.src = url;
	Obj.border = Obj.border || 0;
		  
	return Obj;
}

function showSizes() { 
	var SZ = {};
	
	SZ.Window = window.getSize();
	SZ.Document = document.getSize();
	SZ.Scroll = document.getScroll();
	SZ.Scrsize = document.getScrollSize();
	$each(SZ, function(obj,index){ alert(index+': '+'X: '+obj.x+'  /  Y: '+obj.y); });
}

function cryptString (address, encrypt) {
	
	/// mail 
	if (encrypt) {
		
		var CH = address.split('');
		var L = address.length;
		var R = [];
		for(var i=0;i<L; i++) { 
			R.push((255-address.charCodeAt([i])).toString(16));
		}
		return R.reverse().join( '' );
		
	} else {
	// 6d,65,40,6f,61,6d,79,2e,69,69,61,63,6c,6c,68,6f,64,6f,6f,6d
		address = address.split('').reverse().join('');
		var CH = []; 
		for(var a=0; a<address.length; a+=2) CH.push(address.substr(a,2));
		var L = CH.length;
		var R = [];
		for(var i=0;i<L; i++) {
			R.push(String.fromCharCode(255-parseInt(CH[i],16)));
		}
		return R.join( '' );
	}
	

}

function decryptMail(OBJ) {
	try{OBJ.erase('target');} catch(e){} 
	var mp = new RegExp("\/mailto\/([^\/]+)").exec( OBJ.href ) ; 
	var mails = cryptString(mp[1], false);
	OBJ.href = "mailto:"+ mails;
	if(OBJ.innerHTML == "[E-Mail]") {
		var M = mails.split('?');
		OBJ.innerHTML = M[0];
	}
}