﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus1 = 0;

//loading popup with jQuery magic!
function loadPopup1(){
	//loads popup only if it is disabled
	if(popupStatus1==0){
		$("#backgroundPopup1").css({
			"opacity": "0.79"
		});
		$("#backgroundPopup1").fadeIn("slow");
		$("#popupContact1").fadeIn("slow");
		popupStatus1 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup1(){
	//disables popup only if it is enabled
	if(popupStatus1==1){
		$("#backgroundPopup1").fadeOut("slow");
		$("#popupContact1").fadeOut("slow");
		popupStatus1 = 0;
	}
}

//centering popup
function centerPopup1(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	//alert(screen.height);
	var popupHeight = $("#popupContact1").height();
	var popupWidth = $("#popupContact1").width();
	//centering
	$("#popupContact1").css({
		"position": "absolute",
		"top": 180,
		"left": 100,
		"z-index":1000
	});
	//only need force for IE6
	
	$("#backgroundPopup1").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	
		//centering with css
		centerPopup1();
		//load popup
		loadPopup1();
	
                 
                  	hideAuto(); 
					

			
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClick1").click(function(){
		disablePopup1();
	});
	$("#popupContactClose1").click(function(){
		disablePopup1();
	});
	$("#popupNoThanks1").click(function(){
		disablePopup1();
	});
	//Click out event!
	/*$("#backgroundPopup").click(function(){
		disablePopup();
	});*/
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus1==1){
			disablePopup1();
		}
	});

});
function hideNow1(){

//$('#moreinfo').click();
//$('#moreinfo').trigger('click');
//$("#moreinfo").one("click", function() {
  //window.location="/awards.htm";
//});
sai_user=getCookie('sai_user');

if (sai_user==null || sai_user=="")
  {
	document.getElementById("moreinfo").click();
	Set_Cookie('sai_user','guest',10);
  }


 //$("#moreinfo").one("click", function() {});



	//$('#moreinfo').click();
}

function hideAuto()
{var hide = setTimeout("hideNow1()",5000);
}
/*function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
   // set time, it's in milliseconds
   var today = new Date();
   today.setTime( today.getTime() );
   // if the expires variable is set, make the correct expires time, the
   // current script below will set it for x number of days, to make it
   // for hours, delete * 24, for minutes, delete * 60 * 24
   if ( expires )
   {
      expires = expires * 1000 * 60;
   }
   //alert( 'today ' + today.toGMTString() );// this is for testing purpose only 60 * 24
   var expires_date = new Date( today.getTime() + (expires) );
   //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

   document.cookie = name + "=" +escape( value ) +
      ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
      ( ( path ) ? ";path=" + path : "" ) +
      ( ( domain ) ? ";domain=" + domain : "" ) +
      ( ( secure ) ? ";secure" : "" );
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
