// JavaScript Document
var currentPageEle = "";
var CNT = "";
var SUB_PRO;
var curr = "";
var nxt = "";
var pre = "";

function getPage(page)
{
	
	$('#page_no').val(page);
	$("#frmnews").submit();
}

function contactus_validate()
{
		
	$(document).ready(function() {
							  
 	$("#flash_msg" ).hide().css({visibility: "hidden", display: "none"});
	$("#frmcontact").validate({							  
	rules: {
     name: "required",
	 company:
	 {
	 	required: true
	 },
	 city:
	 {
	 	required: true
	 },
	 phno:
	 {
		required: true,
	 	digits: true
	 },

     email: {
       required: true,
       email: true
     },
	 code:
		 {
			required: true,
			remote: {
			url: siteurl+"checkcode/",
			type: "post",
			data: {
			  code: function() {
				return $("#code").val();
			  },
			  security_check:function(){
				  return $("#security_check").val();
			  }
			},
			beforeSend   : function(){ 
			}
			}
	
		 }
	},
   messages: {
     name: " Please enter your name.",
	 company:
	 {
	 	required: " Please enter company name."		
	 },
	 city:
	 {
	 	required: " Please enter city name."		
	 },
	 phno:
	 {
		required: " Please enter phone no.",
	 	digits: " Please enter valid phone no."		
	 },
 	email: {
       required: " Email address require.",
       email: " Please enter valid email address."
     },
	 code:
	 {
	 	required: "&nbsp;Please enter security code.",
		remote: "&nbsp;&nbsp;Please Enter valid security code."
	 }

   },
	errorPlacement: function(error, element) { 
  					error.appendTo(element.parent().parent().next().children('td:last').children('label'));
				},  
				
	submitHandler: function() {  
			sendmail();
			}, 
	success: function(label) {
			//$('.valid_success').hide();
 			//label.html("&nbsp;").addClass("valid_small"); 					
			} 
	
    });
	}); 
}

function sendmail()
{
	//alert(siteurl);return false;
	$.ajax({
 	    type: "POST",
		url:siteurl + "sendmail/",
		
		data: {
          name: function() {
			return $("#name").val();
          },
		  company:function(){
			 return $("#company").val();
		  },
          address1: function() {
			return $("#address1").val();
          },
          address2: function() {
			return $("#address2").val();
          },
          city: function() {
			return $("#city").val();
          },
          postcode: function() {
			return $("#postcode").val();
          },
          phno: function() {
			return $("#phno").val();
          },
 		  email:function(){
			  return $("#email").val();
		  },
		  enquiry:function(){
			  return $("#enquiry").val();
		  },
		  subscribe:function(){
			  return $("#subscribe").is(":checked");		
		  }
        },
			
		dataType:'html',
		success:function(data)
		{ 
			//alert("Your Contact Details Sent Successfully.");
			reloadcaptcha();
			$("#flash_msg" ).hide().css({visibility: "visible", display: "block"});
			$("#flash_msg" ).addClass('form_success flash_message');
			$("#flash_msg").html("Your Contact Details Sent Successfully.");
			$("#name").val("");
			$("#company").val("");
			$("#address1").val("");
			$("#address2").val("");
			$("#postcode").val("");
			$("#city").val("");
			$("#phno").val("");
			$("#email").val("");
			$("#enquiry").val("");
			$("#code").val("");
			$("#subscribe").removeAttr("checked");
			$(".valid_small").removeClass("valid_small");
 			$("#flash_msg" ).fadeOut(15000);
			
 
		}		
	});
}

function reloadcaptcha()
{
	$.ajax({
 	    type: "POST",
		url:siteurl + "reloadcode/",
		dataType:'html',
		success:function(data)
		{ 
			d = data.split("<@@>");
			$("#security_check").val(d[0]);
			$('#code_img').attr("src",d[1]);
			
		}		
	});
		
}
function brochure_validate()
{
		
	$(document).ready(function() {
	
	$(".showpdf" ).hide();
 	$("#flash_msg" ).hide().css({visibility: "hidden", display: "none"});
	$("#frmbrochure").validate({							  
	rules: {
		 name: "required",
		 company:
		 {
			required: true
		 },
		 city:
		 {
			required: true
		 },
		 phno:
		 {
			required: true,
			digits: true
		 },
		 email: {
		   required: true,
		   email: true
		 },
		 code:
			 {
				required: true,
				remote: {
				url: siteurl+"checkcode/",
				type: "post",
				data: {
				  code: function() {
					return $("#code").val();
				  },
				  security_check:function(){
					  return $("#security_check").val();
				  }
				},
				beforeSend   : function(){ 
				}
				}
		
			 }
	   },
   messages: {
     name: " Please enter your name.",
	 company:
	 {
	 	required: " Please enter company name."		
	 },
	 city:
	 {
	 	required: " Please enter city name."		
	 },
	 phno:
	 {
		required: " Please enter phone no.",
	 	digits: " Please enter valid phone no."		
	 },
     email: {
       required: " Email address require.",
       email: " Please enter valid email address."
     },
	 code:
	 {
	 	required: "&nbsp;Please enter security code.",
		remote: "&nbsp;&nbsp;Please Enter valid security code."
	 }
   },
	errorPlacement: function(error, element) { 
    					error.appendTo(element.parent().parent().next().children('td:last').children('label'));
				},  
				
	submitHandler: function() {  
			requestbrochure();
			}, 
	success: function(label) {
			//$('.valid_success').hide();
			//label.html("&nbsp;").addClass("valid_small"); 					
			} 
	
    });
	}); 
}

function requestbrochure()
{
	//alert(siteurl);return false;
	$.ajax({
 	    type: "POST",
		url:siteurl + "requestbrochure/",
		
		data: {
          name: function() {
			return $("#name").val();
          },
		  company:function(){
			  return $("#company").val();
		  },
          address1: function() {
			return $("#address1").val();
          },
          address2: function() {
			return $("#address2").val();
          },
          city: function() {
			return $("#city").val();
          },
          postcode: function() {
			return $("#postcode").val();
          },
          phno: function() {
			return $("#phno").val();
          },
 		  email:function(){
			  return $("#email").val();
		  }
        },
			
		dataType:'html',
		success:function(data)
		{ 
			reloadcaptcha();
			//alert("Your Request for Robena Brochure is Sent Successfully.");
			$("#flash_msg" ).hide().css({visibility: "visible", display: "block"});
			$("#flash_msg" ).addClass('form_success flash_message');
 			$("#flash_msg").html("Your Request for Robena Brochure is Sent Successfully.");
			$("#name").val("");
			$("#company").val("");
			$("#address1").val("");
			$("#address2").val("");
			$("#postcode").val("");
			$("#city").val("");
			$("#phno").val("");
			$("#email").val("");
			$("#code").val("");
			$(".valid_small").removeClass("valid_small");
			$("#flash_msg" ).fadeOut(15000);
  
		},
/*		error: function(e){
			
			$("#flash_msg" ).hide().css({visibility: "visible", display: "block"});
			$("#flash_msg" ).addClass('form_error flash_message');
			$("#flash_msg").html("Error in sending a mail.");
			$("#name").val("");
			$("#company").val("");
			$("#address1").val("");
			$("#address2").val("");
			$("#postcode").val("");
			$("#city").val("");
			$("#phno").val("");
			$("#email").val("");
			$(".valid_small").removeClass("valid_small");
		}
*/	});

}


function showProject(element,id)
{
	
 	currentPageEle = element;
 	$.ajax({
 	    type: "POST",
		url:siteurl + "getproject/",
 		data: {
			  proid: function() 
			  {
					return id;
			  }
        },
 		dataType:'json',
		success:function(data)
		{ 
			SUB_PRO = data['inner']; 
			CNT = data['innercnt'];
			$('#content1 a').removeClass('active');
			$("#"+currentPageEle).addClass('active');
 			$('.mainproject').hide();
			$('#inner_content').hide();
			$('.recentpro').hide();
			$('.boxes').hide();
			$('#carousel').hide();
			$('#Default_banner').show();
			$('#bannerback').show();
			$('#bannerheader').show();
			if(data['sub']){
   				$('#recent_projects').show();
				$('.archive').show();
			}else{
				$('#recent_projects').hide();
				$('.archive').hide();
			}
			$('.projectdetail').show();
			$('.projectdetail').html(data['main']['description']);
			$('#bannerback').show();
			$('#bannerheader').show();
			$Ban_image = data['main']['banner'].split('|||');
			$('#banner img').attr('src',function(){
							   return imagepath+$Ban_image[0];
							   });
			if(data['main']['image']){
				$('#bannerheader').html(data['main']['title']);
			}else{
				$('#bannerheader').hide();
				$('#bannerback').hide();
			}
			$('.recentproject ul').html('');
			
			if(data['sub'] != undefined)
			{
				$('.recentproject ul').html(data['sub']);
				$('.projectdetail').hide();
			}
			
			
		}		
	});
}


function showProduct(element,id) 
{
		
		currentPageEle = element;
   		$.ajax({
 				 type: "POST",
				 url:siteurl + "product/id/"+id,
				 dataType:'json',
				 success:function(data)
				 {	
				 	//alert(data);
					$("#TitleBackground").show();
				 	$('#procontent a').removeClass('active');
 					$('#'+currentPageEle).addClass('active');
					$("#prodDescription" ).show();
 					$("#prodDescription" ).html(data['val']['description']);
					if(data['val']['banner'] != ''){
						var banner_details = data['val']['banner'].split('|||');
					}
 					var banner_image = '';
 					for(img in banner_details)
					{
						//alert(img+" => "+banner_details);
						banner_image = banner_details[img].replace(/,/gi,"");
						if(banner_image != ''){
							$("#rightcontent img").attr('src',function() { 
										return imagepath+banner_image;
							});
						}
					}
					if(data['val']['banner_title'] != ''){
						var banner_title_details= data['val']['banner_title'].split('||');
					}
					//alert(banner_title_details);
					if(banner_title_details ==','){
						$("#TitleBackground").hide();
					}
  					var banner_title = '';
 					for(img in banner_title_details)
					{
						//alert(img+" => "+banner_title_details);
						//alert(banner_title_details[img]);
						if(banner_title_details[img] != ''){
							banner_title = banner_title_details[img].replace(/,/gi,"");
  							$("#Banner_Title").html(banner_title);
						}
 					}
					$(".boxes").hide();
					$("#defaultcontent").hide();
					
				}
			   
		});
}

function showPages(element,id) 
{
		$('.head3 a').removeClass('active');
 		$(element).addClass('active');
   		$.ajax({
 				 type: "POST",
				 url:siteurl + "history/id/"+id,
				 dataType:'json',
				 success:function(data)
				 {	
				 	$(".boxes").hide();
					$('#defaultcontent').hide();
				 	$('#AboutPage'+id).addClass('active');
					$('#abtuscontent').show();
					$('#abtuscontent').html(data['page_description']);
				 	var  page_image = imagepath+data['banner'];
					
					if(data['banner'] != ''){
						var banner_details = data['banner'].split('|||');
					}
 					var banner_image = '';
 					for(img in banner_details)
					{
						//alert(img+" => "+banner_details);
						banner_image = banner_details[img].replace(/,/gi,"");
						if(banner_image != ''){
							$("#rightcontent img").attr('src',function() { 
										return imagepath+banner_image;
							});
						}
					}
 					
				}
			   
		});
 	
}

function innerBannerScript()
{
		$('#ft-title-example, .ft-example').remove();
		$('#carousel').jqFancyTransitions({ width: 600, height: 495, delay: 6000, position: 'top', direction: 'random' });
}

function showProjectDetail(id)
{
		
 	$.ajax({
 	    type: "POST",
		url:siteurl + "getprojectdetail/",
 		data: {
			  proid: function() 
			  {
					return id;
			  }
        },
 		dataType:'json',
		success:function(data)
		{ 
			var banner_details = '';
			setNextPrevious(data['project_id']);
			$('#carousel').html('');
			//$("#BannerScript").html('');
			$('#content1 a').removeClass('active');
			$("#"+currentPageEle).addClass('active');
 			$('.mainproject').hide();
			$('.projectdetail').hide();
			$('.archive').hide();
   			$('#recent_projects').hide();
			$('.boxes').hide();
			$('#inner_content').show();
			$('.header').html(data['title']);
 			if(data['banner'] != ''){
				var banner_details = data['banner'].split('|||');
			}
			
			var banner_image = '';
			//alert(banner_details.length);
			
			if(banner_details.length > 0){
				
				/*var imageDiv = '<div id="BannerScript" style="display:block;"><ul style="width:618px; height:356px;">';*/
				var imageDiv = '<div id="BannerScript" style="display:none;">';
				
				for(var k=0; k <banner_details.length; k++){
						//alert(k+" => "+banner_details[k]);
					
					banner_image = banner_details[k];
					if(banner_image != ''){
						/*$("#banner img").attr('src',function() { 
									return imagepath+banner_image;
						});*/
						
						$('#carousel').show();
						$('#Default_banner').hide();
						$('#bannerback').hide();
						$('#bannerheader').hide();
						
						//$('.jqb_bar').hide();
 						
						//imageDiv += "<div class='jqb_slide' title=''><a href='#'><img src='"+imagepath+banner_image+"' title='' alt=''/></a></div>";
						
						/*imageDiv += "<li><img alt='' src='"+imagepath+banner_image+"' /></li>";*/
						imageDiv += "<img alt='' src='"+imagepath+banner_image+"' />";
						//alert(imageDiv);
						 
					}
				}
				
				/*imageDiv += "</ul></div>";	*/
				imageDiv += "</div>";	
				/* var Scripthtml = "<script> $(function(){	$('#BannerScript').infiniteCarousel({ displayTime: 6000, textholderHeight : .25 }); }); </script> ";*/
				  var Scripthtml = "<script> $(function(){ $('#carousel').jqFancyTransitions({ width: 600, height: 495, delay: 6000, position: 'top', direction: 'random' }); }); </script> ";
				//$('#carousel').html(imageDiv+Scripthtml);

				$('#carousel').html(imageDiv);
				innerBannerScript();
			
			
			}else{
				
				var imageDiv = "";
				//alert(imagepath);
				$('#carousel').hide();
				$('#Default_banner').show();
				$('#Default_banner').attr('src',function() { 
								return imagepath+"coming_soon.png";
					});
				imageDiv += '<div id="BannerScript" style="display:block;"><ul style="width:618px; height:356px;"><li></li></ul></div>';
				$('#carousel').html(imageDiv);
			}
			
			$('.projectdesc').html(data['description']);
			//alert(data);
			
			//alert(banner_details.length);
/*			var banner_image = '';
			for(img in banner_details)
			{
				//alert(img+" => "+banner_details);
				banner_image = banner_details[img].replace(/,/gi,"");
				if(banner_image != ''){
					/*$("#banner img").attr('src',function() { 
								return imagepath+banner_image;
					});
					
 				}
			}
*/			
			$('#smallimage img').attr('src',function(){
							   return imagepath+data['s_image'];
							   });
			$('#bannerback').hide();
			$('#bannerheader').hide();
			var mainproid = data['project_id'];
			if(nxt != ''){
				$('#nextbtn').show();
				$('#nextbtn a').attr('href',function(){
							   return "javascript:showProjectDetail('"+nxt+"')";
							   });
			}else{
				$('#nextbtn').hide();
			}
			if(pre != ''){
				$('#backbtn').show();
				$('#backbtn a').attr('href',function(){
							   return "javascript:showProjectDetail('"+pre+"')";
							   });
			}else
			{
				$('#backbtn').hide();
 			}
			
		   /*var test_str = '<script>var jqb_vCurrent = 0; var jqb_vTotal = 0; var jqb_vDuration = 15000; var jqb_intInterval = 0; var jqb_vGo = 1; var jqb_vIsPause = false; var jqb_tmp = 20; var jqb_title; var jqb_imgW = 600; var jqb_imgH = 495; </script><script>$(document).ready(function() {	jqb_vTotal = $(".jqb_slides").children().size() -1; $(".jqb_info").text($(".jqb_slide").attr("title"));	 jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration); $("#jqb_object").find(".jqb_slide").each(function(i) { jqb_tmp = ((i - 1)*jqb_imgW) - ((jqb_vCurrent -1)*jqb_imgW); $(this).animate({"left": jqb_tmp+"px"}, "slow");});    });</script>';*/
		
		 
  		}		
	});
}


 function setNextPrevious(id)
{
	for(i in SUB_PRO)
			{
				//alert(SUB_PRO[i]['project_id']);
				j = parseInt(i)+1;
				k = parseInt(i)-1;
				//alert(SUB_PRO[i]['project_id'] +" == "+data['project_id']);
				if(SUB_PRO[i]['project_id'] == id )
				{
					if(i != 0)
					{
						if(SUB_PRO[k]['project_id'] != null)
						{
							pre = SUB_PRO[k]['project_id'];
						}
						else
						{
							pre = "";
						}
					}else{
						pre = "";	
					}
					if(CNT != j)
					{
						if(SUB_PRO[j]['project_id'] != null)
						{
							
							nxt = SUB_PRO[j]['project_id'];
						}
						else
 						{
							nxt = "";
						}
					}else{
						nxt = "";	
					}
					break;
				}
			}	
}

function gotoProject(id)
{
	window.location = "http://localhost/robena/project/";
	//alert(showProject('projectlist'+parseInt(id)-1,id));
	
}




function showuserdialog()
{
	//$.noConflict();
	$( ".ui-dialog-titlebar" ).each(function(){

			if( $(this).parent().html().indexOf('loading') >0)
			{
				$(this).remove();	
			}
      });
	$( "#dialogLoading" ).dialog( "open" ); 
	
}

function userdialog(boxtitle,msg,button,functionname,data)
	 {
		 try{
		 
		 	$( "#dialog" ).dialog( "option", "title", boxtitle );
			$( "#dialog" ).dialog( "option", "zIndex", 999999 );
			$( "#dialog" ).dialog( "option", "position", ['','100'] );
			$( "#dialog" ).dialog( "open" );
			document.getElementById('dialog_msg').innerHTML=msg;
			 
			var buttons = $( ".selector" ).dialog( "option", "buttons" );
		
		//setter
			$( "#dialog" ).dialog( "option", "buttons", [
				{
					text: "Ok",
					click: function() {
						if (button==100)
						{
							 functionname(); 
						}
						$(this).dialog("close"); }
				}
			] );
			
			if (button==1)
			{
				$( "#dialog" ).dialog( "option", "buttons", [
					{
						text: "Yes",
						click: function() {  
							try{
								data=data.split('^^^^');
							}catch(err){}
							
							functionname(data); 
							$(this).dialog("close"); return true; 
						}
					},
					{
						text: "No",
						click: function() { $(this).dialog("close");return false; }
					}
				] )
			}
			
		 }catch(Err)
		 {
			alert(msg,"",boxtitle);
		}
				//$( "#dialog" ).dialog( "option", "position", [0,100] );
			// $( "#dialog" ).notify("This dialog will stay");
			
			return false;
 	}
function hideuserdialog()
{
	$( "#dialogLoading" ).dialog( "close" );
}
