// JavaScript Document

// overlays

function ShowHandsets(make){
    Shadowbox.open({
		content: 'includes/overlay_compatible.php?n=' + make,
		player: 'iframe',
		title: '',
		width: 755,
		height: 800
    });
}
function DownloadPC(){
    Shadowbox.open({
		content: 'includes/overlay_getit.php',
		player: 'iframe',
		title: '',
		width: 755,
		height: 800
    });
}

// forms
function DisableButtons(btn){
	if(btn){
		$('#loader'+btn).html('<img src="images/loader_btn.gif" width="13" height="13" />');		
    	$('#'+btn).addClass('disabled').attr("disabled","disabled"); 
	} else {
		$('#loader').html('<img src="images/loading.gif" width="13" height="13" />');
	    $('.btn').addClass('disabled').attr("disabled","disabled"); 
	}
	$(':input').attr('readonly', true).attr("onkeyup","return false;");
}

function EnableFields(n) {
	$(':input').attr('readonly', false);
	$('.btn').removeClass('disabled').removeAttr('disabled'); 

}

// Validation

function validateEmail(email) {
	
	if (email == null || email == "") {
		return 0;
	}
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!email.match(/^[^@]{1,64}@[^@]{1,255}$/)) {
        // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
        return -1;
    }
    // Split it into sections to make life easier
    var email_array = email.split("@");
    var local_array = email_array[0].split(".");
    for (var i = 0; i < local_array.length; i++) {
        if (!local_array[i].match(/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/)) {
            return -2;
        }
    }
    if (!email_array[1].match(/^\[?[0-9\.]+\]?$/)) { // Check if domain is IP. If not, it should be valid domain name
        var domain_array = email_array[1].split(".");
        if (domain_array.length < 2) {
            return -3; // Not enough parts to domain
        }
        for (i = 0; i < domain_array.length; i++) {
            if (!domain_array[i].match(/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/)) {
                return -4;
            }
        }
    }
    
    return 1;	
}


// closes overlays
function cancel() {
    window.parent.Shadowbox.close();
}
