// JavaScript Document

//window.onload = initAll;
var xhr = false;

function ajax_page( element, page ) {
	
	//alert ( element);
	//alert ( page);

	
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}

	if (xhr) {
		xhr.open("GET", page, true);
		xhr.onreadystatechange = function () {
			if ( xhr.readyState == 4 && xhr.status == 200 ) {
						document.getElementById(element).innerHTML = xhr.responseText;
			}			
		}
		xhr.send(null);
	}
	else {
		alert("Sorry, but I couldn't create an XMLHttpRequest");
	}
}


function innerHTML( element, text) {
	alert( 'element' );
	//document.getElementById(element).innerHTML = text;
}

function redirect_to( url ){
	return window.location = url;
}


var RecaptchaOptions = {
   theme : 'clean'
};
//Other option are: red, white, blackglass, clean, custom


function go_to( url ){
	return window.location = url;
}



function check_all( name ){
	var a=new Array();
	a=document.getElementsByName( name );
	
	for( i=0; i<a.length; i++ ){
		a[i].checked  = true;
	}
}

function de_check_all( name ){
	var a=new Array();
	a=document.getElementsByName( name );
	
	for( i=0; i<a.length; i++ ){
		a[i].checked  = false;
	}
}



/**** CV **********/
function delete_cv(){
	var message = "Are you sure you want to do this? You will lose this CV.";
	if( confirm(message) ){
		return true;
	}
	return false;
}

function copy_cv(){
	var message = "Are you sure you want to do this? You will lose this CV.";
	if( confirm(message) ){
		return true;
	}
	return false;
}




///used on job page adding new job

function check(){
	var a=new Array();
	a=document.getElementsByName("category[]");
	//alert("Length:"+a.length);
	var p=0;
	
	for( i=0; i<a.length; i++ ){
		if(a[i].checked) { p++; }
		
	}
	
	for( i=0; i<a.length; i++ ){
		if( p >= 10 ){
			if ( a[i].checked ) a[i].disabled  = false;
			else a[i].disabled  = true;
		}
		else{
			a[i].disabled  = false;
		}
	}
}
	
function check_me(name){
	var a=new Array();
		a=document.getElementsByName("category[]");
	for( i=0; i<a.length; i++ ){
		if( !a[i].disabled ) {
			if(a[i].value == name ) { 
				if ( a[i].checked )
					a[i].checked = false;
				else
					a[i].checked = true;
			}
			else if( a[i].checked ) { a[i].checked = true; }
			else { a[i].checked = false; }
		}
		else{
			if(a[i].value == name ) { a[i].checked = false; }
		}
	}
	
	return check();
}

function check_job_( name ){
	var a=new Array();
	a=document.getElementsByName(name);

	var p=0;
	
	for( i=0; i<a.length; i++ ){
		if(a[i].checked) { p++; }
		
	}
	
	for( i=0; i<a.length; i++ ){
		if( p >= 1 ){
			if ( a[i].checked ) a[i].disabled  = false;
			else a[i].disabled  = true;
		}
		else{
			a[i].disabled  = false;
		}
	}
}

function validate_from_one_click(name){
	var str = '';
	var elem = document.getElementById(name).elements;
	for(var i = 0; i < elem.length; i++)
	{
		var my_car=elem[i].name;
		var the_length=my_car.length;
		var last_char=my_car.charAt(the_length-1);
		//alert('The last character is '+last_char+'.');
		
		if(last_char == '1' ){
			if(elem[i].value == "" )
			{
				alert("Please enter all the information");
				return false;
			}
		}
	}
	
	return true;
}
