var ColResize = 0;


function ShowHide ( ID, Elem, Title, Class ) {

    if ( document.getElementById(ID).style.display !== 'block' ) {
        document.getElementById(ID).style.display = 'block';
        if ( Title !== '')
            Elem.innerHTML = Title[1];
        if ( Class !== '')
            Elem.className = Class[1];

    } else {
        document.getElementById(ID).style.display = 'none';
        if ( Title !== '' )
            Elem.innerHTML = Title[0];
        if ( Class !== '' )
            Elem.className = Class[0];

    }
    
}
function ShowHideMap ( ID, Elem, Title ) {

    if ( document.getElementById(ID).style.display !== 'block' ) {
        document.getElementById(ID).style.display = 'block';
        document.getElementById("List").className = 'List OnMap';
        Elem.innerHTML = Title[1];
    } else {
        document.getElementById(ID).style.display = 'none';
        document.getElementById("List").className = 'List';
        Elem.innerHTML = Title[0];
    }
}
function ResizeCol (e, LeftId, RightId) {
    
    if ( ColResize == 0 )
        return false;
        
    var posx = 0;
    var posy = 0;
    
    if (!e) 
        var e = window.event;    
    
    if (e.pageX || e.pageY) {

        posx = e.pageX;
        posy = e.pageY;

    } else if (e.clientX || e.clientY) {

        posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;

    }
    
    document.getElementById(LeftId).style.width = posx-27 + 'px';
    if ( posx >= 175 )
        document.getElementById(RightId).style.marginLeft = posx-15 + 'px';
    
}
function SetResizer () {
    document.getElementById('InfoLapaProdResizer').style.height = document.getElementById('ProdWrap').offsetHeight + 'px';
}


var ShowHideSetsVariables = new Array();
ShowHideSetsVariables['sr_districts0'] = '';
ShowHideSetsVariables['sr_districts1'] = '';
ShowHideSetsVariables['sr_districts2'] = '';
ShowHideSetsVariables['sr_districts3'] = '';
ShowHideSetsVariables['sr_districts4'] = '';
ShowHideSetsVariables['sr_districts5'] = '';
ShowHideSetsVariables['sr_districts6'] = '';
ShowHideSetsVariables['sr_districts7'] = '';
ShowHideSetsVariables['sr_districts8'] = '';
ShowHideSetsVariables['sr_districts9'] = '';
ShowHideSetsVariables['riga_streets'] = '';
ShowHideSetsVariables['reg_dis'] = '';

function ShowHideSets(ID, SetNum, Elem, ButtonClass, InitialState, StaticVariableName, ShowHideSetsArray)
	{
	if (ShowHideSetsVariables[StaticVariableName] == '')
		{
		ShowHideSetsVariables[StaticVariableName] = InitialState;
		}
		
	//alert(ShowHideSetsArray[2][2]);
	for (c = 0; c < ShowHideSetsArray[SetNum].length; c++)
		{
		if (ShowHideSetsVariables[StaticVariableName] == 'On')
			{
			if (ShowHideSetsArray[SetNum][c] > 0)
				{
				document.getElementById(ID + ShowHideSetsArray[SetNum][c]).style.display = 'none';
				}
			else
				{
				document.getElementById(ID + (-ShowHideSetsArray[SetNum][c])).style.display = 'block';
				}
			}
		else
			{
			if (ShowHideSetsArray[SetNum][c] > 0)
				{
				document.getElementById(ID + ShowHideSetsArray[SetNum][c]).style.display = 'block';
				}
			else
				{
				document.getElementById(ID + (-ShowHideSetsArray[SetNum][c])).style.display = 'none';
				}
			}
		}
	if (ShowHideSetsVariables[StaticVariableName] == 'On')
		{
		Elem.className = ButtonClass[1];
		//CurrentState = 'Off';
		ShowHideSetsVariables[StaticVariableName] = 'Off';
		//ChangeCSS('.' + ClassName, 'display', 'none');
		}
	else
		{
		Elem.className = ButtonClass[0];
		//CurrentState = 'On';
		ShowHideSetsVariables[StaticVariableName] = 'On';
		//ChangeCSS('.' + ClassName, 'display', 'block');
		}
	}

/*
function ShowHideByClass(ClassName, Elem, ButtonClass, InitialState, StaticVariableName)
	{

	if (ShowHideByClassVariables[StaticVariableName] == '')
		{
		ShowHideByClassVariables[StaticVariableName] == InitialState;
		}
		
	
	if (ShowHideByClassVariables[StaticVariableName] == 'On')
		{
		Elem.className = ButtonClass[1];
		//CurrentState = 'Off';
		ShowHideByClassVariables[StaticVariableName] = 'Off';
		ChangeCSS('.' + ClassName, 'display', 'none');
		}
	else
		{
		Elem.className = ButtonClass[0];
		//CurrentState = 'On';
		ShowHideByClassVariables[StaticVariableName] = 'On';
		ChangeCSS('.' + ClassName, 'display', 'block');
		}
		
	//alert(CurrentState);
	}


function ChangeCSS(theClass,element,value) {
	//Last Updated on October 10, 1020
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;

	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){

    if (document.styleSheets[S]['rules']) {
	  cssRules = 'rules';
	 } else if (document.styleSheets[S]['cssRules']) {
	  cssRules = 'cssRules';
	 } else {
	  //no rules found... browser unknown
	 }

	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }
	  if(!added){
	  try{
	  	document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);

	  } catch(err){
	  		try{document.styleSheets[S].addRule(theClass,element+': '+value+';');}catch(err){}

	  }

	  //if(document.styleSheets[S].insertRule){
			  //document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			//} else if (document.styleSheets[S].addRule) {
				//document.styleSheets[S].addRule(theClass,element+': '+value+';');
			//}
	  }
	 }
	}
	
*/


function Set_Cookie( name, value, expires, path, 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 * 60 * 24;

    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ";domain=" + cms1['domain'] +
    ( ( secure ) ? ";secure" : "" );

}

function Get_Cookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we 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 Delete_Cookie( name, path ) {
    if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ";domain=" + cms1['domain'] +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

