$(function(){
	// Datepicker

	
	
	//$("#sortable").tablesorter(); 

});
function clickPassword() {
	$('#password').html('<h1 class="sm">Please check your email</h1>');
}


function initDropDown() {
	$("#login select").selectbox({
		onOpen: function (inst) {
			//console.log("open", inst);
		},
		onClose: function (inst) {
			//console.log("close", inst);
		},
		effect: "slide"
	});
}

function initLogin() {
	$('#login select').change(function() {
		
		tempVar = $(this).val();
		if (tempVar=="employee") {
			$.nmManual('/main/login_form', {
				sizes: {	// Size information
				    initW: '600px',	// Initial width
				    initH: '400px',	// Initial height
				    w: '1000px',		// width
				    h: undefined,		// height
				    minW: '600px',	// minimum width
				    minH: '400px',	// minimum height
				    wMargin: undefined,	// Horizontal margin
				    hMargin: undefined	// Vertical margin
				}
			});

			
		} else if (tempVar=="customer_en") {
			
			window.location = 'https://www.advance-commissions.com/asps/en_login.asp?Language=1';
		}
		
		 else if (tempVar=="customer_fr") {
			
			window.location = 'https://www.advance-commissions.com/asps/en_login.asp?Language=2';
		}
  		
	});
}


function initTestimonials() {
	var ajaxcount = 5;
	var offset = 2;
	//alert(langType);
	$('.ajax-link').click(function(){
		
		$('.ajax-wrap').html('<p>Loading Testimonial</p>');
		
		$('#ajax-content').load('/main/ajax-display/' + offset, function() {
			$('.ajax-wrap').show();
		});
		offset++;
		
		if (offset == ajaxcount) { 
			
			offset = 2 ;
		};
		
		return false;
	});
}

function initTestimonialsFr() {
	var ajaxcount = 5;
	var offset = 2;
	//alert(langType);
	$('.ajax-link').click(function(){
		
		$('.ajax-wrap').html('<p>Loading Testimonial</p>');
		
		$('#ajax-content').load('/main/ajax-display_fr/' + offset, function() {
			$('.ajax-wrap').show();
		});
		offset++;
		
		if (offset == ajaxcount) { 
			
			offset = 2 ;
		};
		
		return false;
	});
}


function initBios() {

	$.each($('#about ul li'), function(index, value) { 
		   
		//hover effect, display title
		$(this).hover(function() {
			$(this).find('span').animate({
				bottom: '0px'
			});
		}, function() {
			$(this).find('span').animate({
				bottom: '-31px'
			});
		});

		
		$(this).find('a').click(function(e) {
			var myUrl = $(this).attr('href');
			e.preventDefault();
		    $.nmManual( myUrl, {
		        sizes: {
		            minW: 650,
		            minH: 250
		        }
		    });

		});


	});
}


function initExp() {

	$.each($('.exp'), function(index, value) {
			
		$(this).next('div').hide();
		$(this).click(function() {
			$(this).toggleClass('open')
			$(this).next('div').toggle()
		});
		
	});
}

function initLangCheck() {
	$.each( $('#langCheck label'), function() {
		$(this).click(function() {
			$(this).find('input').attr('checked','true');
			$('#langCheck form').submit();
		});
	});
}




function checkLanguage() {
	//how to erase
	//eraseCookie('languageType')
	
	//createCookie('languageType', 'english', 365)
	if ( readCookie('languageType') == null ) {
			
		$("#langCheck").load('/main/languageSelect/').dialog({
			title: "Please choose a language",
			modal: true,
			autoOpen: false,
			width: 400,
			height: 170,
			buttons: {
				"English": function() { 
					createCookie('languageType', 'english', 365);
					$(this).dialog("close");
				}, 
				"French": function() { 
					createCookie('languageType', 'french', 365);
					$(this).dialog("close");
				} 
			}
		}); 
		$("#langCheck").dialog("open");
		
	} else {
		 if ( readCookie('languageType') == 'english' ) {
		 	
		 } else {
		 
		 	//window.location.href = "/fr/";
		 }
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function getUrlVars() { 
    var vars = [], hash;
    var hashes = window.location.href.split('/');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}









// clearing  inputs on focus
function doClear(theText) {if (theText.value == theText.defaultValue) {theText.value = "";}}

//replace input value with default on blur
function doReset(theText){if (theText.value == ""){theText.value = theText.defaultValue;}}


