// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=950,height=700,left = 269.5,top = -16');");
}


function checkMobile() {
	mobil_1 = document.getElementById('msisdn1').value;
	mobil_2 = document.getElementById('msisdn2').value;
	mobil_3 = document.getElementById('msisdn3').value;

	if(mobil_1.length != 3 || mobil_2.length != 3 || mobil_3.length != 4) { 
		alert("Please enter your cell phone number!"); 
		return false;} 
	if(isNaN(mobil_1) || isNaN(mobil_2) || isNaN(mobil_3)) { 
		alert("Please enter a valid cell phone number."); 
		return false;}
	if(document.getElementById('network').value == ""){
		alert ('Please select your cell phone company');
		return false;}
	if(mobil_1.charAt(0) == 1 || mobil_1.charAt(0) == 0) { 
		alert("Cell Number must not start with 0 or 1. Please enter a valid cell phone number.");
		return false;}
		
	return true;
}


//Check the phone
function checkPhoneError(value) {
	if (value == 'badMsisdn') {
		alert('Invalid Phone Number' );
	} else if ( value == 'unsupported' ) {
		alert('Sorry your network is not currently supported' );
	} else if ( value == 'lookupfailed') {
		alert('Unable to determine your carrier. Please try again later' );
	}
	
}


function checkPin() {
	pin = document.getElementById('password').value;

	if(pin == "") { 
		alert("Please enter your PIN number."); 
		return false;} 
	if(document.getElementById('terms').checked == false) {
			alert('Please agree the terms of service!');
			return false;}
		
	return true;
}
	
function checkPwdError(value1) {
	
	if(value1== 'badpassword') {
		alert('Please enter your correct PIN' );
	}
x
	return true;
	
}


function checktitle(saved)
{
	if(document.getElementById(saved).value == '') return false;
}

function updateSelectedTitle(value,saveto)
{
	document.getElementById(saveto).value = value;
}

function getqstring(variable) 
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}

var url = location.href;
var filename = url.split('/'); filename = filename[filename.length-1];

function do_search(formid,e,a)
{
	if(isenter(e))
	{
		YY_checkform('searchTitle','searchtext','#q','0','Please enter your search criteria');
		
		if(document.MM_returnValue)
		{
			formid.action = a;
	        formid.submit();
	        return true;
		}
		
		return false;
	}
}



function isenter(e)
{
	e = e || window.event;
	if (e.keyCode == 13) {
        return true;
    }
    
    return false;
}

function entersubmit(formid,e,a)
{
	e = e || window.event;
    if (e.keyCode == 13) {
    	formid.action = a;
        formid.submit();
        return true;
    }
}

function addInputSubmitEvent(form, input) {
    input.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) {
            form.submit();
            return false;
        }
    }
}

function addSelectSubmitEvent(form, select, submit) {
    select.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) {
            submit.click();
            return false;
        }
    }
}




function addSubmitEvent() {
    var forms = document.getElementsByTagName('form');

    for (var i=0;i < forms.length;i++) {
        var inputs = forms[i].getElementsByTagName('input');
        var selects = forms[i].getElementsByTagName('select');

        for (var j=0;j < inputs.length;j++) {
        	if(inputs[j].type == 'image' || inputs[j].type == 'submit')
        	{
        		var submit = inputs[j];
        	}
        	
            addInputSubmitEvent(forms[i], inputs[j]);
		}
            
        for (var k=0;k < selects.length;k++) {
            addSelectSubmitEvent(forms[i], selects[k], submit);
		}
    }
}

//validating name

function isEmpty(elem, helperMsg){
		if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
		}
		return true;
		}


//Validating Phone Number (This one is got the API in it it's kind of cool isn't it!)



//Jump
function xx(o, x, obj)
{
	if (o.value.length == x)
		eval(obj).focus();
}

