function validateStory(){

	var frm = document.contestform;

	if(frm.CompanyName.value.length < 1){
		alert("Company name is required");
		frm.CompanyName.focus();
		return false;
	}

	if(frm.Industry.value == "none"){
		alert("Please select an industry.");
		frm.Industry.focus();
		return false;
      }

	if(frm.FirstName.value.length < 1){
		alert("First name is required");
		frm.FirstName.focus();
		return false;
	}

	if(frm.LastName.value.length < 1){
		alert("Last name is required");
		frm.LastName.focus();
		return false;
	}

	if(frm.Email.value.length < 1){
		alert("Email is required");
		frm.Email.focus();
		return false;
	}

	if(frm.NetworkNodes.value.length < 1){
		alert("Network nodes is required");
		frm.NetworkNodes.focus();
		return false;
	}

	if(frm.Bandwidth.value.length < 1){
		alert("Bandwidth is required");
		frm.Bandwidth.focus();
		return false;
	}

	if(frm.screenshot.value.length > 1){
		var url = frm.screenshot.value;
		if(!url.match(/\.jpg/i)){
			alert("Image files need to be in jpg format.");
			frm.screenshot.focus();
			return false;
		}
	}

	if(frm.Story.value.length < 1){
		alert("Please provide your story.");
		frm.Story.focus();
		return false;
	}

	return true;
}

function loadStory(id){
	grayOut(50,"");
	AjaxCall("index.php?c=contest&m=entrydetail&idContest=" + id,"LoadDetails");
}

function LoadDetails(data){
	//alert('test' + data);
	var width = ((getSize("width") - 751)/2);

		//var test = document.getElementById("popupdetail");
		//alert(test);
	if(document.getElementById("popupdetail")){
		var test = document.getElementById("popupdetail");
		test.style.display='block';
	}else{
		var test = document.createElement("div");
		test.setAttribute("id","popupdetail");
	}
	test.style.position="absolute";
	test.style.top="150px";
	test.style.left=width + "px";
	test.style.zIndex=160;	
	test.style.color='#FF0000';
	test.innerHTML = data;
	document.body.appendChild(test);
}



function closeStory(){
	var fv = document.getElementById("popupdetail");
	fv.style.display='none';
	grayOut(false,"");
}



function getSize(wh){
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );

	if(wh == "height"){
		return myHeight;
	}else{
		return myWidth;
	}
}


function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

function AjaxCall(url,callback){
     var xmlHttp;

     try {
          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
     } catch (e) {
          // Internet Explorer
          try {
               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
               try {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;
               }
          }
     }

     xmlHttp.onreadystatechange=function() {
          if(xmlHttp.readyState==4) {
               eval(callback)(xmlHttp.responseText);
          }
     }
     xmlHttp.open("POST",url,true);
     xmlHttp.send(null);
}


