// JavaScript Document

function dologin(url, email, pw) {
	var ajaxurl = url + 'user.cfc?method=login&email=' + email + '&pw=' + pw + '&rand=' + Math.random();
	
	ajaxSend( ajaxurl, 'logresult', 1);
	
	//document.location.reload(true);
}


function forgotpass(url, divid){

	var passDiv = document.createElement("div");
	passDiv.id = 'passRemind';
	passDiv.style.position = 'absolute';
	passDiv.style.top = '250px';
	passDiv.style.left = '320px';
	passDiv.style.width = '300px';
	passDiv.style.height = '110px';
	passDiv.style.zIndex = '20';
	passDiv.style.display = 'block';
	passDiv.style.backgroundColor = 'white';
	passDiv.style.border = 'thin solid';
	passDiv.style.paddingLeft = '5px';
	
	var ajaxurl = url + 'user.cfc?method=passRemindWindow' + '&rand=' + Math.random();
	
	document.getElementById(divid).appendChild(passDiv);
	init();
	//alert(ajaxurl);
	ajaxSend( ajaxurl, passDiv.id);
}

function doPassRemind(url, email, divid){
	var ajaxurl = url + 'user.cfc?method=passReminder&email=' + email + '&rand=' + Math.random();
	
	ajaxSend( ajaxurl, divid );
}

function tickchildren(fname, regid){
	
	//alert(document.getElementById(regid).checked);
	
	for (var i = 0; i < document.getElementById(fname).elements.length; i++ ) {
        var thisid = document.getElementById(fname).elements[i].id;
		if (document.getElementById(fname).elements[i].type == 'checkbox' && thisid.substring(0,thisid.indexOf('_')) == regid ) {
			if (document.getElementById(regid).checked)
				document.getElementById(fname).elements[i].checked = true;
			else
				document.getElementById(fname).elements[i].checked = false;
		}
	}
}

function buyCV(url, cvid, e){
	
	if(confirm('Purchase access to this CV? This will deduct 1 CV View credit from your account if available!'))
	{
		
		if (!e) e = window.event;
	
		if (e)
		{ 
			if (e.pageX || e.pageY)
			{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
				mousex = e.pageX;
				mousey = e.pageY;
				//algor = '[e.pageX]';
				//if (e.clientX || e.clientY) algor += ' [e.clientX] '
			}
			else if (e.clientX || e.clientY)
			{ // works on IE6,FF,Moz,Opera7
				mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
				
				//algor = '[e.clientX]';
				//if (e.pageX || e.pageY) algor += ' [e.pageX] '
			}  
		}
		
		var cvBuyDiv = document.createElement("div");
		cvBuyDiv.id = 'cvBuyDiv';
		cvBuyDiv.style.position = 'absolute';
		cvBuyDiv.style.top = (mousey - 100).toString(10) + 'px';
		cvBuyDiv.style.left = (mousex - 100).toString(10) + 'px';
		cvBuyDiv.style.width = '300px';
		cvBuyDiv.style.height = '200px';
		cvBuyDiv.style.zIndex = '20';
		cvBuyDiv.style.display = 'block';
		cvBuyDiv.style.backgroundColor = 'white';
		cvBuyDiv.style.border = 'thin solid';
		cvBuyDiv.style.paddingLeft = '5px';
		
		var ajaxurl = url + 'recruiter.cfc?method=buyCV&cvid=' + cvid + '&rand=' + Math.random();
		
		document.getElementById('generic').appendChild(cvBuyDiv);
		init();
		//alert(ajaxurl);
		ajaxSend( ajaxurl, cvBuyDiv.id);
	}
	
}

function showSubRegions(regionid, span){
	
	if (document.getElementById('subregions_' + regionid).style.display == 'none')
	{
		document.getElementById('subregions_' + regionid).style.display = 'block';
		span.innerHTML = '(hide sub-regions)';
	}
	else
	{
		document.getElementById('subregions_' + regionid).style.display = 'none';
		span.innerHTML = '(show sub-regions)';
	}	
}

function showSubSectors(sectorid, span){
	
	if (document.getElementById('subsector_' + sectorid).style.display == 'none')
	{
		document.getElementById('subsector_' + sectorid).style.display = 'block';
		span.innerHTML = '(hide sub-sectors)';
	}
	else
	{
		document.getElementById('subsector_' + sectorid).style.display = 'none';
		span.innerHTML = '(show sub-sectors)';
	}	
}
