//
// VALIDATION
function isAlphabet(id, msg)
{
	var e = document.getElementById(id);
	var re = /^([0-9])?([a-zA-Z0-9_\-\'\&])/;
	if(!re.test(e.value) || e.value == null || e.value == "")
	{
		alert('Invalid ' + msg);
		return false;
	}
	else {
		return true;
	}
}
//
function isAlphanum(id, msg)
{
	var e = document.getElementById(id);
	var re = /^([a-zA-Z0-9\-\+])/;
	if(!re.test(e.value) || e.value == null || e.value == "")
	{
		alert('Invalid ' + msg);
		return false;
	}
	else {
		return true;
	}
}
//
function isPhone(id, msg)
{
	var e = document.getElementById(id);
	var re = /^\+?[0-9]\d/;
	if(!re.test(e.value) || e.value == null || e.value == 0)
	{
		alert('Invalid ' + msg); 
		return false;
	}
	else {
		return true;
	}
}
//
function isZip(id, msg)
{
	var e = document.getElementById(id);
	var re = /^[0-9]\d/;
	if(!re.test(e.value) || e.value == null || e.value == 0)
	{
		alert('Invalid ' + msg);
		return false;
	}
	else
	{
		return true;
	}
}
//
function isEmail(id, msg) {
	var e = document.getElementById(id);
	var filter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if (!filter.test(e.value) || e.value == null || e.value == "") {
		alert('Invalid ' + msg);
		return false;
	}
	else {
		return true;
	}
}
//
function isPassword(id0, id1)
{
	var e0 = document.getElementById(id0);
	var e1 = document.getElementById(id1);

	if(e0.value == "" || e1.value == "")
	{
		alert("Please enter password");
		return false;
	}
	
	if(e0.value.toLowerCase() != e1.value.toLowerCase())
	{
		alert("Repeat password not equal to Create password");
		return false;
	}
	else
	{
		return true;
	}
}	
//
function isCountry(id, msg)
{
	var e = document.getElementById(id);
	if(e.value == "-")
	{
		alert("Invalid " + msg);
		return false;
	}
	else
	{
		return true;
	}
}
//
function createCountry()
{
	var s = document.getElementById("sel_country");
	
	if(s.length < 2)
	{
		var countries = new Array(
		"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antarctica", "Antigua and Barbuda", 
		"Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", 
		"Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", 
		"Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia", "Cameroon", 
		"Canada", "Cape Verde", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", 
		"Congo, Democratic Republic", "Congo, Republic of the", "Costa Rica", "Cote d'Ivoire", "Croatia", 
		"Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", 
		"Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", 
		"France", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guatemala", 
		"Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", 
		"Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", 
		"Korea, North", "Korea, South", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", 
		"Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", 
		"Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Mongolia", "Morocco", 
		"Monaco", "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", 
		"Norway", "Oman", "Pakistan", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", 
		"Qatar", "Romania", "Russia", "Rwanda", "Samoa", "San Marino", " Sao Tome", "Saudi Arabia", "Senegal", 
		"Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", 
		"Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", 
		"Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", 
		"Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", 
		"Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe");
		//
		for(var i = 0; i < countries.length; i++)
		{
			var e = document.createElement("option");
			e.text = countries[i];
			e.value = countries[i];
			if(document.all){ //IE
				s.add(e);
			}else{
				s.appendChild(e);
			} 
			//s.appendChild(e);
		}
	}
}
//
//
var xmlhttp;
//
function sendRegistrationMail()
{
	xmlhttp = createXmlHttpRequest();
	if(xmlhttp == null)
	{
		alert("Your browser does not support XMLHTTP!");
		return;
	}

	//
	var fname = document.getElementById("in_fname").value;
	var lname = document.getElementById("in_lname").value;
	var n = fname + ' ' + lname;
	// Email
	var e = document.getElementById("in_email").value;
	//
	var p = document.getElementById("in_pass1").value;
	// Company
	var c  = document.getElementById("in_company").value;
	// Phone 1/2
	var p1 = document.getElementById("in_phone1").value;
	var p2 = document.getElementById("in_phone2").value;
	// Business Fax
	var f = document.getElementById("in_fax").value;
	// Address
	var a = document.getElementById("in_addr").value;
	// Town
	var t = document.getElementById("in_town").value;
	// State / Province
	var s = document.getElementById("in_state").value;
	// Zip / Postal code
	var z = document.getElementById("in_zip").value;
	// Country
	var co = document.getElementById("sel_country").value;
	// ARC
	var arc = document.getElementById("in_arc").value;
	// CLIA
	var clia = document.getElementById("in_clia").value;
	// ASTA
	var asta = document.getElementById("in_asta").value;
	// Consortium
	var con = document.getElementById("in_consortium").value;
	// GDS
	var gds = document.getElementById("in_gds").value;
	// Pseudo city
	var psc = document.getElementById("in_psc").value;
	// Remarks
	var rem = document.getElementById("ta_remarks").value;
	//	
	var url = "sendmail.php";
	url = url + "?q=registration" + "&n=" + n + "&e=" + e + "&p=" + p +
				"&c=" + c + "&p1=" + p1 + "&p2=" + p2 + "&f=" + f + "&a=" + a +
				"&t=" + t + "&s=" + s + "&z=" + z + "&co=" + co + "&arc=" + arc +
				"&clia=" + clia + "&asta=" + asta + "&con=" + con + "&gds=" + gds +
				"&psc=" + psc + "&rem=" + rem;
	url = url + "&sid=" + Math.random(); 
	xmlhttp.onreadystatechange = registrationState;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}
//
function registrationState()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			var f = document.getElementById("form_register");
			f.reset();
  			document.getElementById("div_register").innerHTML = '';
			var d = document.getElementById("div_register");
			var p = document.createElement("p");
            var t = document.createTextNode(xmlhttp.responseText);
            attr = document.createAttribute("style");
            p.setAttribute('id', 'p_reg_info');
            p.setAttribute('style','color: green; font-size: 14px; font-weight: 900; font-style: italic;');
            p.appendChild(t);
            d.appendChild(p);
            window.location = "info.shtml";
		}
	}
}
//
function sendAppMail(regtype)
{
	xmlhttp = createXmlHttpRequest();
	if(xmlhttp == null)
	{
		alert("Your browser does not support XMLHTTP!");
		return;
	}

	//
	var fname = document.getElementById("in_fname").value;
	var lname = document.getElementById("in_lname").value;
	var n = fname + ' ' + lname;
	// Email
	var e = document.getElementById("in_email").value;
	// Phone 1/2
	var p1 = document.getElementById("in_phone1").value;
	var p2 = document.getElementById("in_phone2").value;
	// Business Fax
	var f = document.getElementById("in_fax").value;
	// Address
	var a = document.getElementById("in_addr").value;
	// Town
	var t = document.getElementById("in_town").value;
	// State / Province
	var s = document.getElementById("in_state").value;
	// Zip / Postal code
	var z = document.getElementById("in_zip").value;
	// Country
	var co = document.getElementById("sel_country").value;
	// Remarks
	var rem = document.getElementById("ta_remarks").value;
	//	
	var url = "sendmail.php";
	url = url + "?q=app" + "&n=" + n + "&e=" + e +
				"&p1=" + p1 + "&p2=" + p2 + "&f=" + f + "&a=" + a +
				"&t=" + t + "&s=" + s + "&z=" + z + "&co=" + co + "&rem=" + rem + "&rt=" + regtype;
	url = url + "&sid=" + Math.random(); 
	xmlhttp.onreadystatechange = appState;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}
//
function appState()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			var f = document.getElementById("form_register");
			f.reset();
  			document.getElementById("div_register").innerHTML = '';
			var d = document.getElementById("div_register");
			var p = document.createElement("p");
            var t = document.createTextNode(xmlhttp.responseText);
            attr = document.createAttribute("style");
            p.setAttribute('id', 'p_reg_info');
            p.setAttribute('style','color: green; font-size: 14px; font-weight: 900; font-style: italic;');
            p.appendChild(t);
            d.appendChild(p);
            window.location = "info.shtml";
		}
	}
}
//
function sendSubscribeMail()
{
	xmlhttp = createXmlHttpRequest();
	if(xmlhttp == null)
	{
		alert("Your browser does not support XMLHTTP!");
		return;
	}
	//
	var email = document.getElementById("in_subs_mail").value;
	var url = "sendmail.php";
	url = url + "?q=subscribe" + "&email=" + email;
	url = url + "&sid=" + Math.random();
	xmlhttp.onreadystatechange = subscribeState;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}
//
function subscribeState()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			var d = document.getElementById("div_social");
			var e = document.getElementById("p_subs_info");
			if(e != null)
				d.removeChild(e);

			var p = document.createElement("p");
			var t = document.createTextNode(xmlhttp.responseText);
			attr = document.createAttribute("style");
			p.setAttribute('id', 'p_subs_info');
		    p.setAttribute('style','text-align: center; color: green; font-size: 12px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; margin: -20px 0 0 0');
			p.appendChild(t);
			d.appendChild(p);
		}
	}
}
//
function sendContactMail()
{
	xmlhttp = createXmlHttpRequest();
	if(xmlhttp == null)
	{
		alert("Your browser does not support XMLHTTP!");
		return;
	}
	//
	var name    = document.getElementById("in_name").value;
	var email   = document.getElementById("in_mail").value;
	var phone   = document.getElementById("in_phone").value;
	var msg     = document.getElementById("ta_msg").value;
	//
	var url = "sendmail.php";
	url = url + "?q=contact" + "&name=" + name + "&email=" + email + "&phone=" + phone + "&msg=" + msg;
	url = url + "&sid=" + Math.random();
	xmlhttp.onreadystatechange = contactState;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}
//
function contactState()
{
	if(xmlhttp.readyState == 4)
    {
        if(xmlhttp.status == 200)
        {
			var f = document.getElementById("form_contact");
			f.reset();
            document.getElementById("div_info").innerHTML = '';
            var d = document.getElementById("div_info");
            var p = document.createElement("p");
            var t = document.createTextNode(xmlhttp.responseText);
            attr = document.createAttribute("style");
            p.setAttribute('style','color: green; font-size: 12px; font-weight: bold; font-family: Arial, Helvetica, sans-serif');
            p.appendChild(t);
            d.appendChild(p);
        }
    }
}
//
function clearRegisterInfo()
{
	var d = document.getElementById("div_register");
	var e = document.getElementById("p_reg_info");
	if(e != null)
		d.removeChild(e);
}
//
function clearSubsInfo()
{
	var d = document.getElementById("div_social");
	var e = document.getElementById("p_subs_info");
	if(e != null)
		d.removeChild(e);
}
//
function createXmlHttpRequest()
{
	if(window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
   		return new XMLHttpRequest();
	}

	if(window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}

	return null;
}
//
var title = "3KM Travel - Travel Consolidator";
var description = '';
var url_name="3kmtravel.com";
//
function loadPage(url, title, description)
{
	switch(url)
	{
	case 'del.icio.us':
		window.open("http://del.icio.us/post?url=" + url_name + ";title=" + title);
		break; 
	case 'blinklist':
		window.open("http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;url=" + url_name + ";title=" + title); 
     	break;
	case 'furl':
		window.open("http://www.furl.net/storeIt.jsp?u=" + url_name + ";title=" + title); 
     	break;
	case 'digg':
		window.open("http://digg.com/submit?phase=2&amp;url=" + url_name + ";title=" + title); 
     	break;
	case 'ma.gnolia':
		window.open("http://ma.gnolia.com/bookmarklet/add?url=" + url_name + ";title=" + title); 
     	break;
	case 'stumble':
		window.open("http://www.stumbleupon.com/submit?url=" + url_name + "&amp;title=" + title); 
     	break;
	case 'simpy':
		window.open("http://www.simpy.com/simpy/LinkAdd.do?url=" + url_name + ";title=" + title); 
     	break;
	case 'vine':
		window.open("http://www.newsvine.com/_tools/seed&amp;save?url=" + url_name + ";title=" + title); 
     	break;
	case 'reddit':
		window.open("http://reddit.com/submit?url=" + url_name + ";title=" + title); 
     	break;
	case 'fark':
		window.open("http://cgi.fark.com/cgi/fark/edit.pl?new_url=" + url_name + ";new_comment=" + title); 
     	break;
	case 'twitter':
		window.open("http://twitter.com/"); 
     	break;
	case 'facebook':
		window.open("http://www.facebook.com/sharer.php?url=" + url_name + ";title=" + title);
     	break;
	}
}
