/*Javascript Code for making the frames move*/

function closeFrame(num){
	document.getElementById('container' + num).style.display='none';
	switch(num){
		case 0:
			if(isVisible(1)){
				fillRow(1);
			} else if(isVisible(2)){
				fillColumn(2);
			}
			if(!isVisible(1)){
				fillColumn(3);
			}
		break;
		case 1:
			if(isVisible(0)){
				fillRow(0);
			} else if(isVisible(3)){
				fillColumn(3);
			}
			if(!isVisible(0)){
				fillColumn(2);
			}
		break;
		case 2:
			if(isVisible(3)){
				fillRow(3);
			} else if(isVisible(0)){
				fillColumn(0);
			}
			if(!isVisible(3)){
				fillColumn(1);
			}
		break;
		case 3:
			if(isVisible(2)){
				fillRow(2);
			} else if(isVisible(1)){
				fillColumn(1);
			}
			if(!isVisible(2)){
				fillColumn(0);
			}
		break;
	}
	if(!(isVisible(0) || isVisible(1) || isVisible(2) || isVisible(3))){
		document.getElementById("reloadLink").style.display = "block";
	}
}

function changeSrc(frame){
	gotourl = prompt('What URL would you like to go to?');
	if(isValidURL(gotourl)){
		document.getElementById('frame' + frame).src = gotourl;
	} else if(isValidURL("http://"+gotourl)){
		document.getElementById('frame' + frame).src = "http://"+gotourl;
	} else{
		alert("That URL is not valid. Please put an 'http://' at the beginning, and make sure you are entering a valid URL!");
	}
}

function isValidURL(url){
    var RegExp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 

function isVisible(frame){
	return(document.getElementById('container' + frame).style.display != 'none');
}

function fillRow(frame){
	allGoogles[frame].style.width = width + "px";
}

function fillColumn(frame){
	allGoogles[frame].style.height = height + "px";
}

function fillAll(frame){
	allGoogles[frame].style.width = width + "px";
	allGoogles[frame].style.height = height + "px";
}