﻿// JScript File
function popup(mylink){
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href, 'Survey', 'width=790,height=800,scrollbars=yes,resizable=yes');
    return false;
}
function popImg(imgSrc,hi,wi){
    
    if (! window.focus)return true;
    var href;
    if (typeof(imgSrc) == 'string')
       href=imgSrc;
    else
       href=imgSrc.href;
       
    var newImg = new Image();
    newImg.src = imgSrc;
    var ht = hi + 50;
    var wd = wi + 50;
    
    window.open(href, 'popup', 'width='+wd+',height='+ht+',scrollbars=no,resizable=no');
    return false;
} 

function Set_Cookie( name, value, expires, path, domain ) 
{
    // set time in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    if ( expires ){
    expires = expires * 1000 * 60* 60 * 24;  //expires in x days
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" );
}

function Get_Cookie( check_name ) {
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; 
	
    for ( i = 0; i < a_all_cookies.length; i++ )
    {
	    a_temp_cookie = a_all_cookies[i].split( '=' );
	    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

	    if ( cookie_name == check_name )
	    {
		    b_cookie_found = true;
		    // need to handle case where cookie has no value but exists (no = sign, that is):
		    if ( a_temp_cookie.length > 1 )
		    {
			    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
		    }
		    // note that in cases where cookie is initialized but no value, null is returned
		    return cookie_value;
		    break;
	    }
	    a_temp_cookie = null;
	    cookie_name = '';
    }
    if ( !b_cookie_found )
    {
	    return null;
    }
}				

function initCookie(){
    if(!Get_Cookie('User_Cookie')){ 
        //If unique user then set cookie and display survey
        Set_Cookie('User_Cookie', 'Survey', 240, '/', '', '');  //cookie expires 8 months
        display('survey','hidden');
        TimeObject = setTimeout("displaySurvey()", 1000); //wait 1 secs to display cookie
    }else{
        //User has been here before - don't display surveyBox until cookie expires
        nosurvey();
    }
}
function display(sdiv, dvalue){
    document.getElementById(sdiv).style.visibility = dvalue;
}
function displaySurvey(){
    display('surveyModal','visible');
    document.getElementById('surveyModal').style.display = "block";
    display('surveyBox', 'visible');
    document.getElementById('surveyBox').style.display = "block";
}
function nosurvey(){
    display('surveyBox','hidden');
    display('survey','visible');
    display('surveyModal', 'hidden');
}
function takesurvey(){
    popup('survey.aspx'); 
    display('surveyBox', 'hidden');
    display('surveyModal', 'hidden');
}
function ismaxlength(obj){
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
    if (obj.getAttribute && obj.value.length>mlength)
        obj.value=obj.value.substring(0,mlength);
}
function showRate(shValue){
    document.getElementById("rate").style.display = shValue;
}  