function check(index) {
	try {
		if (document.getElementById('first_name').value == '') return false;
		if (document.getElementById('last_name').value == '') return false;
		var email = document.getElementById('email');
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)) return false;
		switch (index) {
			case 1: // For Businesses
				//if (document.getElementById('company').value == '') return false;
				break;
			case 4: // Resources
				//if (document.getElementById('company').value == '') return false;
				if (document.getElementById('00N00000008nVVa').value == 'Select Your Purpose') return false;
				break;
			case 7: // Contact Us
				if (document.getElementById('00N00000008nVVa').value == 'Select Your Purpose') return false;
				break;
		}
	} catch(err){}
	return true;
}
function validate(index, returnUrl) {
	if (check(index)) {
		try {
			document.getElementById('Form').method = 'post';
			document.getElementById('Form').__VIEWSTATE.value = '';
			document.getElementById('Form').action = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
			document.getElementById('Form').encoding = 'application/x-www-form-urlencoded';
			// add more custom fields to Salesforce
			document.getElementById('00N00000008iqtQ').value = "Referring website: " + getCookie("referring_website"); // document.referrer; // referring URL
			document.getElementById('lead_source').value = "Inbound Web Lead";
			document.getElementById('00N00000006p29A').value = document.getElementsByTagName('title')[0].text + " - " + document.location.href; // lead source detail
			if (returnUrl != undefined) {
				document.getElementById("retURL").value = document.location.protocol + "//" + document.location.host + "/" + returnUrl;
			}
			document.getElementById('Form').submit();
		} catch(err){}
	}
	else
		alert('Please fill the correct values.');
	return false;
}
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

jQuery(document).ready(function () {
	$('a[href*="http://www.ifinity.com.au"]').parent().hide();
	if ($('[id*=lblMessage]').parent().parent().parent().parent().next().attr('tagName') == "HR")
	{
		$('[id*=lblMessage]').parent().parent().parent().parent().filter('table').hide();
		$('[id*=lblMessage]').parent().parent().parent().parent().filter('table').next().hide();
	}
	
	if (document.referrer.indexOf("visanow.com") < 0) {
		setCookie("referring_website",document.referrer,null); // store another website prior to visanow.com
	}
	else {
		if (getCookie("referring_website").indexOf("visanow.com") > 0) {
			setCookie("referring_website","",null);
		}
	}

	var path = document.location.pathname.toLowerCase();
	
	// Blog page
	if (path.indexOf("blog") > 0) {
		$('span[id*=ViewBulkEmailOptIn_lblEmail_lblLabel]').hide();
		$('span[id*=ViewBulkEmailOptIn_lblSubscribe]').hide();
		$('span[id*=ViewBulkEmailOptIn_groupname]').hide();
		$('input[id*=ViewBulkEmailOptIn_cmdSubscribeImg]').css({'top':'-15px','position':'relative','float':'left'});
		$('table[id*=ViewBulkEmailOptIn]').attr('width','100%');
		$('table[id*=ViewBulkEmailOptIn] tr td:even').hide(); // fix for IE
		$('input[id*=ViewBulkEmailOptIn_txtEmail]').css({'width':'200px','float':'left'});
		$('input[id*=Search_txtSearch]').css({'width':'200px','float':'left'});
		$('input[id*=Search_btnSearch]').css({'width':'120px','float':'left'});
		$('.c_container').css('padding','0');
		$('#btnGetConsultant').click(function(){
			return validate(6,"immigration-blog/thank-you.aspx");
		});
		
		$('input[id*=cmdSubscribeImg]').click(function(){
		
		/*document.getElementById('txtEmail').style.display="none"
			$('input[id*=txtEmail]')[0].value = "none";*/
			alert("Thank You for your Subscription");
		});
		$('table.BlogInfo').find('tr:first').remove();
		$('[id*=ViewEntry_lnkRss]').remove();
	}
	//Business
	if (path.indexOf("business-immigration") > 0) {
        $('#individuals').attr('href', '/business-immigration/services/provider-comparison.aspx');
		$('#individuals').text('> How we stack up');
		$('#stackup').attr('href', '/resources/government-immigration-info.aspx');
		$('#stackup').text('> Government Links');
		$('#10steps').attr('href', '/resources/employment-eligibility/audit-compliance.aspx');
		$('#10steps').text('> I-9 WEBCAST: Understand and become Form I-9 Compliant with this helpful webcast');
		$('#eligibility').attr('href', '/portals/resources/U.S.%20Immigration/VISANOW_Introduction%20to%20Immigration%20Reform_Employers_Overview_2010.pdf');
		$('#eligibility').text('> CIR 101:Learn about Comprehensive Immigration Reform and its implications for employers');
		$("#paidConsultation").css('display','none');
		$("#demo").css('display','none');
		$("#visatypes").css('display','none');
		$("#resources").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#consultationCompany").css('display','');
		$("#consultationTitle").css('display','');
		$("#ind").css('display','none');
		$("#difference").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
        $('#btnGetConsultant').click(function(){
			return validate(1,"for-businesses/thank-you.aspx");
		});
	}
	
	// Businesses-Thank Yor Redirection
	if(path.indexOf("for-businesses/thank-you") > 0)
	{
		$('#individuals').attr('href', '/business-immigration/services/provider-comparison.aspx');
		$('#individuals').text('> How we stack up');
		$('#stackup').attr('href', '/resources/government-immigration-info.aspx');
		$('#stackup').text('> Government Links');
		$('#10steps').attr('href', '/resources/employment-eligibility/audit-compliance.aspx');
		$('#10steps').text('> I-9 WEBCAST: Understand and become Form I-9 Compliant with this helpful webcast');
		$('#eligibility').attr('href', '/portals/resources/U.S.%20Immigration/VISANOW_Introduction%20to%20Immigration%20Reform_Employers_Overview_2010.pdf');
		$('#eligibility').text('> CIR 101:Learn about Comprehensive Immigration Reform and its implications for employers');
		$("#paidConsultation").css('display','none');
		$("#demo").css('display','none');
		$("#visatypes").css('display','none');
		$("#resources").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#consultationCompany").css('display','');
		$("#consultationTitle").css('display','');
		$("#ind").css('display','none');
		$("#difference").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
	}
	
	//Resources
	if (path.indexOf("resources") > 0) {
	  	if (path.indexOf("corporate-immigration-services") > 0) {
			$("#consultationCompany").css('display','none');
			$('#btnGetConsultant').click(function(){
				return validate(4,"resources/thank-you.aspx");
			});
		}
		if (path.indexOf("resources/international-business-immigration") > 0) {
			$("#demo").css('display','');
		}
				
		$("#paidConsultation").css('display','none');
		$("#contact").css('display','none');
		$("#visatypes").css('display','none');
		$("#resources").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#consultationCompany").css('display','');
		$("#consultationTitle").css('display','');
		$("#consultationInterest").css('display','');
		$("#consultationComment").css('display','');
		$("#competitor").css('display','none');
		$("#corp").css('display','none');
		$("#ind").css('display','none');
		$("#difference").css('display','none');
		$("#aboutus").css('display','none');
		
		if (path.indexOf("resources/visa-types") > 0) {
			$("#paidConsultation").css('display','');
			$("#resources").css('display','');
			$("#demo").css('display','none');
			$("#business").css('display','none');
		}
		$('#btnGetConsultant').click(function(){
			return validate(4,"resources/thank-you.aspx");
		});
	}

	// Individual
	if (path.indexOf("individual-immigration") > 0) {
		$('#complimentary').attr('href', '/individual-immigration/consult-attorney.aspx');
		$('#complimentary').text('> eConsultation for Individuals');
		$('#individuals').attr('href', '/business-immigration/services/provider-comparison.aspx');
		$('#individuals').text('> How we stack up');
		$('#stackup').attr('href', 'http://travel.state.gov/visa/bulletin/bulletin_1360.html');
		$('#stackup').text('> Visa Bulletin');
		$('#testimonial').attr('href', '/individual-immigration/testimonials.aspx');
		$('#testimonial').text('> CLIENT TESTMONIALS: Read what our clients are saying about VISANOW');
		$('#immigration').attr('href', '/Portals/Resources/Individual-Consumer/VISANOW_%20How%20to%20become%20a%20US%20Citizen_Overview_2010.pdf');
		$('#immigration').text('> CITIZENSHIP OVERVIEW: Get all of your questions answered about U.S.');
		$('#10steps').attr('href', 'Portals/Resources/Individual-Consumer/VISANOW_Introduction%20to%20Immigration%20Reform_Individuals_Overview_2010.pdf');
		$('#10steps').text('> CIR 101: Learn about Comprehensive Immigration Reform and its potential implications');
		$('#eligibility').attr('href', '/resources/individuals/navigating-immigration-process.aspx');
		$('#eligibility').text('> IMMIGRATION WEBCAST: Understand the fundamentals of the U.S. immigration process');
		$("#demo").css('display','none');
		$("#business").css('display','none');
		$("#compare").css('display','none');
		$("#contact").css('display','none');
		$("#corp").css('display','none');
		$("#difference").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
		$("#freeConsultation").css('display','none');
		
		$('#btnGetConsultant').click(function () {
	       return validate(2,"for-individuals/thank-you.aspx");
		});
	}
	
	//Landing Page
	
	if(path.indexOf("for-individuals") > 0) {
		$("#business").css('display','none');
		$("#visatypes").css('display','');
		$("#resources").css('display','');
		$("#freeConsultation").css('display','none');
		$("#compare").css('display','none');
		$("#contact").css('display','none');
		$("#demo").css('display','none');
		$("#corp").css('display','none');
		$("#difference").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
		$('#btnGetConsultant').click(function () {
	       return validate(2,"for-individuals/thank-you.aspx");
		});
		
	}
	
	// Individuals-Thank You Redirection
	if(path.indexOf("for-individuals/thank-you") > 0)
	{
		$('#complimentary').attr('href', '/individual-immigration/consult-attorney.aspx');
		$('#complimentary').text('> eConsultation for Individuals');
		$('#individuals').attr('href', '/business-immigration/services/provider-comparison.aspx');
		$('#individuals').text('> How we stack up');
		$('#stackup').attr('href', 'http://travel.state.gov/visa/bulletin/bulletin_1360.html');
		$('#stackup').text('> Visa Bulletin');
		$('#testimonial').attr('href', '/individual-immigration/testimonials.aspx');
		$('#testimonial').text('> CLIENT TESTMONIALS: Read what our clients are saying about VISANOW');
		$('#immigration').attr('href', '/Portals/Resources/Individual-Consumer/VISANOW_%20How%20to%20become%20a%20US%20Citizen_Overview_2010.pdf');
		$('#immigration').text('> CITIZENSHIP OVERVIEW: Get all of your questions answered about U.S.');
		$('#10steps').attr('href', 'Portals/Resources/Individual-Consumer/VISANOW_Introduction%20to%20Immigration%20Reform_Individuals_Overview_2010.pdf');
		$('#10steps').text('> CIR 101: Learn about Comprehensive Immigration Reform and its potential implications');
		$('#eligibility').attr('href', '/resources/individuals/navigating-immigration-process.aspx');
		$('#eligibility').text('> IMMIGRATION WEBCAST: Understand the fundamentals of the U.S. immigration process');
		$("#demo").css('display','none');
		$("#business").css('display','none');
		$("#compare").css('display','none');
		$("#contact").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#corp").css('display','none');
		$("#difference").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
	}
	
	// VISANOW-Difference
	if (path.indexOf("visanow-difference") > 0) {
		$("#paidConsultation").css('display','none');
		$("#contact").css('display','none');
		$("#visatypes").css('display','none');
		$("#resources").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#corp").css('display','none');
		$("#ind").css('display','none');
		$("#resources1").css('display','none');
		$("#aboutus").css('display','none');
		$('#btnGetConsultant').click(function(){
			return validate(3,"visanow-difference/thank-you.aspx");
		});
	}
	
	// About Us
	if (path.indexOf("about-us") > 0) {
	   	$("#paidConsultation").css('display','none');
		$("#contact").css('display','none');
		$("#visatypes").css('display','none');
		$("#resources").css('display','none');
		$("#freeConsultation").css('display','none');
		$("#corp").css('display','none');
		$("#ind").css('display','none');
		$("#resources1").css('display','none');
		$("#difference").css('display','none');
		$('#btnGetConsultant').click(function(){
			return validate(5,"about-us/thank-you.aspx");
		});
	}
	
	// Contact Us
	if (path.indexOf("contact-us") > 0) {
		$('#btnGetConsultant').click(function(){
			return validate(7,"contact-us/thank-you.aspx");
		});
	}
	
	//WebsiteMap Thank You
	
	if (path.indexOf("websitemap") > 0) {
		$('#btnGetConsultant').click(function(){
			return validate(8,"thank-you.aspx");
		});
	}

	/* Visa Types */
	$("#tfindvisa").click(function(){
		var objectj = $("#country option:selected").val() + '#' + $("#type option:selected").val();
		if ($("#country option:selected").val() != ("Select Your Destination")) {
			window.location.replace(objectj); return false;
		} else {
			alert("Select Your Destination"); return false;
		}
	});
	
	// Add hostname to contact form
	try {
		var urlPath = document.getElementsByName("retURL")[0].value;
		document.getElementsByName("retURL")[0].value = document.location.protocol + "//" + document.location.host + "/" + urlPath;
	} catch(err){}
	
	// Add empty title to fix IE
	$('img').attr('title','');
	// Fix dotted border around images when clicking on IE
	if (document.documentElement.attachEvent)
		document.documentElement.attachEvent('onmousedown',function(){
			event.srcElement.hideFocus=true
	});
	
	// Adjust the heights of left pane and right pane
	try {
		if ($('.left_pane2')[0].clientHeight < $('.right_pane')[0].clientHeight) {
			$('.left_pane2').css('height',$('.right_pane')[0].clientHeight+$('.breadcrumb')[0].clientHeight+'px');
		}
	} catch(err){}
	
	// change table row color
	if ($('#navigation table').length > 0) {
		$('#navigation table tr:odd').addClass('odd');
		$('#navigation table tr:odd td').css('background-color','#fff');
		$('#navigation table tr:even td').css('background-color','#e6e2df');
	}
});

