var IE = document.all?true:false;
document.onmousedown = getMouseXY; 
var tempX = 0; 
var tempY = 0; 

var cX = 0; var cY = 0;
var passfocus;
var currentPhoto=0;
var picsaveWidth = 0;
var eventFade;
var fillFade;


function array_crop(){
    var myArray = new Array();
    myArray[0] =document.getElementById('input_crop_x').value;
    myArray[1] =document.getElementById('input_crop_y').value;
    myArray[2] =document.getElementById('input_crop_width').value;
    myArray[3] =document.getElementById('input_crop_height').value;
    myArray[4] =document.getElementById('crop_suid').value;
    myArray[5] =document.getElementById('crop_area').value;
    return myArray ;
}


function fliptab(tab,wich){
    var i;
    divs=document.getElementsByTagName('div');
    for(i=0;i<divs.length;i++){
        if(divs[i].id.substring(0,tab.length)==tab){//we found our tab divs
            divs[i].style.zIndex=i;
            if(divs[i].id==tab+"_"+wich){
                divs[i].style.zIndex=divs.length;
            }
        }
    }
    tds=document.getElementsByTagName('td');
    for(i=0;i<tds.length;i++){
        if(tds[i].id.substring(0,tab.length)==tab){//we found our tab divs
            if(tds[i].id==tab+"_"+wich){
                tds[i].style.backgroundColor="#006D9C";
                tds[i].style.color="#ffffff";
            }else{
                tds[i].style.backgroundColor="#f7f7f7";
                tds[i].style.color="#006D9C";
            }
        }
    }
    
}

function scaleImg(what){
    what = document.getElementById(what);
    if (navigator.appName=="Netscape") winW = window.innerWidth;
    if (navigator.appName.indexOf("Microsoft")!=-1)    winW = document.body.offsetWidth;

    if (what.width>720 || picsaveWidth>720) {
        if (what.width==720) {
            what.width=picsaveWidth;
        } else {
            picsaveWidth = what.width;
            what.style.cursor = "pointer";
            what.width=720;
        }
    }
}


function kill_overlay(rand,cid,mdid,loader){
    sel=document.getElementById('adult_ok'+rand);
    if(sel.options[sel.selectedIndex].value==0){
        document.location='browse_videos.php'
    }else{
        createCookie('adult_verification',1,100);
        hide_me('adultoverlay'+rand);
        event_process(cid,mdid+"|1",'welcome_video',loader);
    }
}


function doc_jump(anch){
    document.location.hash=anch;
}

function delete_me(id){
    aId=document.getElementById(id);
    if(aId){
        aId.parentNode.removeChild(aId);
    }
}

function passit(ip){
    if (passfocus) return;
    var np=ip.cloneNode(true);
    np.type='password';
    if(np.value!=ip.value)
    np.value=ip.value;
    np.disabled=false;
    ip.parentNode.replaceChild(np,ip);
    passfocus=true;
    return np;
}

function GetSelectVal(id){
    sel=document.getElementById(id);
    return sel.options[sel.selectedIndex].value;
}



function getSelRadioValue(radio_name,form){
    frm=document.getElementById(form);
    for(i=0; i < frm.elements.length; i++){
        if (frm.elements[i].type=='radio' && frm.elements[i].name==radio_name){
            if(frm.elements[i].checked == true) {
                return frm.elements[i].value;
            }
        }
    }
}

function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(mdiv,correction) {
    d=document.getElementById(mdiv);
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
            winH = document.body.offsetHeight;
        }	
    }
    scrolls=getScrollXY();
    d.style.left=winW/2-d.offsetWidth/2;
    d.style.top=winH/2-d.offsetHeight/2+scrolls[1];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function showFullScreen(url){
    window.open(url,'fullplay','fullscreen=yes, scrollbars=none');
}

function create_css_picker(objId,preset){
	//Declare the Font Picker Variable.
	var myFontPicker = new FontPicker ();
	myFontPicker.boundControl = objId;
	myFontPicker.scriptAction = "";
	//Set the Font Picker object options
	if(preset=='box'){
        myFontPicker.showDemo = true;

	    myFontPicker.showBold = false;
	    myFontPicker.showItalic = false;
	    myFontPicker.showUnderline = false;
	    myFontPicker.showFontFace = false;
	    myFontPicker.showFontSize = false;
	    myFontPicker.showColor = false;

        myFontPicker.showBorderSize = true;
        myFontPicker.showBorderColor = true;
        myFontPicker.showBackColor = true;
	    myFontPicker.showStatus = true;
        myFontPicker.demoMessage = "BOX"
    }else{
        myFontPicker.showDemo = true;
	    myFontPicker.showBold = true;
	    myFontPicker.showItalic = true;
	    myFontPicker.showUnderline = true;
	    myFontPicker.showFontFace = true;
	    myFontPicker.showFontSize = true;
	    myFontPicker.showColor = true;
        myFontPicker.showBorderSize = true;
        myFontPicker.showBorderColor = true;
        myFontPicker.showBackColor = true;
	    myFontPicker.showStatus = true;
        myFontPicker.demoMessage = "text text text text text"
    }
    
	
	myFontPicker.width = "400px";
    //Font Picker Look and Feel Settings
	/*
	myFontPicker.CSSSettings_Status = "color: #FFFFFF; font: normal 8px Verdana; border: none;";
	myFontPicker.CSSSettings_Button = "padding:0 0 0 0; background-color:#CCCCCC;";
	myFontPicker.CSSSettings_Object = "background-image:#FFFFFF;border: 2px outset #657390;";
	myFontPicker.CSSSettings_Control = "background-color:#657390;border: none;";
	myFontPicker.CSSSettings_Demo = "background-color:#FFFFFF;border: 2px inset #657390;";
	*/
	//Construct the Font Picker font list array.
	var myFontPicker_FontArray = new Array();
	
	/*myFontPicker_FontArray.push("Arial");
	myFontPicker.objectFonts = myFontPicker_FontArray;
    */
	myFontPicker.fontSize_minimum = 8;
	myFontPicker.fontSize_maximum = 32;				                                        
	//Instantiate the Font Picker object.
	myFontPicker.Instantiate();

}


function select_value(selId,val){
    sel=document.getElementById(selId);
    if (!sel) return;
    for(i=0;i<sel.options.length;i++){
        if(sel.options[i].value==val){
            sel.options[i].selected=true;
            return;
        }
    }
}

function getMouseXY(e) { 
    if (IE) { // grab the x-y pos.s if browser is IE 
        tempX = event.clientX + document.body.scrollLeft; 
        tempY = event.clientY + document.body.scrollTop;
    }else {  // grab the x-y pos.s if browser is NS 
        tempX = e.pageX; 
        tempY = e.pageY; 
    }   
    if (tempX < 0){tempX = 0;} 
    if (tempY < 0){tempY = 0;}   
    return true; 
}
function set_position(divid,posX, posY){
    mydiv=document.getElementById(divid);
    if(posX) tempX=tempX/posX;
    if(posY) tempY=tempY/posY;
    mydiv.style.left=tempX;
    mydiv.style.top=tempY;
    mydiv.style.position='absolute';
}


function bif(id){
    chk=document.getElementById(id);
    if(chk) chk.checked=!chk.checked;
}


function Pulsate(element,opacity,duration,steps,options){
        new Rico.Effect.FadeTo(element,opacity,duration,steps,options);
        new Rico.Effect.FadeTo(element,1,duration,steps,options);
}

function select_all(sel){
    sel=document.getElementById(sel);
    for(i=0;i<sel.length;i++){
        sel.options[i].selected=true;
    }
}

function uncheckRadios(frm){
    oform=document.getElementById(frm);
    els = oform.elements;
    for(i=0;i<els.length;i++){
        if (els[i].type == 'radio'){
            els[i].checked=false;
        }
    }
}
function show_me(id,frm,sh_mode){
    aId=document.getElementById(id);
    if(!sh_mode) sh_mode="block";
    if(aId){
        aId.style.display=sh_mode;
        aId.style.visibility="visible";
    }
    aFrm=document.getElementById(frm);
    if(aFrm){
        aFrm.style.display=sh_mode;
        aFrm.style.visibility="visible";
    }
}
function hide_me(id,frm){
    aId=document.getElementById(id);
    if(aId){
        aId.style.display="none";
    }
    aFrm=document.getElementById(frm);
    if(aFrm){
        aFrm.style.display="none";
    }
    //alert("hide "+id);
}

function m_collapse(elem,img,path){
    mdiv=document.getElementById(elem);
    mimg=document.getElementById("img_"+elem);    
    mhint=document.getElementById(elem+"_h");    
    if(!path) path="images/";
    if(mdiv.style.display=="block"){
        //mdiv.className="hideMe";
        mdiv.style.display='none';
        if(mimg) mimg.src=path+img+"max.gif";
        if(mhint) mhint.style.display='block';
    }else{
        //mdiv.className="showMe";
        mdiv.style.display='block';
        if(mimg) mimg.src=path+img+"min.gif";
        if(mhint) mhint.style.display='none';
    }
}
function hideWindowed(div,iframe){
    iframe.style.top=div.style.top;
    iframe.style.left=div.style.left;
    iframe.style.width=div.style.width;
    iframe.style.height=div.style.height;
    iframe.style.zIndex=div.style.zIndex-1;
    iframe.style.display='block';
}
var checkedall=false;
function checkAll(form){
    if(checkedall) {
        uncheckAll(form);
        return;
    }
    for (i=0; i<form.elements.length; i++){
        var chkName=form.elements[i];
        if (form.elements[i].type=='checkbox'){
            //filter only checkbox
            chkName.checked=true;
        }
    }
    checkedall=true;
}

function uncheckAll(form){
    for (i=0; i<form.elements.length; i++){
        var chkName=form.elements[i];
        if (form.elements[i].type=='checkbox'){
            //filter only checkbox
            chkName.checked=false;
        }
    }
    checkedall=false;
}
function have_selected(form){
    for (i=0; i<form.elements.length; i++){
        var chkName=form.elements[i];
        if (chkName.type=='checkbox'){
            if(chkName.id.substr(0,2)=='c_'){
                if(chkName.checked==true){
                    return true;
                }
            }
        }
    }
    return false;
}
function changecss(theClass,element,value) {
	var cssRules;
	if (document.all) {
	    cssRules = 'rules';
	}else if (document.getElementById) {
	    cssRules = 'cssRules';
	}
    classnames=theClass.split('|');
    for(var i=0;i<classnames.length;i++){
	    for (var S = 0; S < document.styleSheets.length; S++){
	        for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
                //alert(document.styleSheets[S][cssRules][R].selectorText+" "+theClass);
	            if (document.styleSheets[S][cssRules][R].selectorText == "."+classnames[i]) {
                    //alert(element+" "+value);
                    for(var j=0;j<document.styleSheets[S][cssRules][R].style.length;j++){
                        alert(document.styleSheets[S][cssRules][R].style[j]);
                    }
	                document.styleSheets[S][cssRules][R].style[element] = value;
	            }
	        }
	    }	
    }
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function checkIt(string){
    var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	return place;
}
function findObj(n, d){
    if(typeof n != "string") return n;
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length){
	    d=parent.frames[n.substring(p+1)].document;
	    n=n.substring(0,p);
    }
    if(!(x=d[n]) && d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++){
        x=d.forms[i][n];
    }

    for(i=0;!x&&d.layers&&i<d.layers.length;i++){
        x=findObj(n,d.layers[i].document);
    }
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}


function isValidAlphaNum(text)
{
	var i;

	for(i=0;i<text.length;i++)
	{
	ch=text.substr(i,1);
	if (!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z") || (ch>="0" && ch<="9") || ch=="-" || ch=="_" || ch=="." || ch==" "))
	{
		return false;
	}
	}
	return true;
}



function isValidGeneral(text)
{
    var i;

    for(i=0;i<text.length;i++)
    {
	ch=text.substr(i,1);
	if (!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z") || (ch>="0" && ch<="9") || ch=="?" || ch=="-" || ch=="_" || ch=="." || ch=="," || ch==" " || ch=="@" || ch=="!" || ch=="*" || ch=='$' || ch=='#' || ch=='&' || ch=='/'))
	{
	    return false;
	}
    }
    return true;
}

function isValidAlphaNumSpec(text)
{
    var i;

    for(i=0;i<text.length;i++)
    {
	ch=text.substr(i,1);
	if (!((ch>="a" && ch<="z") || (ch>="A" && ch<="Z") || (ch>="0" && ch<="9") || ch=="-" || ch=="_" || ch=="." || ch==" "))
	{
	    return false;
	}
    }
    return true;
}

function isValidEmail(str)
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp)
  {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
 return (!r1.test(str) && r2.test(str));
}

function isValidNum(text)
{
    var i;
    for(i=0;i<text.length;i++)
    {
	ch=text.substr(i,1);
	if (!((ch>="0" && ch<="9") || ch=="-" || ch=="_" || ch=="." || ch==" "))
	{
	    return false;
	}
    }

    return true;
}

function isValidMatch(str,form,exist){
    m=str.split(";");
    if(form){
        frm=findObj(form);
        var pass1=find_on_form(m[0],frm);
    }else{
        var pass1=findObj(m[0]);
    }
    
    if(exist){
        if (!pass1.value){
            return true;
        }
    }
    if(form){
        var pass2=find_on_form(m[1],frm);
    }else{
        var pass2=findObj(m[1]);
    }
    
    if (pass1.value!=pass2.value){
		pass1.value="";
		pass2.value="";
		pass1.focus();
		return false;
    }
    return true;
}
function isValidOne(str,form){
    m=str.split(";");
    for(i=0;i<m.length;i++){
        if(form){
            frm=findObj(form);
            var pass1=find_on_form(m[i],frm);
        }else{
            var pass1=findObj(m[i]);
        }
        if(pass1.value!="") return true;
    }
    return false;
}
function isValidSelectCount(str,form,exist){
    m=str.split(";");
    if(form){
        frm=findObj(form);
        var pass1=find_on_form(m[0],frm);
    }else{
        var pass1=findObj(m[0]);
    }
    var sel_count=0;
    var maxCnt = pass1.options.length;
    for(var i = 0; i < maxCnt-1; i++) {
        if ((pass1.options[i] != null) && (pass1.options[i].selected == true)) {
            sel_count++;
        }
    }
    if(exist){//must have at least one selected
        if (!sel_count) return false;
    }
    if(sel_count>m[1]){//allow limited selected items only
        return false;
    }
    return true;
}

function isValidCheckboxCount(str,form,exist){
    m=str.split(";");
    oform=document.getElementById(form);
    els = oform.elements;
    var sel_count=0;
    for(i=0;i<els.length;i++){
        if (els[i].id == m[0]){
            if(els[i].checked){
                sel_count++;
            }
        }
    }
    if(exist){//must have at least one selected
        if (!sel_count) return false;
    }
    if(sel_count>m[1]){//allow limited cehckboxes items only
        return false;
    }
    return true;
}


function isValidLength(str,form,exist){
    m=str.split(";");
    if(form){
        frm=findObj(form);
        var pass1=find_on_form(m[0],frm);
    }else{
        var pass1=findObj(m[0]);
    }
    if(exist){
        if (!pass1.value){
            return true;
        }
    }
    if (pass1.value.length<m[1]){
		pass1.value="";
		pass1.focus();
		return false;
    }
    return true;
}

function isNull(str,form){
    if(form){
        frm=findObj(form);
        var o=find_on_form(str,frm);
    }else{
        var o=findObj(str);
    }
    if(!o) {
        alert(str+" dont exists ");
        return true;
    }
    if (o.value=="0" || o.value==""){
		o.focus();
		return true;
    }
    return false;
}

function find_on_form(currVar,oFormName){
    if (typeof oFormName == "string") {
		oFormName = document.forms[oFormName] || document.getElementById(oFormName);
    }
    if (typeof currVar != "string") {
        currVarName=currVar.id;
    }else{
        currVarName=currVar;
    }
	for (var i = 0; i < oFormName.elements.length; i++) {
		var el = oFormName.elements[i];
		if (el.id==currVarName || el.name==currVarName) {
            return el;
		}
	}
    return null;
}

function validateForm(val_names,val_types,val_titles,form){
    var currVar;
    var i;
    for (i=0;i<val_names.length;i++){
	    if(val_types[i]<=8){
            if(form){
                currFrm=findObj(form);
                currVar=find_on_form(val_names[i],currFrm);
            }else{
                currVar=findObj(val_names[i]);
            }
        }else{
            currVar=val_names[i];
        }

        if(currVar){
            if(val_types[i]<=8){
	            if (val_types[i]<5){
                    if(currVar.value==""){
    		            alert(val_titles[i]);
		                currVar.focus();
		                return false;
	                }
	            }else{
	                val_types[i]-=4;
	            }
	            if ((val_types[i]==1) && !isValidAlphaNum(currVar.value)){
	                alert(val_titles[i]);
	                currVar.focus();
	                return false;
	            }
	            if ((val_types[i]==2) && !isValidNum(currVar.value)){
	                alert(val_titles[i]);
	                currVar.focus();
	                return false;
	            }
	            if ((val_types[i]==3) && !isValidEmail(currVar.value)){
	                alert(val_titles[i]);
	                currVar.focus();
	                return false;
	            }
	            if ((val_types[i]==4) && !isValidGeneral(currVar.value)){
	                alert(val_titles[i]);
	                currVar.focus();
	                return false;
	            }
            }else{
	            if ((val_types[i]==9) && !isValidMatch(currVar,form)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==10) && !isValidLength(currVar,form)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==11) && isNull(currVar,form)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==12) && !isValidLength(currVar,form,true)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==13) && !isValidMatch(currVar,form,true)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==14) && !isValidSelectCount(currVar,form)){
	                alert(val_titles[i]);
	                return false;
	            }
	            if ((val_types[i]==15) && !isValidSelectCount(currVar,form,true)){
	                alert(val_titles[i]);
	                return false;
	            }
                if ((val_types[i]==16) && !isValidCheckboxCount(currVar,form,true)){
                    alert(val_titles[i]);
                    return false;
                }
                if ((val_types[i]==17) && !isValidOne(currVar,form,true)){
                    alert(val_titles[i]);
                    return false;
                }

                if ((val_types[i]==19)){
                    val=GetEditorContents(currVar);
                    if(!val){
                        alert(val_titles[i]);
                        return false;
                    }
                }
            }
        }else{
            alert('JS: You try to validate inexistent field '+val_names[i]);  
            return false;
        }
    }
	return true;
}

//GENERAL ajax
var _p;
function init_ajax(){
    _p = ajax_loader.prototype = new pAjax;
    _p.load_select = function (suid,html_obj,method,extra,multi,wait){
        var oRequest = this.prepare(method, pAjaxRequest.POST);
	    oRequest.setURI("ajax_loader.php");
        oRequest.setParam("suid", suid);
        oRequest.setParam("html_obj", html_obj);
        if(extra) oRequest.setParam("extra", extra);
        if(multi) oRequest.setParam("multi", multi);
        if(wait) ajax_wait(mdiv,0,"");
        oRequest.execute(pAjaxRequest.ASYNC);
    }
    _p.record_action = function (mdiv,suid,method,wait,mode) {//sends ids and methods
        var oRequest = this.prepare(method, pAjaxRequest.POST);
	    oRequest.setURI("ajax.php");
        oRequest.setParam("mdiv", mdiv);
        oRequest.setParam("suid", suid);
        if(wait) ajax_wait(mdiv,0,"");
        if(!mode){
            oRequest.execute(pAjaxRequest.ASYNC);
        }else{
            oRequest.execute(pAjaxRequest.SYNC);
        }
    }
    _p.record_post_form = function (mdiv,frm,method,wait,mode) {//sends form posts
        var oRequest = this.prepare(method, pAjaxRequest.POST);
        oRequest.setURI("ajax.php");
        oRequest.setParam("mdiv", mdiv);
        frm=document.getElementById(frm);
        oRequest.setFormParam(frm);
        if(wait) ajax_wait(mdiv,0,"");
        if(!mode){
            oRequest.execute(pAjaxRequest.ASYNC);
        }else{
            oRequest.execute(pAjaxRequest.SYNC);
        }
    }
    _p.onCreate = function () {
        //st=document.getElementById('statusContainer');
        //if(st) ajax_wait("Please wait ... ");
	}
    _p.onLoad = function () {
        var data = this.getResponse();
        eval(data[0]+"(data[1],data[2]);");
        //st=document.getElementById('statusContainer');
        //if(st) ajax_wait("",3);
        mouter=document.getElementById('outer');
        if(mouter) hide_me('outer');
        n=3;
        if(n) setTimeout( "ajax_fade()", n );
    }
}
function ajax_loader(){
    pAjax.call(this);
    pAjax.setDebugMode(false);
}
function ajax_wait(mdiv,n,s) {
    
    l=findPosX(document.getElementById(mdiv));
    t=findPosY(document.getElementById(mdiv));
    w=document.getElementById(mdiv).offsetWidth;
    h=document.getElementById(mdiv).offsetHeight;
    //alert(mdiv+" - "+t+" - "+h);
    
    document.getElementById(mdiv).innerHTML="";
    document.getElementById(mdiv).style.width=w;
    document.getElementById(mdiv).style.height=h;

    document.getElementById('statusContainer').style.left=l+2;
    document.getElementById('statusContainer').style.top=t+h/2;
    document.getElementById('statusContainer').style.width=w-4;
    //document.getElementById('statusContainer').style.height=40;

    //document.getElementById('statusMsg').innerHTML = "works";
    Effect.Appear('statusContainer',{duration:0.4,to:1});
    $('statusContainer').style.visibility = "visible";
    //if(n) setTimeout( "$('statusContainer').style.visibility = 'hidden';", n );
    if(n) setTimeout( "ajax_fade()", n );
      
}
function ajax_fade(){
    if(document.getElementById('statusContainer')) $('statusContainer').style.visibility = 'hidden';
}


//SELECT loader
function loader(obj_name,list){
    hideLoader(obj_name);//creates a loader span in front of obj element        
    
	var box2 = document.getElementById(obj_name);
    if(list=="null") return;
	reset_select(obj_name);
	for(i=0;i<list.length;i++){
		box2.options[i] = new Option(list[i].label,list[i].value);
	}
    try{
        eval("sel"+obj_name+"();");
    }catch(e){}
}
function load_select(sel,obj,method,extra,multi){
    init_ajax();
    if(sel.options[sel.selectedIndex].value=="0") return;
    showLoader(obj);//creates a loader span in front of obj element    
    _p.load_select(sel.options[sel.selectedIndex].value,obj,method,extra,multi);
}
function hideLoader(obj){
    ldr=document.getElementById(obj+"_loader"); 
    if(ldr) ldr.parentNode.removeChild(ldr);
}

function showLoader(obj){
    try{
        ldr=document.getElementById(obj); 
        loader_span=document.createElement("span");
        loader_span.id=obj+"_loader";
        loader_span.style.float="left";
        loader_span.style.position="absolute";
        loader_span.innerHTML='<img src=ajax-loader.gif>';
        ldr.parentNode.insertBefore(loader_span,ldr);
    }catch(e){}
}

function reset_select(sel){
    var box2 = document.getElementById(sel);
    while(box2.options[0]!=null){
        box2.options[0]=null;
    }
}

//RECORD EDIT/VIEW
var old_content="";
function fill_data(content,mdiv){

    //alert(content);
    cdiv=document.getElementById(mdiv);
    if(cdiv){
        if(content!="") cdiv.innerHTML=content;
        try{
            new Rico.Effect.FadeTo( mdiv, 1, // 100% opacity 
                                      200, // 500ms (1/2 second) 
                                      20 // 10 steps
                                      );
        }catch(e){}
                                  
    }
    run_js(mdiv);
    lajax=cdiv.previousSibling;
    if(lajax && lajax.id=='ajaxloader') cdiv.parentNode.removeChild(lajax);
    //document.getElementById('deb').value=content;
}

function fill_data_style(content,mdiv){
    //alert('ok');
    var browserName=navigator.appName; 
    cdiv=document.getElementById(mdiv);
    if (browserName=="Netscape"){ 
        for (i=0;i<document.styleSheets.length; i++ ){
          if (document.styleSheets[i].title){
            document.styleSheets[i].disabled = true;
            if (document.styleSheets[i].title == 'themesty')
              document.styleSheets[i].disabled = false;
          }
        }    
        content[1]=content[0]+content[1];
    }else{ 
        if(browserName=="Microsoft Internet Explorer"){
            for (i=0;i<document.styleSheets.length; i++ ){
                //alert (document.styleSheets[i].title);
                if (document.styleSheets[i].title == 'themesty') document.styleSheets[i].cssText=content[0];
            }
            //document.styleSheets[0].cssText=content[0]+document.styleSheets[0].cssText;
            //document.styleSheets[0].disabled = false;
        }    
    }
    if(cdiv){
        cdiv.innerHTML=content[1];
    }
    try{
        new Rico.Effect.FadeTo( mdiv, 1, // 100% opacity 
                              500, // 500ms (1/2 second) 
                              20 // 10 steps
                              );    
    }catch(e){}
    run_js(mdiv);
    //document.getElementById('deb').value=content;
}

function fill_data_end(content,mdiv){
    document.getElementById(mdiv[0]).innerHTML=content;
    document.getElementById(mdiv[1]).innerHTML="Edit";
}
function record_cancel(mdiv,lnk){
    document.getElementById(mdiv).innerHTML=old_content;
    document.getElementById(lnk).innerHTML="Edit";
}
function record_edit(mdiv,id,method){
    init_ajax();
    old_content=document.getElementById(mdiv).innerHTML;
    _p.record_action(mdiv,id,method,1);//'user_edit'
}
function record_save(mdiv,method,form){
    init_ajax();
    field=find_on_form('receditAction',form);
    if(!field) return false;
    field.value=1;//action RECORDEDIT_OK
    _p.record_post_form(mdiv,form,method);//"ua_receditform"'user_save'
}
function create_new_list(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}
function delete_list(mdiv,id,method){
    init_ajax();
    _p.record_action(mdiv,id,method);
}

function edit_friend_comment(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}

function show_preview(sel){
    document.getElementById('canvas').style.display="block";
    document.getElementById('pholder').style.display="block";
    document.getElementById('tips').style.display="none";
    for (i=0; i<sel.options.length; i++) {
        if (sel.options[i].selected) {
            init_ajax();
           _p.record_action('canvas',sel.options[i].value,'preview_video');          
           break;
        }
    }    
}

function hide_preview(){
    document.getElementById('canvas').style.display="none";
    document.getElementById('pholder').style.display="none";
    document.getElementById('tips').style.display="block";
}

function film_strip(limit, id, method, mdiv,plid){
    init_ajax();
    args=new Array(); 
    args[0]=id;
    args[1]=limit;
    args[2]=plid;
    try{
        new Rico.Effect.FadeTo( mdiv, .0, // 20% opacity 
                                  100, // 500ms (1/2 second) s
                                  5 // 10 steps
                                  );
    }catch(e){}                            
    _p.record_action(mdiv,args,method);
    
}

function post_comment(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}
function delete_topic(mdiv,id,method){
    init_ajax();
    _p.record_action(mdiv,id,method);
}
function subscription(mdiv,id,method){
    init_ajax();
    _p.record_action(mdiv,id,method);
}
function group_subscription(mdiv,id,method){
    init_ajax();
    _p.record_action(mdiv,id,method);
}


function subscribe_tag(mdiv,id,method,loader){
    init_ajax();
    show_me('sresult');
    if(loader) document.getElementById(mdiv).innerHTML='<img src='+loader+'>';
    _p.record_action(mdiv,id,method);
}

function done_subscription(val,res){
    if(res) {
        tt=val.split("|");
        document.getElementById('butSubscr').value=tt[0];
    }else{
        alert('Ajax error');
    }
    run_js(tt[1]);
}

function done_add_friend(val,res){
    if(res) {
        document.getElementById('addtofriends').innerHTML=val;
    }else{
        alert('Ajax error');
    }
    run_js(val);
    hide_me('channel_actions');
    hide_me('actionsDivBig');
    show_me('watchActionsTable')    
}

function accept_p_comment(mdiv,id,method){
    init_ajax();
    _p.record_action(mdiv,id,method);
}

function fill_playlist(content,mdiv){
//    document.getElementById(mdiv).style.width='100%';
//    document.getElementById(mdiv).style.height='100%';
    plays=content[0];
    viewsel=content[1];
    suid=content[2];
    methodSel=content[3];
    mdivSel=content[4];
    plid=content[5];
    cdiv=document.getElementById(mdiv);
    if(cdiv){
        cdiv.innerHTML=plays;
        try{
            new Rico.Effect.FadeTo( mdiv, 1, // 100% opacity 
                                      100, // 500ms (1/2 second) 
                                      5 // 10 steps
                                      );    
        }catch(e){}
    }
    if(!viewsel){
        film_strip(0,suid,methodSel,mdivSel,-1);
    }else{
        film_strip(0,suid,methodSel,mdivSel,plid);
    }
    run_js(mdiv);
}
function refreshAd(mdiv){
    var d=document.getElementById(mdiv);
    if(d){
        var s=d.getElementsByTagName('iframe');
        if(s && s.length){
            
            s[0].src=s[0].src+'&'+new Date().getTime();
        }
    }
    return true;
}


function run_js(mdiv){
    
    myDiv=document.getElementById(mdiv);
    if(myDiv){
        htmlString=myDiv.innerHTML;
    }else{
        htmlString=mdiv;
    }
    
    //alert(htmlString);
    var re = /<script\b.*?>([\s\S]*?)<\/script/ig; 
    var match;
    while (match = re.exec(htmlString)) {
        //alert(match[1]);
        eval(match[1]);
    }
    //refreshAd(mdiv) ;
}


function watch_action(mdiv,id,method,height,loader){
    init_ajax();
    if(loader) document.getElementById(mdiv).innerHTML='<img src='+loader+'>';
    show_me("actionsDivBig");
    hide_me('watchActionsTable');
    if(height) document.getElementById('actionsDivBig').style.height=height;
    _p.record_action(mdiv,id,method);
}


function watch_action_done(mdiv,frm,method,loader){
    init_ajax();
    show_me("actionsDivBig");
    hide_me('watchActionsTable');
    _p.record_post_form(mdiv,frm,method);
    if(loader) document.getElementById(mdiv).innerHTML='<img src='+loader+'>';
}

function channel_action(mdiv,id,method,height,loader,showDiv){
    init_ajax();
    if(loader) document.getElementById(mdiv).innerHTML='<img src='+loader+'>';
    if(!showDiv) showDiv="yes";
    if(showDiv=="yes") show_me(mdiv);
    if(height) document.getElementById(mdiv).style.height=height;
    _p.record_action(mdiv,id,method);
}

function channel_share_done(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}

function approve_group_media(mdid, ugid,mode,mdiv,method){
    init_ajax();
    args=new Array(); 
    args[0]=mdid;
    args[1]=ugid;
    args[2]=mode;
    new Rico.Effect.FadeTo( mdiv, .0, // 20% opacity 
                                  100, // 500ms (1/2 second) s
                                  5 // 10 steps
                                  );
    _p.record_action(mdiv,args,method);

}


function delete_tag_sub(mdiv,seltag,id,method){
    init_ajax();
    args=new Array(); 
    args[0]=seltag;
    args[1]=id;
    _p.record_action(mdiv,args,method);
}

function reload_theme(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}
function reload_theme_preset(mdiv,thm,method){
    init_ajax();
    _p.record_action(mdiv,thm,method);
}

function send_rating(rate,mdid,mdiv,method){
    init_ajax();
    args=new Array(); 
    args[0]=rate;
    args[1]=mdid;
    document.getElementById(mdiv).style.position='relative';
    document.getElementById(mdiv).style.display='block';
    _p.record_action(mdiv,args,method);
}
var pb_status;
function call_pb(id,mdiv,method){
    setTimeout("refresh_pb('"+id+"','"+mdiv+"','"+method+"')",5000)
}

function refresh_pb(id,mdiv,method){
    init_ajax();
    //alert(mdiv + " - " + id + " - " + method);
    _p.record_action(mdiv,id,method,0);
}


function fill_pb(content,mdiv){
    pb_status=content[0];
/*$content[]='working';
$content[]=$id;//upload id
$content[]=$pb;//pb content - html
$content[]=$eta;//time to finish: minutes/seconds
$content[]=$speed;//KB/sec
$content[]=$upl;//bytes uploaded
$content[]=$total; //total bytes
$content[]=$meter;//percent uploaded    
*/
    //alert(content[0]+" "+content[1]);
    if(content[0]=='refresh' || pb_status=='working') setTimeout("refresh_pb('"+content[1]+"','"+mdiv+"','upload_progress')",5000);
    cdiv=document.getElementById(mdiv);
    //if(content[0]=='refresh' || content[0]=='done') content[2]=document.location='my_videos.php?upload=1';//content[2]="Upload finished";
    if(content[0]=='done') content[2]="Upload finished";
    if(cdiv){
        cdiv.innerHTML=content[2];
        new Rico.Effect.FadeTo( mdiv, 1, // 100% opacity 
                                  100, // 500ms (1/2 second) 
                                  5 // 10 steps
                                  );    
    }
    run_js(mdiv);
}

function load_banner(mdiv,wich){
    init_ajax();
    if(!document.getElementById(mdiv)) return;
    _p.record_action(mdiv,wich,"get_banners");
}


function event_exec(mdiv,arg,method){//run in sync mode, so js waits for the ajax to return before going to next function
    init_ajax();
    if(mdiv){
        mdivO=document.getElementById(mdiv);
        if(!mdivO){
            //alert("no container in template");
            return;
        } 
    }
    
    frm=document.getElementById(arg);
    if (frm && typeof frm != "undefined"){
        _p.record_post_form(mdiv,arg,method,0,true);   
    }else{
        _p.record_action(mdiv,arg,method,false,true);
    }
}

function event_process(mdiv,arg,method,loader,keepContent){
    init_ajax();
    if(mdiv){
        mdivO=document.getElementById(mdiv);
        if(!mdivO){
            //alert("no container in template");
            return;
        } 
    }
    try{
        eventFade=new Rico.Effect.FadeTo( mdiv, .05, // 100% opacity 
                              200, // 500ms (1/2 second) 
                              20 // 10 steps
                              );    
    }catch(e){}
    if(loader){
        if(keepContent) {
            var spal = document.createElement('div');
            spal.setAttribute('style', 'position:absolute;');
            spal.setAttribute('id', 'ajaxloader');
            var al = document.createElement('img');
            al.setAttribute('src', loader);
            spal.appendChild(al);
            document.getElementById(mdiv).setAttribute('style', 'position:relative');
            document.getElementById(mdiv).parentNode.insertBefore(spal,document.getElementById(mdiv));
            
            //cont=document.getElementById(mdiv).innerHTML;        
            //if(loader) document.getElementById(mdiv).innerHTML="<span style='position:absolute' align=center><img src="+loader+"></span>"+cont;
        }else{
            var spal = document.createElement('div');
            spal.setAttribute('style', 'position:absolute;');
            spal.setAttribute('id', 'ajaxloader');
            var al = document.createElement('img');
            al.setAttribute('src', loader);
            spal.appendChild(al);
            document.getElementById(mdiv).setAttribute('style', 'position:relative');
            document.getElementById(mdiv).parentNode.insertBefore(spal,document.getElementById(mdiv));

            //document.getElementById(mdiv).innerHTML="<span style='position:absolute' align=center><img src="+loader+"></span>";
        }
    }

    frm=document.getElementById(arg);
    if (frm && typeof frm != "undefined"){
        _p.record_post_form(mdiv,arg,method);   
    }else{
        _p.record_action(mdiv,arg,method,false);
    }
}

function display_photo(mdiv,src){
    content="<img class=thumb style='float:right' src="+src+">";
    dv=document.getElementById(mdiv);
    if(dv) dv.innerHTML=content;
    closer=document.getElementById('closer');
    if(closer) closer.style.width=dv.style.width;
}

function GetEditorContents(name)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(name) ;

	// Get the editor contents in XHTML.
	//alert( oEditor.GetXHTML( false ) ) ;		// "true" means you want it formatted.
    return oEditor.GetXHTML(true);
}
function post_profile_comment(mdiv,frm,method){
    init_ajax();
    _p.record_post_form(mdiv,frm,method);
}


function loadobjs(){
    if (!document.getElementById) return;
    for (i=0; i<arguments.length; i++){
        var file=arguments[i];
        var fileref="";
        if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
            if (file.indexOf(".js")!=-1){ //If object is a js file
                fileref=document.createElement('script')
                fileref.setAttribute("type","text/javascript");
                fileref.setAttribute("src", file);
            }else if (file.indexOf(".css")!=-1){ //If object is a css file
                fileref=document.createElement("link")
                fileref.setAttribute("rel", "stylesheet");
                fileref.setAttribute("type", "text/css");
                fileref.setAttribute("href", file);
            }
        }
        if (fileref!=""){
            document.getElementsByTagName("head").item(0).appendChild(fileref)
            loadedobjects+=file+" " //Remember this object as being already added to page
        }
    }
}

function recreate_element(el){
    ele=document.getElementById(el);
    var clone = ele.cloneNode(false);
    pele=ele.parentNode;
    pele.removeChild(ele);
    pele.appendChild(clone);
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function clearCookies(){
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        cn=c.split('=');
        c=cn[0];
        eraseCookie(c);
        //alert(c);
    }
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}