var xml = null;

function initialize(xmlPath){
	if(xmlPath != null && xmlPath != ''){
		$(document).ready(function(){		   
			$.ajax({
				url: xmlPath,
				dataType: ($.browser.msie)?'string':'xml',
				success: function(xmlDoc){
					if($.browser.msie){
                    xml = new ActiveXObject("Microsoft.XMLDOM");
                    xml.async = false;
                    xml.loadXML(xmlDoc);
                 	}else
						xml = xmlDoc;
				},
				cache: false,
				async: false
			});
		});
	}else
		alert("XML Path Error");
}

/* return array of company name in String */
function getAllCompanys(){
	var companyName = new Array();
	if(xml != null)
		companyName = $(xml).find("companyName")
	return companyName;
}

/* return hash table with key = item name, value = item value */
function getAllItems(companyName){
	var items = new Array();
	if(xml != null){
		$(xml).find("company").each(function(i){
			if($(this).find("companyName").text() == companyName){
				$(this).find("item").each(function(i){
					items[$(this).find("name").text()] = $(this).find("value").text();
				});
			}
		})
	}
	return items;
}


function initStatisticRecord(companyName){

	tempHTML = '<iframe width="200" height="700" frameborder="0" scrolling="no" src="../xml/fetchXML.php?name=' + companyName + '"></iframe>';
	
	document.getElementById('statisticRecordArea').innerHTML = tempHTML;
	
}

function sendmail(){
	document.getElementById('mailmsg').className = "msg_box";
	document.getElementById('mailmsg').innerHTML = "Your enquiry is under procesing...";
	var to_email = document.getElementById('to_email').value;
	var title = document.getElementById('title').value;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var subject = document.getElementById('subject').value;
	var enquiry = document.getElementById('enquiry').value;
	if(to_email != '' && title != '' && name != '' && email != '' && subject != '' && enquiry != ''){
		$.post(
			   "../lib/sendmail.php", 
			   { 
					to_email: to_email,
					title: title,
					name: name,
					email: email,
					subject: subject,
					enquiry: enquiry
				},
			   function(data){
				   document.getElementById('mailmsg').innerHTML = data;
 			   }
			);
	}else
		document.getElementById('mailmsg').innerHTML = "There are some problems with your input, please check your input then send the enquiry again.";
}
