var URL="http://www.vrft.com/aci/Service.asmx";
//var URL="http://localhost/vrft/aci/Service.asmx";
//var URL="http://localhost:58770/aci/Service.asmx"
//var URL="http://www.vrft.com/aci/Service.asmx";

// JavaScript Document
 
$(document).ready(function() {
	$("#form1").validate();	
	SetLang(null, false);	
	$("#navmenu-h li,#navmenu-v li").hover(
    	function() { $(this).addClass("iehover"); },
    	function() { $(this).removeClass("iehover"); }
  	);
});

function SubmitVerify( formID ) {
	var frm = $("[name=" + formID + "]" );
	frm.submit();
}

function SetLang( langcode, gotoLanguagePage ) {
	gotoLanguagePage = (( gotoLanguagePage == null ) ? true : gotoLanguagePage );
	var sTargetPage = window.location.href;
	if ( sTargetPage.indexOf('.html') < 0 ) {
		sTargetPage += ( sTargetPage.endsWith('/') ? '' : '/' ) + 'index.html';
	}
	
	if ( langcode == null ) {
		langcode = $.cookie('VRFT_LANG');
		if ( langcode == null ) {
			langcode = language();
		}
	} else {
		if ( langcode=='es' ) { 
			langcode = 'en-ES';
		} else {
			langcode = 'en-US';
		}
	}
	if ( langcode=='en-ES' ) {
		$('#img_flag_US').show();
		$('#lang_link_US').show();

		$('#img_flag_ES').hide();
		$('#lang_link_ES').hide();
		$.cookie('VRFT_LANG', 'en-ES');
		$('a').each(function(idx, item) {
			if ( item.href.indexOf('.html') > -1 ) {
				var shref = item.href.replace(/.html/, "_es.html");
				if ( isThere( shref ) ) {
					item.href = shref;
				}
			}
		});
		if ( sTargetPage.indexOf('_es') < 0 ) { 
			var shref = sTargetPage.replace(/.html/, "_es.html");
			if ( gotoLanguagePage ) {
				window.location = shref;
			}
		}
	} else {  //default language
		$('#img_flag_ES').show();
		$('#lang_link_ES').show();

		$('#img_flag_US').hide();
		$('#lang_link_US').hide();
		$.cookie('VRFT_LANG', 'en-US');
		$('a').each(function(idx, item) {
			if ( item.href.indexOf('.html') > -1 ) {
				var shref = item.href.replace(/_es.html/, ".html");
				if ( isThere( shref ) ) {
					item.href = shref;
				}
			}
		});
		if ( sTargetPage.indexOf('_es') > 0 ) { 
			var shref = sTargetPage.replace(/_es.html/, ".html");		
		}
	}
}

function language() {
	var lang = navigator.language;
	if ( lang == null ) {
		lang = navigator.systemLanguage;
	}
	return lang;
} 

function AJ() {
	var obj;
	if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
	else if (window.ActiveXObject){
		try{
			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
		}
		catch(er){
			try{
				obj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(er){
				obj= false;
			}
		}
	}
	return obj;
}

function isThere(url) {
	var req= new AJ(); // XMLHttpRequest object
	try {
		req.open("HEAD", url, false);
		req.send(null);		
		return req.status== 200 ? true : false;
	}
	catch (er) {
		return false;
	}
}

String.prototype.trim = function(){return
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}