Ext.BLANK_IMAGE_URL = '../../images/resources/images/default/s.gif';

var URL = location.href

function queryString(Deger) {
  if(Deger!=null) {
    var regEx = new RegExp("(\\?|&)("+Deger+"=)(.*?)(&|$|#)","i")
    var exec = regEx.exec(URL)
    var Sonuc = RegExp.$3
  } else {
    var regEx = new RegExp("(\\?)(.*?)($)","i")
    var exec = regEx.exec(URL)
    var Sonuc = RegExp.$2
  }

  return(Sonuc)
}

var	main = function(){
	return {
		init : function(){
			 Ext.QuickTips.init();
		     Ext.form.Field.prototype.msgTarget = 'side';

			contacts.init();
			
		}
	}
}();

var contacts = function() {
var tabs;

	return {
		init:function() {
		
		var contactForm = new Ext.FormPanel({
			frame:false,
			labelAlign: 'left',
			waitMsgTarget: true,
			url: 'common.php',
			items:[{
				xtype:"fieldset",
				title:"E-Mail",
				collapsible:false,
				labelWidth:150,
				autoHeight:true,
				items:[{
					xtype:"textfield",
					fieldLabel:"Company Name",
					name:"company",
					width:250
				  },{
					xtype:"textfield",
					fieldLabel:"Name",
					name:"fullname",
					allowBlank:false,
					width:250
				  },{
					xtype:"textfield",
					vtype:'email',
					fieldLabel:"E-Mail",
					name:"email",
					allowBlank:false,
					width:250
				  }]
			  },{
				xtype:"fieldset",
				title:"Message",
				collapsible:true,
				hideLabels:true,
				autoHeight:true,
				items:[{
					xtype:"textarea",
					name:"message",
					height:200,
					allowBlank:false,
					width:'98%'
				  }]
			  }]
			});
		
		// explicit add
			contactForm.addButton(('SEND'), function(){
            if (contactForm.getForm().isValid()) {
					contactForm.getForm().submit({
						params: { ctrl:'sendmail' },
						waitMsg:'Message Sending...',
						success: function ( result, request ) {
							document.getElementById('tab2').innerHTML = '<div style="height:250px"><b>Message Send Success...</b></div>';
						},
						failure: function ( result, request ) { 
							Ext.MessageBox.alert( 'SERVER ERROR', 'Error Mail Sender!' ); 
						} 
					});
            }else{
                Ext.MessageBox.alert('ERROR', 'Fill to all required fields...');
            }
        }, contactForm);
			
    	contactForm.addButton('RESET',function(){ contactForm.getForm().reset(); });
		
		
		contactForm.render('tab2');
		
		
			tabs = new Ext.TabPanel({
				renderTo:'tabs',
				activeTab: 0,
				frame:false,
				plain:true,
				width:450,
				defaults:{autoHeight: true},
				items:[
					{contentEl:'tab1', title: 'Location Info'},
					{contentEl:'tab2', title: 'E-Mail'}
				]
			});

		gmap.show();
		} // end init
		
		,setTab:function() {
			tabs.setActiveTab(0);	
		}
	} // end return
}(); //end details

var gmap = function() {
	
var gmarkers = [];
var htmls = [];

	return {
		show:function() {
			 if (GBrowserIsCompatible()) {
				  var Icon = new GIcon(G_DEFAULT_ICON);
				  Icon.image = "../images/tema/coldmarker.png";
				  //Icon.shadow = "../images/tema/coldmarkerSH.png"; 
				  //Icon.iconSize = new GSize(48, 70); 
				   //Icon.shadowSize = new GSize(37, 67); 
				   //Icon.iconAnchor=new GPoint(35,60);
				   //Icon.infoWindowAnchor=new GPoint(60,0);
				  // A function to create the marker and set up the event window
				  function createMarker(id,point,name,html) {
					var marker = new GMarker(point,Icon);
					GEvent.addListener(marker, "click", function() {
					  marker.openInfoWindowHtml(html);
					});
			
					// Switch icon on marker mouseover and mouseout
					GEvent.addListener(marker, "mouseover", function() {
					  marker.setImage("../images/tema/marker.png");
					});
					GEvent.addListener(marker, "mouseout", function() {
					  marker.setImage("../images/tema/coldmarker.png");
					});
					gmarkers[id] = marker;
					htmls[id] = html;

					return marker;
				  }
				  
				  // create the map
				  var map = new GMap2(document.getElementById("map"));
				  map.addControl(new GLargeMapControl());
				  map.addControl(new GMapTypeControl());
				  map.setCenter(new GLatLng(40.9855 , 28.8311),14);
			
				  // Read the data from example.xml
				  var request = GXmlHttp.create();
				  request.open("GET", "contactmaps.xml", true);
				  request.onreadystatechange = function() {
					if (request.readyState == 4) {
					  var xmlDoc = GXml.parse(request.responseText);
					  // obtain the array of markers and loop through it
					  var markers = xmlDoc.documentElement.getElementsByTagName("marker");
					  
					  for (var i = 0; i < markers.length; i++) {
						// obtain the attribues of each marker
						var lat = parseFloat(markers[i].getAttribute("lat"));
						var lng = parseFloat(markers[i].getAttribute("lng"));
						var point = new GLatLng(lat,lng);
						var html = markers[i].getAttribute("html");
						var label = markers[i].getAttribute("label");
						// create the marker
						var marker = createMarker(i,point,label,html);
						map.addOverlay(marker);
					  }
					  // put the assembled side_bar_html contents into the side_bar div
					  //document.getElementById("side_bar").innerHTML = side_bar_html;
					}
				  }
				  request.send(null);
				}
			
				else {
				  alert("Sorry, the Google Maps API is not compatible with this browser");
				}
		} // end init
		
		, goMap:function(id) {// This function picks up the click and opens the corresponding info window
			contacts.setTab();
			gmarkers[id].openInfoWindowHtml(htmls[id]);
		} // end goMap
		, mapOver:function(id) {// This function picks up the click and opens the corresponding info window
			gmarkers[id].setImage('../images/tema/marker.png');
		} // end goMap
		, mapOut:function(id) {// This function picks up the click and opens the corresponding info window
			gmarkers[id].setImage('../images/tema/coldmarker.png');
		} // end goMap
	}
}(); //end gmap

Ext.EventManager.onDocumentReady(main.init, main, true);
