var d = document;
var w = window;

/*
  _i GETS the object associated with some id, and returns it
*/
   function _i(id){var _q = d.getElementById(id);return _q;}function _ip(id){var _q = pd.getElementById(id);return _q;}

function SubmitForm(form_id){
var fobj = _i(form_id);
  fobj.submit();
}

/*
  CHANGES THE CLASS OF SOME OBJECT
*/
function swclass(id,newclassname){var currelem = _i(id);currelem.className=newclassname;}


// PHP - explode() compatible
function explode(delimiter,string){
  var resArr= string.split(delimiter);
  return resArr;
}

//  PHP - implode() compatible
function implode(delimiter, arr) {
        var genstr ='';
                for (var i = 0; i < arr.length; i++){
                        if(arr[i]){
                            var genstr = genstr+arr[i]+delimiter;
                        }
                }
                genstr = genstr.substring(0, genstr.length-1);
        return  genstr;
}
// PHP print_r() compatible
function print_r(arr){
        for(var value in arr){
                document.write('<br>'+value+' => '+arr[value]);
        }
}


function DELETE_CONFIRMATION(info){//dialog box
	var arr=info.split(',');	
	var id= arr[0];
	var j= arr[1];
	if(j==1){
		var url = "login_list.php?ac=del&eid=";
	}
	url = url+id;
	// -- // alert(url); // return false;
	var where_to= confirm("Do you really want to DELETE this record?");
	if (where_to== true){
		window.location=url;
	}
};
function changeV(did,sw){

	var ideditname;
	var ideviewname;
     
	ideditname = 'edit_'+did;
	ideviewname = 'view_'+did;
//lert
    el  =  document.getElementById(ideditname);
    el1 =  document.getElementById(ideviewname);
 
   if(sw!='view'){
	  el.style.display='none';
	  el1.style.display='block';
	}

  if(sw!="edit"){
	  el.style.display='block';
	  el1.style.display='block';
  }

};

function CheckCount(id,ns) {
	var txtcon;
	var countdiv;
	var el;
	var ts;
	txtcont  = 'smst_'+id;
	countdiv = 'showcount_'+id;
    
	el = d.getElementById(txtcont);
    countel = d.getElementById(countdiv);
	ts = el.value;
    //alert(ts);
    smsLength = el.value.length;

  if (smsLength > ns) {
   // MyForm.title_t.value=MyForm.title_t.value.substring(0,ns);
     el.value = el.value.substring(0,ns);
    countel.innerHTML = 0;
  } else{
    countel.innerHTML = ns - smsLength;
  }
}

function SwitchView(id) {
 var obj = d.getElementById(id);
 //alert("Object id: "+id);
  if (obj.style.display == 'none') {
    obj.style.display = 'block';
  }
  else {
    obj.style.display = 'none';
  }
}
function SH(id) {
	//alert('id ime:'+id);
 var obj = d.getElementById(id);
  if (obj.style.display == 'none') {
    obj.style.display = 'block';
  }
  else {
    obj.style.display = 'none';
  }
}

// hides and sisplays at the same time div objects
// usage ShowHide('divid1,divid2,divid3','divid4,divid5',',');
function ShowHide(objtoshow,objtohide,border){
	var  toshowArr = new Array();
	var  tohideArr = new Array();
	var	 $i	=	0;
    toshowArr = str_to_arr(objtoshow,border);
	tohideArr = str_to_arr(objtohide,border);

	// display needed divs 
	if(toshowArr!=""){
		for($i=0;$i<toshowArr.length;$i++){
			if(document.getElementById(toshowArr[$i])){
				document.getElementById(toshowArr[$i]).style.display    = 'block';
			}
		}
	}
	// hide needed divs 
	if(tohideArr!=""){
		for($i=0;$i<tohideArr.length;$i++){
			if(document.getElementById(tohideArr[$i])){
				document.getElementById(tohideArr[$i]).style.display    = 'none';
			}
		}
	}
}
function str_to_arr(str,border){
  var arr=str.split(border);
  return arr;
}

function in_array(strr,marray){
	var i=0; // var i=0; - local i=0; - globalna promenliva
	for(i=0;i<marray.length;i++){
		if(marray[i]==strr){
			return 1;
		}
	}
	return 0;
}

function StepMark(curstepid){
	if(curstepid=='step1'){
		/* GET NEXT STEP DIV*/
		var nextstepid = curstepid.replace('1','2');
		/* GET CURRENT PROGRESS FIELD*/
		var progrcurstid  = curstepid+'p';
		/* GET NEXT PROGRESS FIELD*/
		var progrnextstid = progrcurstid.replace('1','2');
	}else if(curstepid=='step2'){
		var nextstepid = curstepid.replace('2','3');
		var progrcurstid  = curstepid+'p';
		var progrnextstid = progrcurstid.replace('2','3');
	}else if(curstepid=='step3'){
		var nextstepid    = curstepid.replace('3','4');
		var progrcurstid  = curstepid+'p';
		var progrnextstid = progrcurstid.replace('3','4');
	}else if(curstepid=='step4'){
		var nextstepid = curstepid.replace('4','5');
		var progrcurstid  = curstepid+'p';
		var progrnextstid = progrcurstid.replace('4','5');
	}else if(curstepid=='step5'){
		var nextstepid    = curstepid.replace('5','6');
		var progrcurstid  = curstepid+'p';
		var progrnextstid = progrcurstid.replace('5','6');
	}
       var progcurstatid = progrcurstid+'st';
	   // the id of the idv holding the current class of the menu button
	      var thisclassid = progrcurstid+'c'; 
	      document.getElementById(thisclassid).innerHTML    = 'stepproc';
        /* CHANGE THE CURRENT CLASS OF THE NEXT MENU */
	      var nextclassid = progrnextstid+'c';
	      document.getElementById(nextclassid).innerHTML    = 'stepac';
        /* HIDE CURRENT */
        document.getElementById(curstepid).style.display    = 'none';
		/* DISPLAY NEXT */
		document.getElementById(nextstepid).style.display   = 'block';
        /* SET CURRENT PROGRESS FIELD AS PROCESSED  */
		document.getElementById(progrcurstid).className     = 'stepproc';
		/* SET NEXT PROGRESS FIELD AS ACTIVE  */
		document.getElementById(progrnextstid).className    = 'stepac';
		/* DISPLAY STATUS IMAGE */
		document.getElementById(progcurstatid).className    = 'npstatus';
		document.getElementById(progcurstatid).innerHTML    = '<IMG SRC="img/ok.gif" WIDTH="13" HEIGHT="13" BORDER=0 ALT="">';
}

/*
 *  changes the class of the specified element
 */
function ChangeClass(elementid,chclass){
	document.getElementById(elementid).className = chclass;
}

function ChangeBackClass(elementid){
	var id = elementid+'c';
	var currclass = document.getElementById(id).innerHTML;
	document.getElementById(elementid).className = currclass;
}
function hidediv(id) {
  //alert('hide:' + id);
 //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
     document.getElementById(id).style.display = 'none';
  }
  else {
     if (document.layers) { // Netscape 4
         document.id.display = 'none';
     }
     else { // IE 4
         document.all.id.style.display = 'none';
     }
  }
};

/////////////////////////////////////////////////////////////////////////////////	system_clients.php
function EDIT_STATUS(id){
	var button	=	"butt"+id;
	var reason	=	"r"+id;
	var text	=	document.getElementById(reason).value;
	text=text.replace(/ /g,"");
	if(text!='' && text!='<?=$TRS[146]?>'){
		if(text.length>=10){
			document.getElementById(button).disabled = false;
			document.getElementById(button).className='buttons';
		}else if(text.length<10){
			document.getElementById(button).disabled = true;
			document.getElementById(button).className='disbuttons';
		}
	}
};

function toggleTranslate(id) {

  el = document.getElementById(id);
  if (el.style.display == 'block') {
    el.style.display = 'none';
  }
  else {
    el.style.display = 'block';
  }
};

function ShowDiv(id){
	el = document.getElementById('page');
	if (el.style.display == 'none') {
		el.style.display = 'block';
	}
};
function INNER(obj1,obj2,obj3){
	var	codefirst	=	obj1;
	var code		=	obj2;
	var inpu		=	obj3;
	var	textt	=	document.getElementById(codefirst).options[document.getElementById(codefirst).selectedIndex].text;
	//document.getElementById(codefirst).options[document.getElementById(codefirst).selectedIndex].text;else{
	if(textt!="-- Please Select --"){
		document.getElementById(code).innerHTML=textt;
		document.getElementById(inpu).value=textt;
	}else{
		document.getElementById(code).innerHTML="";
		document.getElementById(inpu).value="";
	}
};

function INNERR(obj1,obj2,obj3){
	var	codefirst	=	obj1;
	var code		=	obj2;
	var inpu		=	obj3;
	var	textt	=	document.getElementById(codefirst).options[document.getElementById(codefirst).selectedIndex].text;
	//document.getElementById(codefirst).options[document.getElementById(codefirst).selectedIndex].text;
	if(textt!="SOF"){
		document.getElementById(code).innerHTML=textt;
		document.getElementById(inpu).value=textt;
	}else{
		document.getElementById(code).innerHTML="";
		document.getElementById(inpu).value="";
	}
};

function myfunction(obj){
	alert(obj.options[obj.selectedIndex].text);
	obj.selectedIndex // returns the index of the selected option, ie: 0,1,2...
	obj.value //returns the value of the selected option
	obj.options[obj.selectedIndex].text // returns the text nested in the selected option
};

/*
VRUSHTA izbranata stinost ili text ot SELECT MENU
*/
function GetSelectVal(selectid,type){
    
	var sellobj =   _i(selectid);
	var selind  = sellobj.selectedIndex;
    if(type=='value'){
	var selval  = sellobj.options[selind].value;
	}else{
	var selval  = sellobj.options[selind].text;
	}
	return selval;
			 
};
//////////////////////////////////////////////////////////////////////////////
function popUpBig(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left = 262,top = 134');");
};
/////////////////////////////////////////////////////////////////////////////////
function CHG_IMAGE(id,image){
	document.getElementById(id).src = image;
};
///////////////////////////////////////////////////////////////////////////////////				SET COOKIE
function setCookie(c_name,value,expiredays){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
};
///////////////////////////////////////////////////////////////////////////////////				GET COOKIE
function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  var c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	   	var c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return ""
};
////////////////////////////////////////////////////////////////////////////////////////////////			SET DIV-s VISIBLITY
function check_div_Cookie(){
	var div_id=getCookie('div_id');
	if (div_id!=null && div_id!=""){
		var up_arr	=	div_id+"_up_arr";
		var down_arr	=	div_id+"_down_arr";
		//alert('Welcome again '+div_id+'!')
		document.getElementById(div_id).style.display    = 'block';
		document.getElementById(up_arr).style.display = 'block';
		document.getElementById(down_arr).style.display = 'none';
		
	}
};
////////////////////////////////////////////////////////////////////////////////////////////////			SET CHART TYPE
function check_chart_Cookie(){
	chart_type=getCookie('chart');
	if (chart_type!=null && chart_type!=""){
		//alert(chart_type);
	}
};
/////////////////////////////////////////////////////////////////////////////////////////////
function popUp(URL,width,height,resizable) {
	day = new Date();
	//var width	=	width;
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=" + resizable + ",width=" + width + ",height=" + height + ",left = 262,top = 134');");
};
//////////////////////////////////////////////////////////////////////////////
function replace_value(rid){
	var mad	=	"made" + rid;
	var due	=	"repldue" + rid;
	var reason	=	"reason" + rid;
	var made = document.getElementById(mad).value;
	var repldue = document.getElementById(due).value;
	if(made!=repldue){
		document.getElementById(reason).style.display	=	'block';
		var maded	=	"maded" + rid;
		document.getElementById(maded).value=made;
		return false;
	}
	return true;
};
///////////////////////////////////////////////////////////////////////////// POPUP DIV ///////////////////////////////////
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
};

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
};

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
};

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function LoadPopUpData(dttoload,title){
// vzimame dannite koito shte puhnem v containera
   var dannitoload = _i(dttoload).innerHTML;
// setvame title-a
   _i('popuptitle').innerHTML = title;
// zarejdame dannite v containera
   _i('popupdanni').innerHTML = dannitoload;
// praim go visible
   SH('info');
}
/*
KAK SE VIKA!
<a href="#" onclick="LoadPopUpData('content1','title 1')">LoadPopUpData 1</a>
<a href="#" onclick="LoadPopUpData('content2','title2')">LoadPopUpData 2</a>
<div id="content1">TOVA E SUDURJANIE 11111111</div>
<div id="content2">TOVA E SUDURJANIE 22222222</div>
*/
function JavActionCheck(){
var curactiontotakeid = _i('JavActionId').innerHTML;
 // alert(curactiontotakeid);
 // imame edit sluchai i triabva da zaredim otnovo edit diva sus sudrurjanie
	if(curactiontotakeid==1){
		_i('editsiteform').innerHTML = dannitoload;
        _i('JavActionId').innerHTML = '';
	}
	if(curactiontotakeid==2){
		_i('addnewsiteform').innerHTML = adddannitoload;
        _i('JavActionId').innerHTML = '';
	}
	if(curactiontotakeid==3){
        _i('JavActionId').innerHTML = '';
		_i('glasspane').className='glasspaneinactive';
	}
	// step 1 ot extra replacements
	if(curactiontotakeid==21){
		_i('step1').innerHTML = step1content;
        _i('JavActionId').innerHTML = '';
        _i('glasspane').className='glasspaneinactive';
	}
};
////////////////////////////////////////////////////////////////////////////////////////	SHOW DIVS - HIDE ALL OTHERS
function HideOtherDivs(strtosearch,idtoshow){
	RE = new RegExp(strtosearch, "i");
	var x = d.getElementsByTagName('div');
	for (i=0;i<x.length;i++){
	var thisdivid = x[i].id;
		if(thisdivid){
			if(thisdivid.match(RE)){
				d.getElementById(thisdivid).style.display = 'none';
			}
		}
	}
	if(d.getElementById(idtoshow)){
		d.getElementById(idtoshow).style.display = 'block';
	}
};

// EXTEND
Array.prototype.contains = function (element)
  {
          for (var i = 0; i < this.length; i++)
       {
              if (this[i] == element)
          {
                      return true;
              }
          }
          return false;
  };