




function popUpYouTube(URL) {
	window.open('http://www.justclicksix.com/youtubevideo.php?url='+URL, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=420');
}


/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}


function displaylimit(thename, theid, thelimit){
	var theform=theid!=""? document.getElementById(theid) : thename
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining.'
	if (document.all||ns6)
		document.write(limit_text)
	if (document.all){
		eval(theform).onkeypress=function(){
			return restrictinput(thelimit,event,theform)
			}
		eval(theform).onkeyup=function(){
			countlimit(thelimit,event,theform)
			}
	}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) {
			restrictinput(thelimit,event,theform)
		}, true);
		document.body.addEventListener('keyup', function(event) {
			countlimit(thelimit,event,theform)
		}, true);
	}
}




function strip_tags(str, allowed_tags) {
    // Strip HTML and PHP tags from a string
    //
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strip_tags/
    // +       version: 811.1812
    // +   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)
    // *     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>'

    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];

    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(/(<\/?[^>]+>)/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 postStringForm(docForm) {
    var submitContent = '';
    var formElem;
    var lastElemName = '';

    for (i = 0; i < docForm.elements.length; i++) {

        formElem = docForm.elements[i];
        switch (formElem.type) {
            // Text fields, hidden form elements
            case 'text':
            case 'hidden':
            case 'password':
            case 'textarea':
            case 'select-one':
					submitContent += formElem.name+"="+escape(formElem.value)+"&";
					while ( submitContent.indexOf('+') != -1){
						submitContent = submitContent.replace('+', encodeURIComponent('+'));
					}
            break;

            // Radio buttons
            case 'radio':
                if (formElem.checked) {
                    submitContent += formElem.name + '=' + escape(formElem.value) + '&'
                }
                break;

            // Checkboxes
            case 'checkbox':
                if (formElem.checked) {
                    // Continuing multiple, same-name checkboxes
                    if (formElem.name == lastElemName) {
                        // Strip of end ampersand if there is one
                        if (submitContent.lastIndexOf('&') == submitContent.length-1) {
                            submitContent = submitContent.substr(0, submitContent.length - 1);
                        }
                        // Append value as comma-delimited string
                        submitContent += ',' + escape(formElem.value);
                    }
                    else {
                        submitContent += formElem.name + '=' + escape(formElem.value);
                    }
                    submitContent += '&';
                    lastElemName = formElem.name;
                }
                break;

        }
    }
    // Remove trailing separator
    submitContent = submitContent.substr(0, submitContent.length - 1);
    return submitContent;
}

function getPageWithoutRedir(page, div, id){
		//page = fisier prelucrare, div= element care se actualizeaza
	var param = "id="+id;
	res = ajaxUpdate( div, page, {
		params:param,
		meth:"post",
		async:true,
		startfunc:"onById('loading')",
		endfunc:"offById('loading'); onById('"+div+"');",
		errorfunc:"ajaxError()" }
	);
	return false;
}

function getPage(page, div, redirTo, formData, loadingDiv){
	if(loadingDiv=='')
		loadingDiv = 'AJAXloading';
		//daca ajax response este gol si redirTo este setat se face redirectare
		//page = fisier prelucrare, div= element care se actualizeaza, loadingDiv - idul elementul care se afiseaza cand se face loading
	var param = formData;
	res = ajaxUpdate( div, page, {
		params:param,
		meth:"post",
		async:true,
		startfunc:"onById('"+loadingDiv+"')",
		endfunc:"offById('"+loadingDiv+"'); onById('"+div+"');redir('"+redirTo+"', '"+div+"')",
		errorfunc:"ajaxError()" }
	);
	return false;
}

function redir(url, div){
//url pagina catre care se face redirectul, div = divul in care se afiseaza raspunul
	if(getById(div).innerHTML==''){
		if(url!='')
			window.location=url;
	}
}

function onById(id){
	document.getElementById(id).style.visibility = "visible";
}
function offById(id){
	document.getElementById(id).style.visibility = "hidden";
}
function ajaxError(){
	alert( "There was an error encountered while performing the request. Please try again later." );
}
function getById(id){
	return document.getElementById(id);
}

function MsgBox(msg,msg1)
{
  spring = window.confirm(msg1);
  if (spring == true)
    openNewWindow(msg);
}

function openNewWindow(msg)
{
  window.location = msg;
}


function toggle(id){
  if (document.getElementById(id).style.display=='none')
    document.getElementById(id).style.display='';
  else
    document.getElementById(id).style.display='none';
}


function addInput(id,nr) {
	var elem = document.getElementById('elem_'+id);
  	var num = document.getElementById('count_'+nr);
  	var increment = parseInt(document.getElementById('count_'+nr).value)+1;

	num.value = increment;
	var newdiv = document.createElement('div');
	var divIdName = nr+'_'+increment+'Div';

	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = '<input type="file" name="'+nr+'_'+increment+'_'+id+'" /> <a href="javascript:removeElement(\''+divIdName+'\')">Remove</a>';
	elem.appendChild(newdiv);
}
function addInputFile(id,nr) {
	var elem = document.getElementById('elem_'+id);
  	var num = document.getElementById('count_'+nr);
  	var increment = parseInt(document.getElementById('count_'+nr).value)+1;

	num.value = increment;
	var newdiv = document.createElement('div');
	var divIdName = nr+'_'+increment+'Div';

	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = 'File<input type="file" name="'+nr+'_'+increment+'_'+id+'" /> Keywords<input type="text" name="keyw_'+nr+'_'+increment+'_'+id+'" style="width:100px" /> <a href="javascript:removeElement(\''+divIdName+'\')">Remove</a>';
	elem.appendChild(newdiv);
}

function addInputText(id,nr) {
	var elem = document.getElementById('elem_'+id);
  	var num = document.getElementById('count_'+nr);
  	var increment = parseInt(document.getElementById('count_'+nr).value)+1;

	num.value = increment;
	var newdiv = document.createElement('div');
	var divIdName = nr+'_'+increment+'Div';

	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = '<b>Field name</b><input type="text" name="'+increment+'_ctis" style="width:100px" /> <a href="javascript:removeElement(\''+divIdName+'\')">Remove</a>';
	elem.appendChild(newdiv);
}

function removeElement(divNum)
{

  var olddiv = document.getElementById(divNum);
	olddiv.innerHTML='';
}
