// JavaScript Document


function request_form() {
	//alert("hello");
   var name = document.getElementById('name');
   var postcode = document.getElementById('postcode');
   var phone = document.getElementById('phone');
   var email = document.getElementById('email');

	if(name.value =="")
  	 {
    alert("Please enter your name");
	name.focus();
	return false;
   }
    if(postcode.value =="")
   {
    alert("Please enter your postcode");
	postcode.focus();
	return false;
   }
   if(phone.value=="")
   {
    alert("Please enter your phone no.");
	phone.focus();
	return false;
   }
    if(!isInteger(phone.value))
   {
    alert("Please enter your valid phone no.");
	phone.focus();
	return false;
   }
   if(email.value=="")
   {
    alert("Please enter your email id.");
	email.focus();
	return false;
   }
    if(!conValidEmail(email.value))
   {
    alert("Please enter a valid  email address");
	email.focus();
	return false;
   }
    
}

function contact_request() {
	//alert("hello");
   var contactname = document.getElementById('contactname');
   var contact_email = document.getElementById('contact_email');
   var telephoneno = document.getElementById('telephoneno');
   var mobile_no = document.getElementById('mobile_no');
   
	if(contactname.value =="")
  	 {
    alert("Please enter your contact name");
	contactname.focus();
	return false;
   }
   
    if(contact_email.value =="")
   {
    alert("Please enter a email address.");
	contact_email.focus();
	return false;
   }
  
    if(!conValidEmail(contact_email.value))
   {
    alert("Please enter a valid  email address.");
	contact_email.focus();
	return false;
   }
   if(mobile_no.value =="")
   {
    alert("Please enter your mobile no.");
	mobile_no.focus();
	return false;
   }
    if(!isInteger(mobile_no.value))
   {
    alert("Please enter your valid mobile no.");
	mobile_no.focus();
	return false;
   }

    if(telephoneno.value =="")
   {
    alert("Please enter your phone no.");
	telephoneno.focus();
	return false;
   }
    if(!isInteger(telephoneno.value))
   {
    alert("Please enter your valid phone no.");
	telephoneno.focus();
	return false;
   }
 
}

function isVailidNumber(obj){
var num = obj.value;
var numRE = /^\d*[0-9]?$/;
if(num.match(numRE)){ return true }
else {return false }
}
function conValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}// JavaScript Document

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(phone){
	//var Phone=document.frmSample.txtPhone
	var phone = document.getElementById(phone);
	
	if ((phone.value==null)||(phone.value=="")){
		//alert("Please Enter your Phone Number")
		phone.focus()
		return false
	}
	if (checkInternationalPhone(phone.value)==false){
		//alert("Please Enter a Valid Phone Number")
		phone.value=""
		phone.focus()
		return false
	}
	return true
 }
 
 function printer_friendly(tagid)
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById(tagid).innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Inel Power System</title>'); 
   docprint.document.write('</head><body onLoad="self.print()"><center>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}

function fromreset()
{
	//alert("Reset");
document.getElementById('firstname').value="";
document.getElementById('lastname').value="";
document.getElementById('con_email').value="";
document.getElementById('work_phone').value="";
document.getElementById('home_phone').value="";
document.getElementById('mobile_no').value="";
}


function add_property_form()
{	
	//alert("hi");
	if(document.getElementById('p_code').value=='')
	{
		alert("Please Enter Your Property Code");
		document.getElementById('p_code').focus()
		//document.getElementById('trouser_size_td').style.color='red';
		return false;
	}
	if(!isInteger(document.getElementById('p_code').value))
   {
    alert("Property code will be in numbers only");
	document.getElementById('p_code').focus()
	return false;
   }
	
	if(document.getElementById('p_name').value=='')
   {
    alert("Please Your Property Name");
	document.getElementById('p_name').focus()
	return false;
   }	
   if(document.getElementById('property_type').selectedIndex == 0)
		{
		alert("Please Enter Your Property Type");
		document.getElementById('property_type').focus()
		//document.getElementById('visa_status_td').style.color='red';
		return false;
	}
	if(document.getElementById('property_country').selectedIndex==0)
	{
		alert("Please Select Property Country");
		document.getElementById('property_country').focus()
		return false;
	}
	else if(document.getElementById('property_city').selectedIndex==0)
	{
		alert("Please Select Property City");
		document.getElementById('property_city').focus()
		return false;
	}
	else if(document.getElementById('property_city').value=="Other" && document.getElementById('other_city').value=='')
	{
		alert("Please Enter Property City");
		document.getElementById('other_city').focus()
		return false;
	}
	else if(document.getElementById('location').selectedIndex==0)
	{
		alert("Please Select Property Area/Location");
		document.getElementById('location').focus()
		return false;
	}
	else if(document.getElementById('location').value=="Other" && document.getElementById('other_location').value=='')
	{
		alert("Please Enter Property Area/Location");
		document.getElementById('other_location').focus()
		return false;
	}
	if(document.getElementById('transaction_type').selectedIndex == 0)
		{
		alert("Please Enter Your Transaction Type");
		document.getElementById('transaction_type').focus()
		//document.getElementById('visa_status_td').style.color='red';
		return false;
	}
	
	if(document.getElementById('area').value=='')
	{
		alert("Please Enter Your Property Area");
		document.getElementById('area').focus()
		//document.getElementById('eye_color_td').style.color='red';
		return false;
	}
	
	if(document.getElementById('property_price').value=='')
	{
		alert("Please Enter Your Property Price");
		document.getElementById('property_price').focus()
		//document.getElementById('trouser_size_td').style.color='red';
		return false;
	}
	if(!isInteger(document.getElementById('property_price').value))
   {
    alert("Price will be in numbers only");
	document.getElementById('property_price').focus()
	return false;
   }
     if(document.getElementById('property_discription').value=='')
	{
		alert("Please Enter Your Property Discription");
		document.getElementById('property_discription').focus()
		//document.getElementById('trouser_size_td').style.color='red';
		return false;
	}
	if(document.getElementById('property_discription').value.length < 50) {
  alert("please enter minium 50 character property discription");
  document.getElementById('property_discription').focus();
  return false;
	}
	//Property Image one
	if(document.add_property.property_image.value != "") {
	var property_image = document.add_property.property_image.value;
	
	var filelength = parseInt(property_image.length) - 3;
	var fileext = property_image.substring(filelength,filelength + 3);
// Check file extenstion
	if (fileext != "jpg" & fileext != "jpeg")
		{
	alert ("You can only upload jpg images.");
 	document.add_property.property_image.focus();
	return false;
		} 
	}
	
	//Property Image 2
	if(document.add_property.property_image2.value != "") {
	var property_image = document.add_property.property_image2.value;
	
	var filelength = parseInt(property_image.length) - 3;
	var fileext = property_image.substring(filelength,filelength + 3);
// Check file extenstion
	if (fileext != "jpg" & fileext != "jpeg")
		{
	alert ("You can only upload jpg images.");
 	document.add_property.property_image2.focus();
	return false;
		}
		}
	
	//Property Image one
	if(document.add_property.property_image3.value != "") {
	var property_image = document.add_property.property_image3.value;
	
	var filelength = parseInt(property_image.length) - 3;
	var fileext = property_image.substring(filelength,filelength + 3);
// Check file extenstion
	if (fileext != "jpg" & fileext != "jpeg")
		{
	alert ("You can only upload jpg images.");
 	document.add_property.property_image3.focus();
	return false;
		} 
	}
	
	//Property Image one
	if(document.add_property.property_image4.value != "") {
	var property_image = document.add_property.property_image4.value;
	
	var filelength = parseInt(property_image.length) - 3;
	var fileext = property_image.substring(filelength,filelength + 3);
// Check file extenstion
	if (fileext != "jpg" & fileext != "jpeg")
		{
	alert ("You can only upload jpg images.");
 	document.add_property.property_image4.focus();
	return false;
		} 
	}
	
	}
	
function add_property_form_reset()
{
	//alert("Reset");
document.getElementById('contactname').value="";
document.getElementById('contact_email').value="";
document.getElementById('contact_title').value="";
document.getElementById('company').value="";
document.getElementById('street_Address').value="";
document.getElementById('city').value="";
document.getElementById('state').value="";
document.getElementById('postcode').value="";
document.getElementById('mobile_no').value="";
document.getElementById('telephoneno').value="";
document.getElementById('fax').value="";
}
	
function add_property_form_reset()
{
	//alert("Reset");
document.getElementById('company_name').value="";
document.getElementById('firstname').value="";
document.getElementById('lastname').value="";
document.getElementById('contact_no').value="";
document.getElementById('mobile_no').value="";
document.getElementById('user_email').value="";
document.getElementById('othersubcity').value="";
document.getElementById('req_select_title').value="";
document.getElementById('property_price').value="";
}
function user_form_validate() {
	
if(document.getElementById('firstname').value=='')
	{
		alert("Please Enter Your First Name");
		document.getElementById('firstname').focus()
		//document.getElementById('first_name_td').style.color='red';
		return false;
	}
	if(document.getElementById('lastname').value=='')
	{
		alert("Please Enter Your Last Name");
		document.getElementById('lastname').focus()
		//document.getElementById('family_name_td').style.color='red';
		return false;
	}
	else if(document.getElementById('contact_no').value=='')
	{
		alert("Please Enter Your Contact No");
		document.getElementById('contact_no').focus()
		//document.getElementById('nationality_td').style.color='red';
		return false;
	}
	else if(!isInteger(document.getElementById('contact_no').value))
   {
    alert("Please Enter Your Valid Contact No.");
	document.getElementById('contact_no').focus()
	return false;
   }
	else if(document.getElementById('mobile_no').value=='')
	{
		alert("Please Enter Your Mobile No");
		document.getElementById('mobile_no').focus()
		//document.getElementById('nationality_td').style.color='red';
		return false;
	}
	else if(!isInteger(document.getElementById('mobile_no').value))
   {
    alert("Please Enter Your Valid Mobile No.");
	document.getElementById('mobile_no').focus()
	return false;
   }
	
	else if(document.getElementById('user_email').value=='')
	{
		alert("Please Enter Your Email Address");
		document.getElementById('user_email').focus()
		//document.getElementById('dob_td').style.color='red';
		return false;
	}
	 else if(!conValidEmail(document.getElementById('user_email').value))
   {
    alert("Please Your Valid Email Address");
	document.getElementById('user_email').focus()
	return false;
   }	
	
	
	
}
function hidecity() {
if(document.getElementById('property_country').value=='United Arab Emirates') {
document.getElementById('property_city').disabled = false;
document.getElementById('other_city').style.visibility = 'hidden';
document.getElementById('location').disabled = false;
document.getElementById('other_location').style.visibility = 'hidden';
}
else {
document.getElementById('property_city').disabled = true;
document.getElementById('other_city').style.visibility = 'visible';
document.getElementById('location').disabled = true;
document.getElementById('other_location').style.visibility = 'visible';
}
}
function hidelocation() {
/*if(document.getElementById('property_city').value=='Dubai') {
document.getElementById('location').disabled = false;
document.getElementById('other_location').style.visibility = 'hidden';

}
else {
document.getElementById('location').disabled = true;
document.getElementById('other_location').style.visibility = 'visible';

}*/
}
function change_password() {
	//alert("hello");
	if(document.getElementById('old_password').value =="") {
		alert("Please Eneter Old Password.");
		document.getElementById('old_password').focus();
		return false;
	}
	if(document.getElementById('new_password').value =="") {
		alert("Please Eneter New Password.");
		document.getElementById('new_password').focus();
		return false;
	}
	if(document.getElementById('confirm_password').value =="") {
		alert("Please Eneter Confirm Password.");
		document.getElementById('confirm_password').focus();
		return false;
	}
if(document.getElementById('new_password').value != document.getElementById('confirm_password').value) {	
	alert("Your password and confirm password not match.");
	return false;
}
	
}

function press_room_add_form() {
	//alert("hello");
	if(document.getElementById('news_heading').value =="") {
		alert("Please Enter News Title.");
		document.getElementById('news_heading').focus();
		return false;
	}
	if(document.getElementById('discription').value =="") {
		alert("Please Enter News Discription.");
		document.getElementById('discription').focus();
		return false;
	}
}
function get_citylist(country_name){
if(country_name !='' && country_name !=0) {
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) {
	           document.getElementById('citylist').innerHTML=req.responseText;	
            }
	  }
	             // Prepare request object (automatically choose GET or POST).
            req.open(null, 'ajax.php', true);
           // Send data to backend.
		  req.send( {'countryname':country_name,'onaction':'get_state'} );
	  }
}
function get_locationlist(form){
var country_name = form.property_country.value;
var city_name = form.property_city.value;
				document.getElementById('other_city').value='';
			    document.getElementById('other_city').disabled=true;
				document.getElementById('other_location').value='';
				document.getElementById('other_location').disabled=true;
if(country_name !='' && country_name !=0 && city_name !='' && city_name !=0 && city_name !='Other') {
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) {
	           document.getElementById('locationlist').innerHTML=req.responseText;	
			   
				
            }
	  }
	             // Prepare request object (automatically choose GET or POST).
            req.open(null, 'ajax.php', true);
           // Send data to backend.
		  req.send( {'countryname':country_name,'city_name':city_name,'onaction':'get_location'} );
	  }
else if (city_name =='Other') {
	 document.getElementById('other_city').disabled=false;
	 document.getElementById('other_location').disabled=false;
	 document.getElementById('locationlist').innerHTML= '<select name="location" id="location" class="selectbox" onchange="get_location_other(this.value)" ><option value="0">Area/Location</option><option value="Other" selected="selected">Other</option></select>';
}
}
function get_location_other(value){
	if(value == 'Other') {
		document.getElementById('other_location').disabled=false;
	}
	else {
		document.getElementById('other_location').value='';
		document.getElementById('other_location').disabled=true;
	}
}


function manage_city_get_citylist(country_name){
if(country_name !='' && country_name !=0) {
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) {
	           document.getElementById('citylist').innerHTML=req.responseText;	
            }
	  }
	             // Prepare request object (automatically choose GET or POST).
            req.open(null, 'ajax_country.php', true);
           // Send data to backend.
		  req.send( {'countryname':country_name,'onaction':'get_state'} );
	  }
}

//validation for add location

function city_wise_location_validation() 
{
	//alert("hi");
if(document.getElementById('add_location').value=="") {
	
	alert("Enter City.");
	
	document.getElementById('add_location').focus();
	return false;
}
return true;
}
//validation for add location

function city__validation() 
{
	//alert("hi");
if(document.getElementById('add_city').value=="") {
	
	alert("Enter Location.");
	
	document.getElementById('add_city').focus();
	return false;
}
return true;
}