﻿// JScript File

function magsSortChange(){
    obj = document.getElementById("selMagsSort");
    //alert(document.location.pathname)

    var tmp = ""
    var tmp2 = ""

    //tmp = document.location.pathname;
    tmp = document.location.toString();
    //alert(tmp) 

    tmp2 = tmp.indexOf("sort=");
    tmp3 = tmp.indexOf("&",tmp2);

    if (tmp2 > -1)
        {
        if (tmp3 == -1)
            {
            tmp = tmp.substr(0,tmp2)
            }
        else
            {
            //alert(tmp3)
            tmp = tmp.substr(0,tmp2) + tmp.substr(tmp3+1)
            } 
        }

    tmp = tmp.replace(/\?$/, "");
    tmp = tmp.replace(/&$/, "");

    //alert(tmp)    

    if (tmp.indexOf("?") > -1)
        {
        document.location = tmp + "&sort=" + obj.value;
        //alert(tmp + "&sort=" + obj.value);
        } 
    else
        {
        document.location = tmp + "?sort=" + obj.value;
        //alert(tmp + "?sort=" + obj.value);
        }
}


function xRenewOnOff() {
    //alert("aa");
    $("#xRenewReasonsText").slideToggle(600);
}


function doRemoteRequest(url) {
    if (window.XMLHttpRequest) 
        {              
        AJAX=new XMLHttpRequest();              
        } 
    else 
        {                                  
        AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        }
    if (AJAX) 
        {
        AJAX.open("GET", url, false);                             
        AJAX.send(null);
        return AJAX.responseText;                                         
        } 
    else 
        {
        alert("AJAX error")
        return false;
        }                                             
}

var user_screen_width = '';
var user_screen_height = '';
var xData = '';

function SetResolutionsValues() {
    if( typeof( window.innerWidth ) == 'number' ) 
        { 
        //Non-IE 
        user_screen_width = window.innerWidth;
        user_screen_height = window.innerHeight; 
        } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
        { 
        //IE 6+ in 'standards compliant mode' 
        user_screen_width = document.documentElement.clientWidth; 
        user_screen_height = document.documentElement.clientHeight; 
        } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
        { 
        //IE 4 compatible 
        user_screen_width = document.body.clientWidth; 
        user_screen_height = document.body.clientHeight; 
        } 
        
    xData += user_screen_width + "~" + user_screen_height
}

SetResolutionsValues();
//alert(xData);

var tmp = "";
var tmp2 = "";
var tmp3 = "";
var tmp4 = "";
var tmp5 = "";

tmp = document.location.toString();
//alert(tmp);


tmp5 = tmp.indexOf("localhost");
        
tmp2 = tmp.indexOf("/magazine/");

if (tmp2 > -1)
    {
    
    tmp4 = tmp.indexOf("magsconnect.ca");
    
    if (tmp4 > -1)
        {
        tmp3 = tmp.replace("http://www.magsconnect.ca","");
        
        xData += "~" + tmp3        
        //alert(xData);

        if (tmp5 > -1)
            {
            doRemoteRequest('http://localhost:1871/MagsExpress/ajax-client/client-specs.aspx?xData=' + xData);  
            }
        else
            {
            doRemoteRequest('http://www.magsconnect.ca/ajax-client/client-specs.aspx?xData=' + xData);
            }                              
        }
    else
        {
        tmp3 = tmp.replace("http://www.magsconnect.com","");
        
        xData += "~" + tmp3        
        //alert(xData);
        
        if (tmp5 > -1)
            {
            doRemoteRequest('http://localhost:1871/MagsExpress/ajax-client/client-specs.aspx?xData=' + xData);  
            }
        else
            {
            doRemoteRequest('http://www.magsconnect.com/ajax-client/client-specs.aspx?xData=' + xData);
            }         
        }       
    }       
