/**
 * @author neil.grimes
 */


function createMarker(point,html) {
    var marker = new GMarker(point);
    
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
    return marker;
}

function loadContactUsGoogleMap() {

    if (GBrowserIsCompatible()) {
        
		var map = new GMap2(document.getElementById("map"));
        
		map.setCenter(new GLatLng(54.168627,-6.334434), 15);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
		var point1 = new GLatLng(54.168627,-6.334434);
		
		/* marker1 will be the pop up listing and address of the company */
        var marker1 = createMarker(point1,'<table width=248><tr><th>InterTradeIreland</th></tr><tr><td>The Trade and Business Development Body</td></tr><tr><td>The Old Gasworks Business Park,</td></tr><tr><td>Kilmorey St, Newry</td></tr><tr><td>Co Down, BT34 2DE.</td></tr></table><br /><table cellpadding="2" cellspacing="2"><tr><td class="bold">Tel : </td><td>028 30834100 (048 from Ireland)</td></tr><tr><td class="bold">Textphone : </td><td>028 30834169 (048 from Ireland)</td></tr><tr><td class="bold">Fax : </td><td>028 30834155 (048 from Ireland)</td></tr><tr><td class="bold">Email : </td><td><a href="mailto:info@intertradeireland.com">info@intertradeireland.com</a></td></tr></table>');
        
		map.addOverlay(marker1);
    }
}

function setClassById(id, style) {
    var obj;

    if ((obj = findObj(id)) != null) {
        setClass(obj, style);
    }
}

/**
 * Set the css class of an object
 */
function setClass(src, name) {
    src.className = name;
}

function showLayer(layer) {
    if (layer == 'addressLayer') {
        setClassById('addressLayer', 'shown');
		setClassById('mapLayer', 'hidden');
    } else {
        setClassById('mapLayer', 'shown');
        setClassById('addressLayer', 'hidden');
    }
}   

/* search the dom for the object */
function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) {
    x=d.all[n];
  }
  for (i=0;!x&&i<d.forms.length;i++) {
    x=d.forms[i][n];
  }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
    x=findObj(n,d.layers[i].document);
  }
  if(!x && d.getElementById) {
    x=d.getElementById(n);
  }
  // alert('object ' + n + ' is ' + x);
  return x;
}

function checkContactForm(){
	
	var emailRegex = /^.+\@.+\..+$/;
	missinginfo = "";

	if (document.form.txtname.value == "") {
	    missinginfo += "\n     -  Your Name";
	}
	
    if (document.form.txtAddress.value == "" && document.form.txtEmail.value == "" && document.form.txtTel.value == "") {
		missinginfo += "\n     -  Your must supply one of the following : ";
		missinginfo += "\n          an Address or"
		missinginfo += "\n          an Email Address or"
		missinginfo += "\n          a Telephone Number"
	} else {
		if (document.form.txtEmail.value != "") {
		
			value = document.form.txtEmail.value;
			
			if (!emailRegex.test(value)) {
				missinginfo += "\n     -  Your Email Address is not of the correct format";
				missinginfo += "\n           e.g.    example@example.com";
			}
		}
	}
	
	if (document.form.selNature.value == "") {
	    missinginfo += "\n     -  Your Nature of Business";
	}
	
	if (document.form.txtareaComments.value == "") {
	    missinginfo += "\n     -  Your Comments";
	}
	
	if (missinginfo != "") {
	    missinginfo ="_____________________________\n" +
	    "The following errors exist on the form :\n" +
	    missinginfo + "\n_____________________________" +
	    "\nPlease re-enter and submit again!";
	    
	    alert(missinginfo);
	    return false;
	}
	    else return true;
	}	

	
