function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}

function WithoutNewContent(ss) {
if(ss.value !== ss.defaultValue) { return false; }
return true;
}


function NoneWithContent(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].value.length > 0) { return false; }
        }
return true;
}

function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].checked) { return false; }
        }
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}

function WithoutSelectionValue(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].selected) {
                if(ss[i].value.length) { return false; }
                }
        }
return true;
}

function change_vis( obj )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( o.style.display == "none" )
    {
      if( o.tagName == "TR" )
        o.style.display = "table-row";
      else
        o.style.display = "block";
    }
    else
      o.style.display = "none";
  }
  else
  {
    if( document.all[obj].style.display == "none" )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}  

function set_vis( obj, vis )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( vis )
    {
      if( o.tagName == "TR" )
        o.style.display = "table-row";
      else
        o.style.display = "block";
    }
    else
      o.style.display = "none";
  }
  else
  {
    if( vis )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}

//Pop-up Window Auto Center
var win= null;
function popWin(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

// this function is called with the id of the form that need to be verified
function CheckForChanges(objForm) {
	var theForm = eval('document.getElementById("'+objForm+'")');
	var msg = 'Nu ai salvat modificarile facute pe aceasta pagina! Prin accesarea acestui link, toate modificarile(editarile) vor fi pierdute.\n\nClick Ok pentru a continua sau foloseste butonul Cancel pentru a merge la loc astfel incat sa poti salva modificarile facute.\n\n';
	var theObj;
	var changed_fields = "\n";
	var changes_detected = false;
	
	//Validate Information
	for (var i=0; i<theForm.length; i++) 
	{
		theObj = theForm.elements[i];
		var checkObj = true;		
		
		if (typeof(exceptions) == 'undefined')
			var exceptions_len = 0;
		else
			var exceptions_len = exceptions.length;
		
		for (j=0;j<exceptions_len;j++)
		{
			if(exceptions[j] == theObj.name)
				checkObj = false;
		}
		
		if (checkObj)
		{
			if (theObj.type == 'text') 
			{
				if (theObj.value != theObj.defaultValue)
				{
					changes_detected = true;
					changed_fields += theObj.name+" ";
				}
			}
			else if (theObj.type == 'textarea')
			{
				if (theObj.value != theObj.defaultValue)
				{
					changes_detected = true;
					changed_fields += theObj.name+" ";
				}
			}
			else if (theObj.type == 'select-one')
			{
				if (theObj.options[theObj.selectedIndex].defaultSelected != true)
				{
					changes_detected = true;
					changed_fields += theObj.name+" ";
				}
			}
			else if (theObj.type == 'checkbox')
			{
				if (theObj.defaultChecked != theObj.checked)
				{
					changes_detected = true;
					changed_fields += theObj.name+" ";
				}
			}
			else if (theObj.type == 'radio')
			{
				if (theObj.defaultChecked != theObj.checked)
				{
					changes_detected = true;
					changed_fields += theObj.name+" ";
				}
			}

		}
	}
	
	if (changes_detected)
	{
		question = confirm(msg);
		if (question != "0")
			return true;
		else return false;
	}
}

function phone_type_focus(item){
	if (item.value == "Custom Phone Type:")
		item.value='';
}

function phone_type_blur(item){
	if (!item.value.length)
		item.value="Custom Phone Type:";
}
function formatPhone(objPhone) {
	var basePhone = "";
	var newPhone = "";
	if (objPhone.value.length > 0) {
		var intAllowed = "0123456789";
		for (var i=0;i<objPhone.value.length;i++) {
			for (var j=0;j<intAllowed.length;j++) {
				if (objPhone.value.charAt(i) == intAllowed.charAt(j)) {
					basePhone += objPhone.value.charAt(i);
					break;
				}
			}
		}
		if (basePhone.length != 10) {
			alert("Trebuie sa introduci un numar format din 10 cifre.");
			objPhone.focus();
		} else {
			var prefix = basePhone.substr(0,3);
			if (prefix == "031" || prefix == "021")
			{
				newPhone += "(" + basePhone.substr(0,3) + ")"; // area code
				newPhone += " " + basePhone.substr(3,7); // suffix
			}
			else
			{
				newPhone += "(" + basePhone.substr(0,4) + ")"; // area code
				newPhone += " " + basePhone.substr(4,6); // prefix
			}
			objPhone.value = newPhone;
		}
	}
}
//
function just_formatPhone(objPhone) {
	var basePhone = "";
	var newPhone = "";
	if (objPhone.value.length > 0) {
		var intAllowed = "0123456789";
		for (var i=0;i<objPhone.value.length;i++) {
			for (var j=0;j<intAllowed.length;j++) {
				if (objPhone.value.charAt(i) == intAllowed.charAt(j)) {
					basePhone += objPhone.value.charAt(i);
					break;
				}
			}
		}
		if (basePhone.length == 10) {
			var prefix = basePhone.substr(0,3);
			if (prefix == "031" || prefix == "021")
			{
				newPhone += "(" + basePhone.substr(0,3) + ")"; // area code
				newPhone += " " + basePhone.substr(3,7); // suffix
			}
			else
			{
				newPhone += "(" + basePhone.substr(0,4) + ")"; // area code
				newPhone += " " + basePhone.substr(4,6); // prefix
			}
			objPhone.value = newPhone;
		}
	}
}

function validateEmail(inValue) {
	var objRegExp = "^([a-zA-Z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$";
	var objEmailRegExp = new RegExp(objRegExp);
	return objEmailRegExp.test(inValue.toLowerCase());
}

function validateForm(objForm) {
	var theForm = eval('document.getElementById("'+objForm+'")');
	var msg = '';
	var theObj;
	var intPos;
	var Count = 0;
	
	//Validate Information
	for (var i=0; i<theForm.length; i++) {
		theObj = theForm.elements[i];
		intPos = theObj.name.indexOf("_");
		
		if (theObj.name.substring(0,intPos) == "Req") {
			if (theObj.type == 'text') {
				if (theObj.name.indexOf("ag") != -1) {
					if (theObj.value.length == 0) {
						Count ++;
						theObj.className = 'req_form';
					} else if (theObj.value.length > 0 && theObj.name.toLowerCase().indexOf("ag_email") != -1) {
						var isValidEmail = validateEmail(theObj.value);
						if (!isValidEmail) {
							msg += '-- ' + theObj.name.substring(intPos+4,theObj.name.length) + ' pare sa nu fie o adresa de e-mail valida.\n';
							msg += '   Verifica daca adresa de e-mail introdusa este cea corecta.  Ex: numelemeu@internet.ro\n\n';
							Count++
							theObj.className = 'req_form';
						} else {
							theObj.className = 'form';
						}
					} else {
						theObj.className = 'form';
					}
				}
			} else if (theObj.type == 'textarea') {
				if (theObj.name.indexOf("ag") != -1) {
					if (theObj.value.length == 0) {
						Count++;
						theObj.className = 'req_form';
					} else {
						theObj.className = 'form';
					}
				}
			} else if (theObj.type == 'select-one') {
				if (theObj.name.indexOf("ag") != -1) {
					if (theObj.options[theObj.selectedIndex].value == "") {
						Count++;
						theObj.className = 'req_form';
					} else {
						theObj.className = 'form';
					}
				}
			}
		}
	}
	if (Count > 0) {
		msg += "-- Cateva campuri obligatorii din formular nu au fost completate.\n   Completeaza te rog campurile marcate cu rosu si apoi vei putea continua.";
	}
	
	if (msg.length > 0) {
		alert(msg);
		document.getElementById("top").scrollIntoView();
		return false;
	} else {
		return true;
	}
	
}

function wizard_alert(location)
{
	question = confirm("Iesirea din actiunea de constuire a unei pagini imobiliare noi va duce la pierderea informatiilor introduse pana acum!!\n\nEsti sigur ca vrei sa renunti la construirea unei pagini imobiliare noi?")
	if (question !="0"){
		window.location = location;
	}
}

