function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL;
    }
}

function validate_contact_us()
{
	if(v.exec())
	{
		post_contact_us();
	}

	return false;
}

function post_contact_us()
{
	/* Ajax Object*/
	ajax_loader(1);
	var contact_ajaxObject = new sack(); 
	contact_ajaxObject.requestFile = $("#contact_base_url").html()+'/contact/ajax_files/contact_us_process.php';  // post data file	
	contact_ajaxObject.setVar('contact_type', Url.encode(document.getElementById('contact_type').value));
	contact_ajaxObject.setVar('firstname', Url.encode(document.getElementById('firstname').value));
	contact_ajaxObject.setVar('lastname', Url.encode(document.getElementById('lastname').value));
	contact_ajaxObject.setVar('company_name', Url.encode(document.getElementById('company_name').value));
	contact_ajaxObject.setVar('title', Url.encode(document.getElementById('title').value));
	contact_ajaxObject.setVar('address', Url.encode(document.getElementById('address').value));
	contact_ajaxObject.setVar('city', Url.encode(document.getElementById('city').value));
	contact_ajaxObject.setVar('state', Url.encode(document.getElementById('state').value));
	contact_ajaxObject.setVar('country_id', Url.encode(document.getElementById('country_id').value));
	contact_ajaxObject.setVar('country_name', Url.encode($("#country_id option:selected").text()));
	contact_ajaxObject.setVar('phone_business', Url.encode(document.getElementById('phone_business').value));
	contact_ajaxObject.setVar('phone_home', Url.encode(document.getElementById('phone_home').value));
	contact_ajaxObject.setVar('email', Url.encode(document.getElementById('email').value));
	contact_ajaxObject.setVar('confirm_email', Url.encode(document.getElementById('confirm_email').value));
	contact_ajaxObject.setVar('comment', Url.encode(document.getElementById('comment').value));
	contact_ajaxObject.setVar('verification_code', Url.encode(document.getElementById('verification_code').value));
	contact_ajaxObject.onCompletion =  function(){
		var res = contact_ajaxObject.response; 
		var arr_res = res.split('!~!');
		switch(arr_res[0])
		{
			case '0':
				//document.getElementById("td_contact_us").innerHTML = "Thank you for Contacting Dan Dunn!";
				document.getElementById("cimage").src="/captcha.php";
				document.getElementById("msg_center").innerHTML = "<font color='green'>Thank You! We will be in touch within 48hrs.</font>"; 
				alert("Thank You! We will be in touch within 48hrs.");
				break;
			case '1':
				document.getElementById("msg_center").innerHTML = arr_res[1];
				// refresh_captcha(document.getElementById("comment_captcha"));
				break;
		}
		ajax_loader(0);
		
	};     // Specify function that will be executed after file has been found
	contact_ajaxObject.runAJAX();
	// Execute AJAX function
}

function get_country_name()
{
	var obj_country = document.getElementById('country_id');
	if( obj_country.selectedIndex > -1 )
	{
		var selected_text = obj_country.options[obj_country.selectedIndex].text;
		document.getElementById('country_name').value = selected_text;
	}
}
