/* RETURN OBJECT*/
function _i(id){
 objd = d.getElementById(id);	
 return objd;	
}

/*RESIZE TEXT FUNCTIONS*/
var maxsize ='16';
var minsize ='9';
var cursize = 11;
function BiggerSize(){
 if(cursize<=maxsize){
    cursize++;
	SetSize(cursize);
 }
}
function SmallerSize(){
 if(cursize>=minsize){
    cursize--;
	SetSize(cursize);
 }
}
function SetSize(newsize){
    document.getElementById('bodytext').style.cssText = "font-size:"+newsize+"px;";
}
/* HIDES AND DISPLAYS A SINGLE OBJECT*/
function SH(id) {

  el = document.getElementById(id);
  if (el.style.display == 'block') {
    el.style.display = 'none';
  }
  else {
    el.style.display = 'block';
  }
};

/* HIDES AND DISPLAYS SPECIFIED objects*/
function ShowHide(objtoshow,objtohide,border){//'all,fromupload','fromurl',','
	var toshowArr = new Array();
	var tohideArr = new Array();

    toshowArr = str_to_arr(objtoshow,border);
	tohideArr = str_to_arr(objtohide,border);

	// display needed divs 
	for($i=0;$i<toshowArr.length;$i++){
		document.getElementById(toshowArr[$i]).style.display    = 'block';
	}
	// hide needed divs 
	for($i=0;$i<tohideArr.length;$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){
	for(i=0;i<marray.length;i++){
		if(marray[i]==strr){
			return 1;
		}
	}
	return 0;
};
function MVR(paramVar1)
{
//document.getElementById("trnsprant"+paramVar1).style.cursor = "hand";
document.getElementById("trnsprant"+paramVar1).className = "vsb";


}
function MOT(paramVar1)
{
document.getElementById("trnsprant"+paramVar1).className = "trsp";
}
function GetLoc(loc)
{
window.location=loc;
}
function Colorchange(a,color){
document.getElementById(a).bgColor=color;
}

function Applysub(id)
{document.getElementById(id).style.display='block';
}

function ChangePreview(that,photo_title,path,preview_href){
//document.getElementById(id).style.display='block';
document.getElementById('preview').innerHTML='<a href='+preview_href+'><div  onClick="" style="cursor:pointer"><DIV STYLE="position:relative;left:0px;top:0px;padding:10px;cursor:hand;" TITLE="'+photo_title+'"><img  border="0" src="'+path+'" TITLE="'+photo_title+'" ALT="'+photo_title+'"><br><b>'+photo_title+'</b></DIV></DIV></a> ';
//alert(document.getElementById('preview').innerHTML);
//alert(id);
}



// -----------------------------------------------------
// Get window width in pixels; returns 0 if unidentifiable.
// -----------------------------------------------------
function getWindowWidth(){
  var ww = 0;
  d = document;
   if ( typeof window.innerWidth != 'undefined' )
     ww = window.innerWidth;  // NN and Opera version
   else
   {
     if ( d.documentElement
       && typeof d.documentElement.clientWidth!='undefined'
       && d.documentElement.clientWidth != 0 )
       ww = d.documentElement.clientWidth;
     else
       if ( d.body
         && typeof d.body.clientWidth != 'undefined' )
         ww = d.body.clientWidth;
     else alert ("Can't identify window width - please tell me which browser you are using.")
   }
   return ww;
}


function getWindowHeight(){
  var ww = 0;
  d = document;
   if ( typeof window.innerHeight != 'undefined' )
     ww = window.innerHeight;  // NN and Opera version
   else
   {
     if ( d.documentElement
       && typeof d.documentElement.clientHeight!='undefined'
       && d.documentElement.clientHeight != 0 )
       ww = d.documentElement.clientHeight;
     else
       if ( d.body
         && typeof d.body.clientHeight != 'undefined' )
         ww = d.body.clientHeight;
     else alert ("Can't identify window width - please tell me which browser you are using.")
   }
   return ww;
}

// -----------------------------------------------------
// Adjust image size according to window width
// -----------------------------------------------------

function resizeimg(id,src,status) {
  var ww = getWindowWidth();
  var wh=getWindowHeight();
  var im_wo=document.getElementById("myimg").width;
  var im_w=document.getElementById("myimg").width+300;
  var im_h=document.getElementById("myimg").height;
  var iw,ih;
  var text;
  status=Math.abs(status-1);
 var proportion;

        if (status==0){
             remainder_w=im_w-ww;
             remainder_h=im_h-wh;
             remainder_w_h=remainder_w-remainder_h;

	         if((remainder_w>=0)&&(remainder_h<=0)){
	                 iw=ww-300;
					 proportion=iw/im_wo;
                     ih=im_h*proportion;
                     document.getElementById('msg').style.display='block';
             }
             if((remainder_h>=0)&&(remainder_w<=0)){
	                 
                     ih=wh;
                     proportion=ih/im_h;
                     iw=im_wo*proportion;
                    document.getElementById('msg').style.display='block';
            }
          	if((remainder_h>=0)&&(remainder_w>=0)){
	                     if ( remainder_w_h>=0){
							     iw=ww-300;
                                proportion=iw/im_wo;
                                ih=im_h*proportion;
                                 document.getElementById('msg').style.display='block';
                         }
	                    if ( remainder_w_h<=0){
							  ih=wh;
                     proportion=ih/im_h;
                     iw=im_wo*proportion;
                                 document.getElementById('msg').style.display='block';
                        }
            }
          if((remainder_h<=0)&&(remainder_w<=0)){
                          iw=im_wo;
	                      ih=im_h;
                         document.getElementById('msg').style.display='none';
         }
   document.getElementById(id).innerHTML='<img id="myimg" src='+src+' width="'+iw+'"  height="'+ih+'"  onclick=resizeimg("'+id+'","'+src+'","'+status+'");>';
 // alert(document.getElementById(id).innerHTML);
  }
 


   if (status==1){

      document.getElementById('msg').style.display='none';
 document.getElementById(id).innerHTML='<img id="myimg" src='+src+'   onclick=resizeimg("'+id+'","'+src+'","'+status+'");>';
 // alert(document.getElementById(id).innerHTML);
  }

}

function showsize(){
  alert("Window width = " + getWindowWidth());
}

function ViewAlbumDesc(id){
document.getElementById(id).style.display='block';
}

function HideAlbumDesc(id){
document.getElementById(id).style.display='none';
};

//functions,used in pd.php

   function getData(){
         return true;
   }
  function insertData(cs){
	    if(cs==1){
		    document.f2.tpp.value=1;
        }else if(cs==2){
		    document.f2.tpp.value=2;
	    }else if(cs==3){
		    document.f2.tpp.value=3;
	    }else if(cs==4){
		    document.f2.tpp.value=4;
	    }
	 
	   var rd = document.getElementById("reportdetails");
	   rt = rd.innerHTML;
	   document.f2.data.value=rt;
	   //alert(document.f2.data.value);
	   document.f2.submit();
	   return true;
  }
  function HTMLtoPDF(){
	   var rd = document.getElementById("reportdetails");
	   rt = rd.innerHTML;
	   document.pdf_form.inner.value=rt;
	   window.open('','Loading',height=100,width=100);
	   document.pdf_form.submit();
	   return true;
  }

  
function CheckForm(){
	var	msg	= "";
	//lasty name
	var titl = document.contactform.x_msg.value;
	titl=titl.replace(/\"/g,"");
	titl=titl.replace(/@/g,"");
	titl=titl.replace(/#/g,"");
	titl=titl.replace(/\$/g,"");
	titl=titl.replace(/%/g,"");
	titl=titl.replace(/\^/g,"");
	titl=titl.replace(/\&/g,"");
	titl=titl.replace(/\*/g,"");
	titl=titl.replace(/ /,"");
	if (titl.length<10){
		msg="Съобщението трябва да съдържа поне десет символа!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//company
	var titl = document.contactform.x_company.value;
	titl=titl.replace(/\"/g,"");
	titl=titl.replace(/ /g,"");
	if (titl.length <3){
		msg="Моля, въведете Фирма!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//first name
	var titl = document.contactform.x_fn.value;
	titl=titl.replace(/\"/g,"");
	titl=titl.replace(/ /g,"");
	if (titl.length <3){
		msg="Моля, въведете име!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//lasty name
	var titl = document.contactform.x_ln.value;
	titl=titl.replace(/\"/g,"");
	titl=titl.replace(/ /g,"");
	if (titl.length <3){
		msg="Моля, въведете фамилия!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//city
	var titl = document.contactform.x_city.value;
	titl=titl.replace(/\"/g,"");
	titl=titl.replace(/ /g,"");
	if (titl.length <3){
		msg="Моля, въведете град!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//email check
	var Email=document.contactform.x_email.value;
	regexpEmail=/^[-a-zA-Z0-9_\.]{1,}[@][-a-zA-Z0-9_\.]{1,}[.][a-zA-Z]{2,4}$/;
	if(!regexpEmail.test(Email)){
		msg="Моля, въведете валиден е-майл!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	//phone
	var phone1= document.contactform.x_phone.value;
	if (phone1.length>0){
		regexpphone1=/^[-0-9+ ]{5,}$/;//				phone number
		if(!regexpphone1.test(phone1)){
			msg="Моля, въведете валиден е-майл!<br>";
			msg=msg.replace(/<br>/g,"");
			alert(msg);
			return false;
		}
	}
	//mobile
	var phone1= document.contactform.x_mobile.value;
	if (phone1.length>0){
		regexpphone1=/^[-0-9+ ]{5,}$/;//				phone number
		if(!regexpphone1.test(phone1)){
			msg="Моля, въведете валиден е-майл!<br>";
			msg=msg.replace(/<br>/g,"");
			alert(msg);
			return false;
		}
	}
	//lasty name
	var titl = document.contactform.x_msg.value;
	titl=titl.replace(/\"@/g,"");
	titl=titl.replace(/ /,"");
	if (titl.length<10){
		msg="Съобщението трябва да съдържа поне десет символа!<br>";
		msg=msg.replace(/<br>/g,"");
		alert(msg);
		return false;
	}
	
document.contactform.submit();
}
//