/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function gel(elid){
	return document.getElementById(elid);
}

function fpos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [parseInt(curleft),parseInt(curtop)];
	}
}

function toggle(elid){
	if (gel(elid).style.display != 'none'){
		gel(elid).style.display = 'none';
	} else {
		gel(elid).style.display = 'block';
	}
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
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;
}	

function setimghover(el){
	var divs = document.getElementsByTagName("div");
	for(i=0; i < divs.length; i++){
		if(divs.item(i).id.substr(0,8) == 'imglink_'){
			//divs.item(i).style.background = '#FFFFFF';
			divs.item(i).style.borderColor = '';
		}
	}
	//el.style.background='#FFEECC';
	el.style.borderColor = '#6699FF';
}

function setgalleryover(el){
	el.style.borderColor = '#6699FF';
}

function setgalleryout(el){
	el.style.borderColor = '#E4E1DA';
}

function trhover(el){
	el.style.background='#F3F3F3';
}

function trout(el){
	el.style.background='';
}


function showUploadForm(){
	//gel('uploadForm').style.top = gel('uploadForm').style.top+4+'px';
	//gel('uploadForm').style.left = gel('uploadForm').style.left+4+'px';
	toggle('uploadForm');
}

function hideUploadForm(){
	toggle('uploadForm');
}

function showImage(fname,fhtml){
	gel('image_full').src = 'img/user/'+fname;
	gel('image_comments').innerHTML = fhtml;
	//gel(flink).style.border = '1px solid #778899';
}

function touch_url(x_url) {
	this.req = new XMLHttpRequest();
	req.open('GET', x_url, true);
	req.send(null);
}

function getget(varname){
	var qs = location.search;

	qs = location.search.substring(1);
	var pairs = qs.split("&");

	var tmpAry;
	for(var i=0; i<pairs.length; i++){
		tmpAry = pairs(i).split("=");
		if (tmpAry(0) = varname) // name
			return tmpAry(1); // value
	}
	return false;
}

function checkContactForm(){
	if (gel('cf_name').value != '' && gel('cf_message').value != ''){
		gel('cf_source').value = 'human';
		return true;
	} else {
		return false;
	}
}

function show_form(lng){
	gel('form_it').style.display = 'none';
	gel('form_en').style.display = 'none';
	gel('form_es').style.display = 'none';
	gel('form_po').style.display = 'none';
	gel('a_it').style.fontWeight = 'normal';
	gel('a_en').style.fontWeight = 'normal';
	gel('a_es').style.fontWeight = 'normal';
	gel('a_po').style.fontWeight = 'normal';
	
	gel('a_'+lng).style.fontWeight = 'bold';
	gel('form_'+lng).style.display = 'block';
}

function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'

	var key = '', allowed = false;
	var matches = [];
	var allowed_array = [];
	var allowed_tag = '';
	var i = 0;
	var k = '';
	var html = '';
	
	var replacer = function(search, replace, str) {
	    return str.split(search).join(replace);
	};
	
	// Build allowes tags associative array
	if (allowed_tags) {
	    allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
	}
	
	str += '';
	
	// Match tags
	matches = str.match(/(<\/?[\S][^>]*>)/gi);
	
	// Go through all HTML tags
	for (key in matches) {
	    if (isNaN(key)) {
	        // IE7 Hack
	        continue;
	    }
	
	    // Save HTML tag
	    html = matches[key].toString();
	
	    // Is tag not in allowed list? Remove from str!
	    allowed = false;
	
	    // Go through all allowed tags
	    for (k in allowed_array) {
	        // Init
	        allowed_tag = allowed_array[k];
	        i = -1;
	
	        if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
	        if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
	        if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
	
	        // Determine
	        if (i == 0) {
	            allowed = true;
	            break;
	        }
	    }
	
	    if (!allowed) {
	        str = replacer(html, "", str); // Custom replace. No regexing
	    }
	}
	
	return str;
}

function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
str = str.replace( /\s*tab-stops:[^"]*/gi, "" ) ;
str = str.replace( /\s*face="[^"]*"/gi, "" ) ;
str = str.replace( /\s*face=[^ >]*/gi, "" ) ;
str = str.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
str = str.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
str = str.replace( /\s*style="\s*"/gi, '' ) ;
str = str.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
str = str.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
str = str.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
str = str.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;
str = str.replace(/<\\?\?xml[^>]*>/gi, "") ;
str = str.replace(/<\/?\w+:[^>]*>/gi, "") ;
str = str.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
str = str.replace( /<H1([^>]*)>/gi, '' ) ;
str = str.replace( /<H2([^>]*)>/gi, '' ) ;
str = str.replace( /<H3([^>]*)>/gi, '' ) ;
str = str.replace( /<H4([^>]*)>/gi, '' ) ;
str = str.replace( /<H5([^>]*)>/gi, '' ) ;
str = str.replace( /<H6([^>]*)>/gi, '' ) ;
str = str.replace( /<\/H\d>/gi, '<br>' ) ; //remove this to take out breaks where Heading tags were
str = str.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;
str = str.replace( /<(B|b)>&nbsp;<\/\b|B>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
//some RegEx code for the picky browsers
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;
str = str.replace( re, "<div$2</div>" ) ;
var re2 = new RegExp("(<font|<FONT)([^*>]*>.*?)(<\/FONT>|<\/font>)","gi") ;
str = str.replace( re2, "<div$2</div>") ;
str = str.replace( /size|SIZE = ([\d]{1})/g, '' ) ;

return str ;
}
