var ie6 = navigator.userAgent.indexOf('MSIE 6') > 0 ? true : false;
function css_correct(){
	var css = "";
	if(navigator.userAgent.toLowerCase().indexOf('firefox') > 0){
		css = "<link rel='stylesheet' type='text/css' href='css/ff.css'>";
	}
	document.write(css);
}
function populateFrame(){
	rand = rand || Math.floor(Math.random()*99999);
	morris.location.href = "shareyourstoryform.html?rand=" + rand;
}
function checkemail(str){
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		return true;
	} else {
		return false;
	}
}
function checkFile(src){
	var goodExt = /[^/].(?:jpg|jpeg|gif|bmp|png)/i;
	if(src.match(goodExt)){
		return true;
	} else {
		return false;
	}
}
function form_validate(){
	var fr = document.forms['ShareStoryForm'];
	
	if(fr.a04_Story.value == ""){
		handleError("Please enter your story.", fr.a04_Story);
		return;
	}
	if(fr.a01_Name.value == ""){
		handleError("Please enter your name.", fr.a01_Name);
		return;
	}
	if(!checkemail(fr.a02_Email_Address.value)){
		handleError("Please enter a valid email.", fr.a02_Email_Address);
		return;
	}

	if(fr.a03_Birth_Year.value == ""){
		handleError("Please select your birthdate.", fr.a03_Birth_Year);
		return;
	}
	if(fr.myFile.value == ""){
		handleError("Please select a file to upload.", fr.myFile);
		return;
	}
	if(!checkFile(fr.myFile.value)){
		handleError("Please select a .jpg, .jpeg, .gif, .bmp or .png file to upload.", fr.myFile);
		return;
	}
	if(!fr.check_confirm.checked){
		handleError("Please read and accept the terms and conditions", fr.check_confirm);
		return;
	}
	getObj('killbox').innerHTML = ""; // kill checkbox
	//parent.uploadReponse();
	fr.submit();
}
function handleError(msg, obj){
	getObj('errormsg').innerHTML = msg;	
	obj.focus();
	obj.className = 'err';
}
function getObj(obj){
	if(document.getElementById){
		return document.getElementById(obj);
	}
}
function show(id,top){
	if(top) getObj(id).style.top = top + "px";
	getObj(id).style.visibility = "visible";
} 
function hide(id){
	getObj(id).style.visibility = "hidden";
} 

function frmclear(which){
	which.className = '';
}
var y_coord;
function share_your_story(coord){
	y_coord = coord || 200;
	Math.floor(Math.random()*99999);
	morris.location.href = "shareyourstoryform.html?rand=" + rand;
	setTimeout('openContainer()', 200);
}
function openContainer(){
	show('morriscontainer',y_coord);
	show('morris');
}
function closeContainer(){
	hide('morriscontainer');
	hide('morris');
	thisMovie("dailies").popupClosed();
}

function show_terms(){
	show('terms');
	if(ie6) hide('offform');
}
function hide_terms(){
	hide('terms');
	if(ie6) show('offform');
}
function uploadReponse(){
	closeContainer();
	thisMovie("dailies").uploadComplete();
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
