/*! Copyright (c) 2011 Azliana Ismail (http://www.sota.travel)
*
* Version: 1.0.0
*
*/

window.onload = function() {
	var pkg_ids = document.getElementsByName("package_id");
	var rate_ids = document.getElementsByName("rate_id");
	var api = document.getElementById("api_key");
	for (x = 0; x < rate_ids.length; x++) {
		var form = document.createElement("form");
		with (form) {
			setAttribute("name", "form"+x); // give form a name
			setAttribute("action", "javascript:void(0)"); // give form an action
			setAttribute("method", "post"); // give form a method
			setAttribute("target", "new");
		}
		form.onsubmit = function(){ //handle form submit with a message
			//alert(this.elements[0].value);
			var objFrame=document.getElementById("sota_frame");
			var hn = window.location.hostname;
			var vtf = document.location.href;
			var path = window.location.pathname.split( '/' );
			
			//alert(path[1]);
			
			//detect production or staging
			if (hn == "124.150.142.162" || vtf =="http://allmalaysia.info/vtf-test/" || path[1] == "vtf-test") {
				var host = "http://124.150.142.162/enquiry/";
			}else if(hn == "192.168.1.118"){
				var host = "http://192.168.1.118/enquiry/";
			}
			else {
				var host = "https://enquiry.sota.travel/";
			}
			//alert(this.elements[1].value);
			//for single rate package
			if (this.elements[1].value != ""){
				objFrame.src = host + "index.cfm?var_dir=index&api_id=" + api.value + "&package_id=" + this.elements[0].value + "&package_rate_id=" + this.elements[1].value;
			}else{
				objFrame.src = host + "index.cfm?var_dir=index&api_id=" + api.value + "&package_id=" + this.elements[0].value;
			}
			//alert(objFrame.src);
			document.getElementById('light').style.display = 'block';
			document.getElementById('fade').style.display = 'block'
			return false;
		}
		var package_id = document.createElement("input"); // create an input element
		with (package_id) {
			setAttribute("name", "p_id"+x); // give input a name
			setAttribute("type", "hidden"); // make it a submit button
			setAttribute("value", pkg_ids[x].value); // give input a value
		}
		var rate_id = document.createElement("input"); // create an input element
		with (rate_id) {
			setAttribute("name", "r_id"+x); // give input a name
			setAttribute("type", "hidden"); // make it a submit button
			setAttribute("value", rate_ids[x].value); // give input a value
		}
		
		form.appendChild(package_id);
		form.appendChild(rate_id);
		
		var input = document.createElement("input"); // create an input element
		with (input) {
			setAttribute("name", "enquiry"+x); // give input a name
			setAttribute("class", "btn_red");
			setAttribute("type", "submit"); // make it a submit button
			setAttribute("value", "Enquire for Free"); // give input a value
		}
		form.appendChild(input); // append input to form
		document.getElementById(rate_ids[x].value).appendChild(form);
		
		//alert(x);
	}
		
}

function open_box(url){
	
	var link = escape(url);
	//alert(url);
	
	var objFrame=document.getElementById("sota_frame"); 
	objFrame.src = url; 
	document.getElementById('light').style.display = 'block';
	document.getElementById('fade').style.display = 'block';
	
}

function open_detail(package_id){
	var hn = window.location.hostname;
	var vtf = document.location.href;
	var path = window.location.pathname.split( '/' );
	
	//detect production or staging
	if (hn == "124.150.142.162" || vtf =="http://allmalaysia.info/vtf-test/" || path[1] == "vtf-test") {
		var host = "http://124.150.142.162/sotatravel/";
	}else if(hn == "192.168.1.118"){
		var host = "http://192.168.1.118/sotatravel/";
	}
	else {
		var host = "http://www.sota.travel/";
	}
	
	var url = host + "index.cfm?var_dir=details&var_pack_id=" + package_id + "&var_template=3&var_flag=1";
	
	//alert(url);
	
	var objFrame=document.getElementById("sota_frame"); 
	objFrame.src = url; 
	document.getElementById('light').style.display = 'block';
	document.getElementById('fade').style.display = 'block';
	
}


function open_box_iframe(url){
	
	var link = escape(url);
	//alert(url);
	
	var objFrame=window.parent.document.getElementById("sota_frame"); 
	objFrame.src = url; 
	window.parent.document.getElementById('light').style.display = 'block';
	window.parent.document.getElementById('fade').style.display = 'block';
	
}

function hide_box(){
	
	var objFrame=document.getElementById("sota_frame"); 
	objFrame.src = ""; 
	document.getElementById('light').style.display = 'none';
	document.getElementById('fade').style.display = 'none';
	
}

