﻿
$().ready(function() {
	$.fn.themeswitcher && $('<div/>').css({
		position: "absolute",
		right: 10,
		top: 10
	 }).appendTo(document.body).themeswitcher();
	 jQuery.validator.addMethod(
     "selectNone",
     function(value, element) {
     if (element.value == "")
     {
      return false;
     }
    else return true;
  },
  "Please select an option."
);

	// validate the comment form when it is submitted
    // validate signup form on keyup and submit
	$("#FmPyr").validate({
		rules: {
		            PyrSelecttype:"required",
		            prydropstates:"required",
                    prydropcities:"required",
                    PyrSelectbudget:"required",
                    pyrcaptcha:{required:true, digits:true},
		            Pyrphone:{required:true,minlength:10,maxlength:10,digits:true},
			        firstname: "required",
			        lastname: "required",
			        username: {
				                required: true,
				                minlength: 2
			                    },
			        password: {
				        required: true,
				        minlength: 5
			        },
			        confirm_password: {
				        required: true,
				        minlength: 5,
				        equalTo: "#password"
			        },
			        Pyremail: {
				        required: true,
				        email: true
			        },
			        Pyrname:"required",
			        topic: {
				        required: "#newsletter:checked",
				        minlength: 2
			        },
			        Usernamelogin: "required",
			        Passwordlogin:"required"
		},
		messages: {
			        firstname: "Please enter your firstname",
			        lastname: "Please enter your lastname",
			        username: {
				        required: "Required",
				        minlength: "Your username must consist of at least 2 characters"
			        },
			        password: {
				        required: "Required",
				        minlength: "Your password must be at least 5 characters long"
			        },
			        confirm_password: {
				        required: "Required",
				        minlength: "Your password must be at least 5 characters long",
				        equalTo: "Please enter the same password as above"
			        },
			        Pyremail: "Required",
			        agree: "Please accept our policy",
		            pyrcaptcha:{required:"Required",digits:"Enter Only Digits"},
			        Pyrphone:{
			        required:"Required",
			        minlength:"Phone No Cannot be Less Then 10 Digits",
			        maxlength:"Phone No Cannot be More Then 10 Digits",
			        digits:"No Alphabets are Allowed"
			         }
		     },
		      submitHandler: function(form) {
                                       collectpyrdata();
                                       return false;
                                    }
	});
	
	

});

  function collectpyrdata()
{


var pyrdetails="pyr!";


var type=document.getElementsByName('pyrRadioGroup1');
for(k=0;k<type.length;k++)
{
    if(type[k].checked==true)
    {
      pyrdetails+=type[k].value+"!";
       break;
    }
}

var mode=document.getElementsByName('pyrRadioGroup2');
for(h=0;h<type.length;h++)
{
    if(mode[h].checked==true)
    {
      pyrdetails+=mode[h].value+"!";
      break;
    }
}


var propertType=document.getElementById('PyrSelecttype');
for(i=0;i<=propertType.length-1;i++)
{

 if(propertType[i].selected==true)
 {
   pyrdetails+= propertType[i].value+"!";
  break;
  
 }
 
}


var firstname=document.getElementById('PyrTextname').value;
pyrdetails+=firstname+"!";
var email=document.getElementById('PyrTextemail').value;
pyrdetails+=email+"!";
var phone=document.getElementById('PyrTextphone').value;
pyrdetails+=phone+"!";

var budget=document.getElementById('PyrSelectbudget');
for(i=0;i<=budget.length-1;i++)
{
if(budget[i].selected==true)
{
pyrdetails+=budget[i].value+"!";
break;
}
}
var state=document.getElementById('pyrdropstates');
for(i=0;i<=state.length-1;i++)
{
if(state[i].selected==true)
{
pyrdetails+=state[i].value+"!";
break;
}
}

var city=document.getElementById('prydropcities');
for(i=0;i<=city.length-1;i++)
{
if(city[i].selected==true)
{
pyrdetails+=city[i].value;
break;
}
}


 NewCommonAjaxCall(pyrdetails+"!"+document.getElementById('pyrtextcaptcha').value);
}

	
function showpyrdata(name)
{
    if(name=="1")
    {
    
    var ajaxResponse="$Select Residential Type#1$Residential Apartment#2$Independent House/Villa#3$Residential Land#4$Builder Floor#5$Farm House#6$Studio Apartmen#7$Serviced Apartments#8$Others";
     RemoveItems123('PyrSelecttype');
     BindValues123('PyrSelecttype',ajaxResponse);
    }
    else
    {
     var ajaxResponse="$Select Commercial Type#9$Commercial Shops/Showrooms#10$Commercial Land/Inst. Land#11$Office in Business Park#12$Office in IT Park#13$Ware House#14$Cold Storage#15$Factory#16$Manufacturing#17$Business center#18$Industrial Lands/Plots#19$Agricultural/Farm Land#20$Other";
     RemoveItems123('PyrSelecttype');
     BindValues123('PyrSelecttype',ajaxResponse);
    }
}
function BindValues123(OptionId,OptionValue)
    {
       if(document.getElementById(OptionId).length>0)
       {
                var opt = document.getElementById(OptionId);
                var len= opt.length;
                for(i = 0 ; i < len; i++)
                {
                    opt.remove(i);
                }
       }
        var iterate = OptionValue.split('#');
       
        for(i = 0 ;i < iterate.length; i++)
        {
        
          document.getElementById(OptionId).options[i] = new Option(iterate[i].split('$')[1],iterate[i].split('$')[0]);
        }
    }
    
    function RemoveItems123(OptionId)
    {
        var opt = document.getElementById(OptionId);
        if(opt!=null)
        {
            var len= opt.length;
            for(i = 0 ; i < len; i++)
            {
                opt.remove(i);
            }
        }
    }
    function PYRDialog()
    {
            //$('#').val("");
            $('#dialog').dialog('open');
    }
    
     /**********On Change State call Function in Post Your Requirement*********/
     function fillcitiesdropdownlist()
    {
       var cities=document.getElementById('prydropcities');
       var selstates=document.getElementById('pyrdropstates');       
       var selvalue=selstates.options[document.getElementById('pyrdropstates').selectedIndex].value;
       var selcountry="1"//india;
       if(document.getElementById('pyrdropstates').selectedIndex!="0")
       {
         cities[0].text="Loading .......";
         cities.disabled=false;
         
         NewCommonAjaxCall("state$"+selcountry+"$"+selvalue);
     }
    else
        {
         cities.disabled=true;
        }
  
    }
