// One object tracks the current modal dialog opened from this window.
// Generate a modal dialog.
//var win=null

//replaceAll function
String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}

function openDialog(url, name, w, h) {

          if (checkFocus()==1) {return 1}
          w=w+(0.05*w)
          h=h+(0.05*h)
          var left = (screen.availWidth - w) / 2
          var top = (screen.availHeight - h) / 2
          //var attr = "left=" + left + ",top=" + top + ",resizable=no,scroll=no,status=no,titlebar=0,width=" + w + ",height=" + h
          var attr = "resizable=no,scroll=no,status=no,titlebar=0,width=" + w + ",height=" + h
          // Generate the dialog and make sure it has focus.
          //alert(name)
          active=0
          name = window.open(url,name,attr)
          //name.focus()
}

// Grab all Navigator events that might get through to form elements while
// dialog is open. For Internet Explorer, disable form elements.

function checkFocus() {

  if (window.win)
          { if (window.win.closed) {self.status="ii inchisa";return 0}
               else {self.status=" nu ii inchisa";return 1}
          }
  else { self.status="nu exista"; return 0}
    }

function setFocus() {

  if (window.win)
          { if (window.win.closed) {self.status="ii inchisa";self.focus()}
               else {self.status="nu ii inchisa"; win.focus()}
          }
          else { self.status="nu exista";self.focus()}
    }

function openWindow(action,frameName,widthValue,heightValue){
  openDialog(action, frameName, widthValue, heightValue)
}

function openNewWindow()
{
	var img=document.images['image'];
      var newImg = new Image();
      source = img.src;
     	newImg.src = source;
	imgH = newImg.height;
	imgW = newImg.width;
      var name = source.substr(source.lastIndexOf("/")+1, source.length);
      name = name.replaceAll(".","");
      name = name.replaceAll("%","");
      name = name.replaceAll("+","");
      name = name.replaceAll("-","");
	openDialog(source, name, imgW, imgH);
}

function openNewWindow2()
{
	var img=document.images['image'];
      var newImg = new Image();
      source = img.src;
      newSource = source.replace(/Medii/, "Mari");
     	newImg.src = newSource;
      //alert(newSource);
      while(newImg.height==0){
      }
	imgH = newImg.height;
	imgW = newImg.width;
      alert('Image:'+imgW+','+imgH);
      var name = source.substr(source.lastIndexOf("/")+1, source.length);
	openDialog(newSource, name, imgW, imgH);
}

function changeImage(imagePath){
     // alert("changeImage")
      var img= document.images['image'];
      img.src = imagePath;
}

function changeSty(){
      //alert('change style')
      var url = location.href;
	param = url.substr(url.lastIndexOf('/')+1, url.length) ;
      param = param.replace('_en.php','');
	param = param.replace('.php', '');
      if ((param=="contact") || (param=="proiectare")) 
      	{}
      else {
            if ((param=="despre") || (param=="index"))
			id="mymenu1"
      	else if ((param=="mobilier") || (param=="peretiDespartitori") || (param=="scauneBirou"))
			id="mymenu2"
      		else if ((param=="dormitoare") || (param=="dressinguri") || (param=="bucatarii") || (param=="corpuriIluminat") || (param=="calorifereDecorative") || (param=="baiAccesorii") || (param=="scauneCanapele") || (param=="cameradezi") )
			id="mymenu3"
      	else if((param=="gresieFaianta") || (param=="ardezie"))
           		id="mymenu4";
		document.getElementById(id).className="show";
      	menu_status[id] = 'show';
     } 
}


// the following function is used to change the language, for internalization
function languageChange(toLang){
	var URL = document.URL;
      var newUrl;
	if(toLang == "enToRo"){
		newURL = URL.substring(0,URL.lastIndexOf(".")-3)+".php";
	}
	if(toLang == "roToEn"){
               if (URL == "http://www.archicraft.ro/") {
                   newURL = "http://www.archicraft.ro/index_en.php";
               }else{ 
		    	 newURL = URL.substring(0,URL.lastIndexOf("."))+"_en.php";
                   //newURL = URL+"?$lang=en";   
                }
	}
	document.getElementById('steag').href=newURL;
}

function openMovieLocal(){
window.open("http://www.hotelmonjardin.ro/play_avi.html","mywindow","location=1,status=1,scrollbars=0,width=435,height=375");
}
function openMovie(){
window.open("http://hotelmonjardin.ro/cazare_delta_dunarii/cazare_Delta_Dunarii_Hotel_Monjardin_film.php","mywindow","location=1,status=1,scrollbars=0,width=435,height=375");
}
function openPrice(){
window.open("http://www.hotelmonjardin.ro/cazare_delta_dunarii/cazare_delta_dunarii_hotel_tarife_content.php","mywindow","location=1,status=1,scrollbars=1,width=600,height=400");
}

function isEmpty(sir)
{
  jj=0;
  for(ii=0;ii<sir.length;ii++)
  {
    if (sir.charAt(ii)==" ")
     {jj++;}
    else
      {break;}
  }
  if (jj==sir.length)
   {return true;}
  else
   {return false;}
}


function check_form(form)
{
 return_boolean = true
 obj = eval(form)
 for(i=0;i<obj.length;i++)
 {
  field_name = obj.elements[i].name;
  if (field_name.indexOf("_ck") != -1)
  { if (isEmpty(obj.elements[i].value))
    {
      obj.elements[i].style.backgroundColor = "red";
      return_boolean = false
    }
    else
    {
      obj.elements[i].style.backgroundColor = "white";
    }
  }
  if (field_name.indexOf("_sp") != -1)
  { 
      obj.elements[i].value=trimAll(obj.elements[i].value);
      return_boolean=true;
  }
  if (field_name.indexOf("_int") != -1) {
    if (!checkInt(obj.elements[i].value))
    {
      obj.elements[i].style.backgroundColor = "lightgreen";
      return_boolean = false
    }
    else
    {
      obj.elements[i].style.backgroundColor = "white";
    }
  }
  if (field_name.indexOf("_eml") != -1) {

    if (!checkEmail(obj.elements[i].value))
      {
        obj.elements[i].style.backgroundColor = "yellow";
        return_boolean = false
      }
      else
      {
        obj.elements[i].style.backgroundColor = "white";
      }

  }
  if (field_name.indexOf("_phone") != -1) {

    if (!checkPhone(obj.elements[i].value))
      {
        obj.elements[i].style.backgroundColor = "blue";
        return_boolean = false
      }
      else
      {
        obj.elements[i].style.backgroundColor = "white";
      }

  }
  if (field_name.indexOf("_fl") != -1) {

    if (!checkPozitiveFloat(obj.elements[i].value))
      {
	obj.elements[i].style.backgroundColor = "gray";
	return_boolean = false
      }
      else
      {
	obj.elements[i].style.backgroundColor = "white";
      }

  }
 }
return return_boolean;
}

function checkInt(value){
  var intValue;

  if (isEmpty(value)) return true;
  if(isNaN(value)) return false;
  intValue=parseInt(value);
  if(intValue.toString()==value) return true;
  else return false;
  }

function checkPhone(value){
  if (isEmpty(value)) return false;
  value=value.replaceAll('.','');
  value=value.replaceAll('-','');
  if(isNaN(value)) return false;
  else return true; 
} 

function checkPozitiveFloat(value){
if (isEmpty(value)) return true;
if(!checkFloat(value)) return false;
    return (parseFloat(value)>=0);
}

function checkFloat(value){
    if(isNaN(value)) return false;
	return true;
  }

function checkEmail(value)
     {
     // Return false if e-mail field is blank.
     if ((value.indexOf ('@',0) == -1) || (value.indexOf ('.',0) == -1))
        { return false;
        }
     // Return false if e-mail field does not contain a '@' and '.' .
     else
        {
        return true;
        }
   }

function mouseOver()
{
document.getElementById("film_1").src ="images/film_over.jpg"
}
function mouseOut()
{
document.getElementById("film_1").src ="images/film.jpg"
}

function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
//alert(file_name.substring(file_name.lastIndexOf("/")+1, end));
//alert(file_name); 
        return file_name.substring(file_name.lastIndexOf("/")+1, end);
    }

function returnCurrentDoc()
{
 var fileName=returnDocument();
if(fileName.lastIndexOf("_en.php")!=-1 )
	    fileName=fileName.substring(0,fileName.lastIndexOf("_en.php"))+".php";
    else 
    	fileName=fileName.substring(0,fileName.lastIndexOf(".php"))+"_en.php";
//    alert(fileName);
    document.location.href=fileName;
 return fileName;
}



