$(document).ready(function() {
$('#inputBox').focus();
if($('#inputBox').val()!='')
{
  $('#inputBox').val($('#inputBox').val()); 
}
//$('#attendees').numeric();
//$('.location').alpha({allow:" '_-,"});
$('#inputBox').alpha({allow:" '_-,"});
$('#venue').alphanumeric({allow:" '_-,"});
$.metadata.setType("attr", "validate");
$('#detailPageForm').validate({
    errorPlacement: function(error, element) {
        if(element.attr('type') == 'checkbox') {
                     //error.appendTo('#checkerror');
                     $('#checkerror').show();
                     }
                }
            });

$('#newsletterSubscriberForm').validate({
    
        rules: {
                newsletteremail:{
                             required:true,
                             email:true,
                             maxlength:100
                }
            },
        messages: {
                newsletteremail: {
                            required:"Required field cannot be left blank", 
                            email:"Please use correct email format",
                            maxlength:"Email can not greater than 100 characters"
                                                                      
                            }
                    }
    
            });

//$('#fname').alpha();
//$('#lname').alpha();
//$('#city').alpha({allow:" "});
//$('#meeting_city').alpha({allow:" "});
//$('#state').alpha({allow:" "});
//$('#country').alpha({allow:" "});
//$('#meeting_country').alpha({allow:" "});
//$('#phone').alphanumeric();
//$('#postcode').alphanumeric();
$('#no_of_guest_room').alphanumeric();
$('#no_of_attendees').alphanumeric();
$('#meeting_budget').numeric({allow:"."});
$('#listVanueForm').validate({
    
        rules: {
                fname:{
                             required:true,
                             maxlength:50
                },
                lname:{
                             required:true,
                             maxlength:50
                },
                email:{
                             required:true,
                             email:true,
                             maxlength:120
                },
                phone:{
                             required:true,
                             maxlength:15
                },
                full_property_name:{
                             maxlength:200
                },
                company_name:{
                             maxlength:150
                },
                property_address:{
                             maxlength:200
                },
                city:{
                             required:true,
                             maxlength:50
                },
                country:{
                             required:true
                             
                },
                state:{
                             maxlength:50
                },
                postcode:{
                             required:true,
                             maxlength:15
                }
            },
        messages: {
                fname: {
                            required:"Required field cannot be left blank", 
                            maxlength:"First name can not greater than 50 characters"
                                                                      
                            },
                lname: {
                            required:"Required field cannot be left blank", 
                            maxlength:"Last name can not greater than 50 characters"
                                                                      
                },
                email: {
                            required:"Required field cannot be left blank", 
                            email:"Please use correct email format",
                            maxlength:"Email can not greater than 120 characters"
                                                                      
                },
                phone: {
                            required:"Required field cannot be left blank",
                             maxlength:"Phone number can not greater than 15 characters/numbers"
                                                                      
                },
                full_property_name: {
                            maxlength:"Property name can not greater than 200 characters"
                                                                      
                },
                company_name: {
                            maxlength:"Company name can not greater than 150 characters"
                                                                      
                },
                property_address: {
                            maxlength:"Property address can not greater than 200 characters"
                                                                      
                },
                city: {
                            required:"Required field cannot be left blank",
                            maxlength:"City name can not greater than 50 characters"
                                                                      
                },
                country: {
                            required:"Required field cannot be left blank"
                            
                                                                      
                },
                state: {
                            maxlength:"State name can not greater than 50 characters"
                                                                      
                },
                postcode: {
                            required:"Required field cannot be left blank",
                            maxlength:"Postal code can not greater than 15 characters"
                                                                      
                }
            }
    
            });


$('#contactusForm').validate({
    
        rules: {
                fname:{
                             required:true,
                             maxlength:50
                },
                lname:{
                             required:true,
                             maxlength:50
                },
		company_name:{
                             maxlength:150
                },
                email:{
                             required:true,
                             email:true,
                             maxlength:120
                },
                phone_no:{
                             required:true,
                             maxlength:15
                },
                meeting_city:{
                             //required:true,
                             maxlength:50
                },
                meeting_country:{
                            // required:true,
                             maxlength:50
                },
                time_zone:{
                         required:true
                },
		suggestion:{
                            // required:true,
                             maxlength:500
                }
            },
        messages: {
                fname: {
                            required:"Required field cannot be left blank", 
                            maxlength:"First name can not greater than 50 characters"
                                                                      
                            },
                lname: {
                            required:"Required field cannot be left blank", 
                            maxlength:"Last name can not greater than 50 characters"
                                                                      
                },
		company_name: {
                            maxlength:"Company name can not greater than 150 characters"
                                                                      
                },
                email: {
                            required:"Required field cannot be left blank", 
                            email:"Please use correct email format",
                            maxlength:"Email can not greater than 120 characters"
                                                                      
                },
                phone_no: {
                            required:"Required field cannot be left blank",
                             maxlength:"Phone Number can not greater than 15 characters/numbers"
                                                                      
                },
                meeting_city: {
                            required:"Required field cannot be left blank",
                            maxlength:"Meeting city can not greater than 50 characters"
                                                                      
                },
                meeting_country: {
                            required:"Required field cannot be left blank",
                            maxlength:"Meeting country can not greater than 50 characters"
                                                                      
                },
                time_zone:{
                           required:"Required field cannot be left blank"
                },
                suggestion: {
                            maxlength:"Suggestion can not greater than 500 characters"
                                                                      
                }
                
            }
    
    });

$('#newsletteremail').change(function() {
                          var  newsletteremail = $("#newsletteremail").val();
                          if(newsletteremail!='')
                          {
                          $.ajax({
                            type:"POST",
                            cache: false,
                            async: false,
                            url:baseUrl+"/newsletter/emailexist",
                            data:"email="+newsletteremail,
                            success:function(responseText){
                                                    if(responseText.match("exist")){
                                                    $("#emailstatus").val('1');
                                                    }
                                                    else{
                                                        $("#emailstatus").val('0');
                                                     
                                                    }
						    $('#newsletteremail').focus();
                                             
                                       }
                          });
                          }
});
$('#newsletterSubscriberForm').submit(function() {
                          var emailstatus = $("#emailstatus").val();
			                          $('#newsletteremail').focus();
						  if(emailstatus=='1')
						  {
						   $("#emailexistError").html('You have already subscribe to our newsletter.');
						   return false;
						   
						  }
						  else{
						   return true;
						  }
                         
                          
});
$("#amenities_ck").click(function () {
		      //$('#amenities_show').toggle();
		      var srcPath='';
		      if($("#amnt_icon").attr("src")==baseUrl+'/public/images/default/middle_arrow.gif')
		      {
			  srcPath=baseUrl+'/public/images/default/down_arrow.gif';
		      } else {
			  srcPath=baseUrl+'/public/images/default/middle_arrow.gif';
		      }
		      $("#amnt_icon").attr("src", srcPath);
		      $("#amenities_show").toggle("slow");

                             

});

$("#additoinaldoc_ck").click(function () {
		      //$('#amenities_show').toggle();
		      var srcPath='';
		      if($("#doc_icon").attr("src")==baseUrl+'/public/images/default/middle_arrow.gif')
		      {
			  srcPath=baseUrl+'/public/images/default/down_arrow.gif';
		      } else {
			  srcPath=baseUrl+'/public/images/default/middle_arrow.gif';
		      }
		      $("#doc_icon").attr("src", srcPath);
		      $("#doclist_show").toggle("slow");

                             

});
$("#detailRooms_ck").click(function () {
		      //$('#amenities_show').toggle();
		      var srcPath='';
		      if($("#det_icon").attr("src")==baseUrl+'/public/images/default/middle_arrow.gif')
		      {
			  srcPath=baseUrl+'/public/images/default/down_arrow.gif';
		      } else {
			  srcPath=baseUrl+'/public/images/default/middle_arrow.gif';
		      }
		      $("#det_icon").attr("src", srcPath);
		      $("#detailRoom_show").toggle("slow");

                             

});

 $('#listVanueForm').find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
	        $(this).val('');
                break;
            case 'textarea':
            case 'checkbox':
            case 'radio':
               
        }
    });
$('#contactusForm').find(':input').each(function() {
        switch(this.type) {
            case 'text':
	        $(this).val('');
            case 'textarea':
	         $(this).val('');
		  break;
        }
    });
$('#onlyform').find(':input').each(function() {
        switch(this.type) {    
            case 'text':
	        $(this).val('');
            case 'textarea':
	         $(this).val('');
		  break;     
        }
    });


$('#newsletterSubscriberForm').find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
	      $(this).val('');
              break;
            case 'textarea': 
            case 'checkbox':
            case 'radio':
                
        }
    });
                     
});
function validateSearch()
{
    var str=$('#inputBox').val();
    var ven=$('#venue').val();
    var searchText= jQuery.trim(str);
    var Venue= jQuery.trim(ven);

   if(searchText=='' && Venue=='' )
   {
    alert('Search field cannot be left blank.');
    return false;
   }
   /*if(venue=='')
   {
    alert('Attendees field cannot be left blank.');
    return false;
   }*/
   return true;
}
 function submitenter(event,i)
    {
         if (!event)
          event = window.event;
         var code = event.keyCode;

	if(code==27)
	{
	  if(i==1)
	  $('#inputBox').val('');
	  else
	    $('#venue').val('');
	  return false;
	}
         /*  else if (code == 13)
        {
	  if(i==1){
		return false; //this is for Event Location
	  }
	  else{
	    return true; // this is for venue location
	  }
        }*/
        else{
          return true;}
	  
	
    }


function setInMyList(premId)
{
            //$('#mylist_'+premId).fadeOut();       
              loading('mylist_'+premId,'1');
              $.ajax({
              type:"POST",
              cache: false,
              async: false,
              url:baseUrl+"/search/setmylist",
              data:"premid="+premId,
              success:function(responseText){
                       // alert(responseText);
                        loading('mylist_'+premId,'');
                        if(responseText=='max')
                        {
                          $('#mylist_'+premId).html('<span class="button"><input type="submit" onclick="javascript:setInMyList(\''+premId+'\')" value="Add to My List" class=""></span>').show();
                          alert('You may request up to seven RFPs at a time. Please remove a venue before trying to add more.');
                        }
                        else{
                        $('#mylist_'+premId).html('<span class="success already_added aCenter"><img src="'+baseUrl+'/public/images/check.png"></span>').show();
                          //$('#mylist_'+premId).fadeOut(1000)
                           $.ajax({
                                    type:"POST",
                                    cache: false,
                                    async: false,
                                    url:baseUrl+"/search/showmypremiumlist",
                                    success:function(responseText){
                                        //alert(responseText);
                                            $('#showmylistMenu').html(responseText);    
                                    }
                                });
                        }

                                }
            });
              
         }
         
 function removeMyPremiumList(premId)
 {
                $.ajax({
                type:"POST",
                cache: false,
                async: false,
                url:baseUrl+"/search/removepremiumlist",
                data:"premid="+premId,
                success:function(responseText){
                  //$('#show_'+responseText).fadeOut();
                    var temp = new Array();
                    temp = responseText.split('~');
                   
                    if(temp[0]=='empty')
                    {
                      $('#showmylistMenu').html('<span class="errors">Empty My List</span>');
                        $('#mylist_'+temp[1]).html('<span class="button"><input type="submit" onclick="javascript:setInMyList(\''+premId+'\')" value="Add to My List" class=""></span>');
                    }
                    else{
                    $('#show_'+temp[1]).hide();
                    $('#mylist_'+temp[1]).html('<span class="button"><input type="submit" onclick="javascript:setInMyList(\''+premId+'\')" value="Add to My List" class=""></span>');
                    
                    }
              }
            });
    
 }
 
 function removefromMainMyPremiumList(premId)
 {
            var r=confirm("Are you sure you want to delete?");
            if (r==true)
            {
                $.ajax({
                type:"POST",
                cache: false,
                async: false,
                url:baseUrl+"/search/removepremiumlistfrommain",
                data:"premid="+premId,
                success:function(responseText){
                      var temp = new Array();
                    temp = responseText.split('~');
                    if(temp[0]=='empty')
                    {
                      $('#show_mainbox').html('<span class="errors">Your cart is empty</span>');
                    }
                    else{
                    $('#showmylist_'+temp[1]).fadeOut();    
                    }
                 
                    }
                  });
            }
            else
            {
               
            }    
    
 }
 
 function removeListfrommylistpreview(premId)
 {
    
   var r=confirm("Are you sure you want to remove this venue?");

            if (r==true)
            {
		$('#'+premId).remove();
                $.ajax({
                type:"POST",
                cache: false,
                async: false,
                url:baseUrl+"/search/removelistfrommylistpreview",
                data:"premid="+premId,
                success:function(responseText){
                      var temp = new Array();
                    temp = responseText.split('~');
                    if(temp[0]=='empty')
                    {
		      $('#cn_hid').hide();
		      $('#deletemsgshow').html('You have successfully deleted venue.').fadeIn(10);
		      $('#deletemsgshow').fadeOut(10000);
                      $('#show_mainbox').html('<span class="errors">Your cart is empty</span>');
                    }
                    else{
                    $('#showmylist_'+temp[1]).fadeOut();
		    $('#deletemsgshow').html('You have successfully deleted venue.').fadeIn(10);
		    $('#deletemsgshow').fadeOut(10000);

                    }
                 
                    }
                  });
            }
            else
            {
               
            }    
 }
  function showMap(id,name,address)
  { 
	   /*$.ajax({
                type:"POST",
                cache: false,
                async: false,
                url:baseUrl+"/search/showmap",
                data:"name="+name+'&addres='+address,
                success:function(responseText){
                        $('#showmap_'+venderOID).html(responseText).show();   
                    }
                  });*/
	  var id1="showmap_"+id;
	  var id2="div_"+id;
	  var id3="anchor_"+id;
	  var iframeElement = document.getElementById(id1);
	  var iframeshow = document.getElementById(id2);
	  var eventdisable = document.getElementById(id3);
          eventdisable.style.cursor="pointer";
	  iframeshow.style.display="block";
	  iframeElement.src = baseUrl+'/search/showmap?venuename='+name+'&address='+address;
	  //iframeElement.style.border='2px solid #cccccc';
	  var imgurl=baseUrl+'/public/css/images/ifrem_bg.gif';
	  iframeElement.style.background="url("+imgurl+") no-repeat scroll 0 0 transparent";
	  iframeElement.style.padding='2px 2px 16px';
	  iframeElement.style.width = "400px";
	  iframeElement.style.height = "200px";
	  
	
	  //eventdisable.onmouseover = null;   
  }
  function hideMap(id)
  {
	  var id1="showmap_"+id;
	  var id2="div_"+id;
	  var id3="anchor_"+id;
	  var iframeElement = document.getElementById(id1);
	  var iframeshow = document.getElementById(id2);
	  var eventdisable = document.getElementById(id3);
	  
	  eventdisable.style.cursor="default";
	  iframeshow.style.display="none";
	  iframeElement.src='';
	  iframeElement.style.border='';
	  iframeElement.style.width = "0px";
	  iframeElement.style.height = "0px";
	 // iframeElement.style.border = "";
  }


