// JavaScript Document

function load() {
	startBlink();
	var t = document.getElementsByTagName('title')[0];
	if (t.innerHTML == "Gracious Image -- Contact Us")
		initialize();
}

function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i < blink.length; i++)
    	blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
	if (document.all)
    	setInterval("doBlink()",1000)
}

function initialize() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(1.2874885761801003, 103.84184002876282), 17);
 
		map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        // Add 10 markers to the map at random locations
		var point = new GLatLng(1.2874885761801003, 103.84184002876282);
		map.addOverlay(new GMarker(point));
	}
}

function mouseOver(name) {
	document.getElementById('img' + name).src = "images/templates/" + name + "S.png";
}
function mouseOut(name) {
	document.getElementById('img' + name).src = "images/templates/" + name + ".png";
}

function displayFabrics(name) {
	document.getElementById('showcase').src = "images/fabrics/" + name + "_b.jpg";
}

function displayBlinds(name) {
	document.getElementById('showcase').src = "images/blinds/" + name + "_b.jpg";
}

function displayCurtains(name) {
	document.getElementById('showcase').src = "images/curtains/" + name + "_b.jpg";
}

function displayMotorized(name) {
	document.getElementById('showcase').src = "images/motorized/" + name + "_b.jpg";
}

function displayCarpets(name) {
	document.getElementById('showcase').src = "images/carpets/" + name + "_b.jpg";
}

function displayWallpapers(name) {
	document.getElementById('showcase').src = "images/wallpapers/" + name + "_b.jpg";
}

function resetDisplay() {
	document.getElementById('showcase').src = "images/showcase/blank.png";
	document.getElementById('showcasetxt').innerHTML = "";
}

function changelabel(){
 
if (document.getElementById("overseasCheckBox").checked)
{
	document.getElementById("city").disabled=false;
	document.getElementById("city").value="";
	document.getElementById("country").disabled=false;
}
else
{
	document.getElementById("city").disabled=true;
	document.getElementById("city").value="Singapore";
	document.getElementById("country").disabled=true;
	document.getElementById("country").options[0].text="Singapore";
	document.getElementById("country").options[0].selected=true;
}
	
  }
  
function checkFields(emailStr) {      

missinginfo = "";
if (document.getElementById("txtCustName").value == "") {
missinginfo += "\n     -  Name";

}

if (document.getElementById("txtCustContactNo").value == "") {
missinginfo += "\n     -  Mobile No";
}


if (!(document.getElementById("txtCustEmail").value == "") && 
((document.getElementById("txtCustEmail").value.indexOf('@') == -1) || 
(document.getElementById("txtCustEmail").value.indexOf('.') == -1))) {
missinginfo += "\n     -  Valid Email Address";
}



if (document.getElementById("enquiry").value == "") {
missinginfo += "\n     -  Enquiry";
}


if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"The following fileds are compulsory:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again.\n";
alert(missinginfo);
return false;
}

return true;

}

function checkFields2(emailStr) {      

missinginfo = "";
if (document.getElementById("txtCustName").value == "") {
missinginfo += "\n     -  Name";

}

if (document.getElementById("txtCustContactNo").value == "") {
missinginfo += "\n     -  Mobile No";
}


if (!(document.getElementById("txtCustEmail").value == "") && 
((document.getElementById("txtCustEmail").value.indexOf('@') == -1) || 
(document.getElementById("txtCustEmail").value.indexOf('.') == -1))) {
missinginfo += "\n     -  Valid Email Address";
}


if (document.getElementById("enquiry").value == "") {
missinginfo += "\n     -  Enquiry";
}


if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"The following fileds are compulsory:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again.\n";

alert(missinginfo);
return false;
}

return true;

}

function checkFields3() {      

missinginfo = "";
if (document.getElementById("txtCustName").value == "") {
missinginfo += "\n     -  Friend's Name";

}

if (document.getElementById("txtCustContactNo").value == "") {
missinginfo += "\n     -  Friend's Contact";
}


if (document.getElementById("txtRefName").value == "") {
missinginfo += "\n     -  Referral's Name";
}
if (document.getElementById("txtRefNo").value == "") {
missinginfo += "\n     -  Referral's Contact";
}

if (document.getElementById("enquiry").value == "") {
missinginfo += "\n     -  Enquiry";
}


if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"The following fileds are compulsory:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again.\n";
alert(missinginfo);
return false;
}

return true;

}
function enquiry()
{ 
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (div=="EnquiryMessage")
			document.getElementById('EnquiryMessage').innerHTML = ajaxRequest.responseText;
			else{
			document.getElementById('EnquiryMessage').innerHTML = "";
		
			document.getElementById('EnquiryForm').innerHTML = ajaxRequest.responseText;
			}
		}
	}
	var div= "EnquiryForm";
	var AddressFlag = true ;
	var enquiryFlag =true ;
	if (!document.EnquiryForm.AddressType[0].checked && !document.EnquiryForm.AddressType[1].checked  ) {
       AddressFlag =false;
    }
	if (!document.EnquiryForm.enquiryType[0].checked && !document.EnquiryForm.enquiryType[1].checked && !document.EnquiryForm.enquiryType[2].checked  ) {
       enquiryFlag =false;
    }
	if (AddressFlag==false || enquiryFlag==false){
	var queryString = "?AddressFlag=" + AddressFlag + "&enquiryFlag=" + enquiryFlag ;
	var div ="EnquiryMessage";
	ajaxRequest.open("GET", "checkEnquiry.php" + queryString, true);
	}
	else
	{
		var Magazines='',Advertisements='',Friends='';
		
		if (document.getElementById('Magazines').checked)
	        Magazines= document.getElementById('Magazines').value;
		if (document.getElementById('Advertisements').checked)
	       Advertisements =document.getElementById('Advertisements').value;
	    if (document.getElementById('Friends').checked)
	       Friends =document.getElementById('Friends').value;
		   var queryString = "?AddressFlag=" + AddressFlag + "&enquiryFlag=" + enquiryFlag ;
	    queryString += "&Magazines=" + Magazines + "&Advertisements=" + Advertisements + "&Friends=" + Friends ;
		if (document.EnquiryForm.AddressType[0].checked && document.EnquiryForm.enquiryType[0].checked){
			var AddressType = 'local';
			var EnquiryType= 'new';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		   }
	    if (document.EnquiryForm.AddressType[0].checked && document.EnquiryForm.enquiryType[1].checked){
			var AddressType = 'local';
			var EnquiryType= 'exist';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		   }
		
		if (document.EnquiryForm.AddressType[0].checked && document.EnquiryForm.enquiryType[2].checked){
			var AddressType = 'local';
			var EnquiryType= 'refer';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		}
		if (document.EnquiryForm.AddressType[1].checked && document.EnquiryForm.enquiryType[0].checked){
			var AddressType = 'overseas';
			var EnquiryType= 'new';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		}
		if (document.EnquiryForm.AddressType[1].checked && document.EnquiryForm.enquiryType[1].checked){
			var AddressType = 'overseas';
			var EnquiryType= 'exist';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		}
		if (document.EnquiryForm.AddressType[1].checked && document.EnquiryForm.enquiryType[2].checked){
			var AddressType = 'overseas';
			var EnquiryType= 'refer';
			queryString +=  "&AddressType=" + AddressType + "&EnquiryType=" + EnquiryType
	       ajaxRequest.open("GET", "checkEnquiry.php" + queryString , true);
		}
	
	}
	
	
	ajaxRequest.send(null); 
	
	
	
	
}
//-->