﻿// JScript File
//clear textbox
function clearDefault(el) {
    if (el.defaultValue==el.value) el.value = "";
    el.style.color ="#000000";
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function fadein(id, millisec, toppx) {
    
    document.getElementById(id).style.display="block";
    document.getElementById(id).style.opacity = 0;
    /*document.getElementById(id).style.margin-top = toppx + 'px';*/
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 97, millisec);
    }
} 

function fadeout(id, millisec, toppx) {
    document.getElementById(id).style.display="none";
    document.getElementById(id).style.opacity = 0;
    /*document.getElementById(id).style.opacity = 0;*/
    /*document.getElementById(id).style.margin-top = toppx + 'px';*/
    /*
    if(document.getElementById(id).style.opacity == 1) {
        document.getElementById(id).style.opacity = 0;
        //opacity(id, 100, 0, millisec);
    }
    */
}

//Function to check al checkboxes in domaincheck
function CheckAll()
{
    
    count = document.forms[0].elements.length;
        
    var name="";
    var lengte = 0;
    var check = 1;
    
    /*
    if(document.forms[0].checkall.checked == 1){   
        check = 1;
        document.forms[0].checkall.checked = 0;
    } else {
        check = 0;    
        document.forms[0].checkall.checked = 1;
    }
    */

//    alert("checked = " + document.forms[0].checkall.checked + " and check = " + check);
    
    for (i=0; i < count; i++) 
	{
	    name = document.forms[0].elements[i].name;
	    lengte = name.length;
	    //alert("substr = " + name.substring(lengte-8,lengte)); 
    	if(name.substring(lengte-8,lengte)=="CB_order"){
	        //document.forms[0].elements[i].checked = check; 
	        document.forms[0].elements[i].checked = check; 
	    }
	    
	}
}

//Function to check invert checkboxes in domaincheck
function CheckInvert()
{
 
    count = document.forms[0].elements.length;   

    // If we don't set this enabled, we might end up having to click twice on "clickall"
    //document.forms[0].checkall.checked = 1;    
    
    var name="";
    var lengte = 0;
    
    for (i=0; i < count; i++) 
	{ 
	    name = document.forms[0].elements[i].name;
	    lengte = name.length;
    	if(name.substring(lengte-8,lengte)=="CB_order"){
	        if(document.forms[0].elements[i].checked){
	           document.forms[0].elements[i].checked = 0; 
	        }
	        else{
	            document.forms[0].elements[i].checked = 1;
	        }	        
	    }
	}
}

function CheckInvertRadio(e)
{
    count = document.forms[0].elements.length;
    var name="";
    var lengte = 0;
    
    for (i=0; i < count; i++) 
	{
	    name = document.forms[0].elements[i].name;
	    lengte = name.length;
    	if(name.substring(lengte-8,lengte)=="RB_order"){
	        if (e.name == name){
	            document.forms[0].elements[i].checked = 1;
	        }
	        else{
	            document.forms[0].elements[i].checked = 0;
	        }	        
	    }
	}
}

function ValidateCheckbox(id, error)
{
    var checkvalid = document.getElementById(id).checked;
    if(!checkvalid){
        alert(error);
        return false;
    }
    else{
        return true;
    }
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
    begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" + 
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// create expire date as GMT
// [dP] - date part like D(day) M(month) or Y(year)
// [aM] = augmenter the quantity added
function setExpDate(dP, aM) {
	var endDate = new Date();
	if(dP == "M") {
	    var expMonth = endDate.getMonth() + aM;
	    endDate.setMonth(expMonth);
	} else if(dP == "Y") {
	    var expYear = endDate.getFullYear() + aM;
	    endDate.setFullYear(expYear);
	} else {
	    var expHour = endDate.getHours() + (aM*24);
	    endDate.setHours(expHour);
	}
	var expire = endDate.toGMTString();
	/* make GMT string because some servers do not recognize toGMTString correctly*/
	var datePart = expire.split(" ");
	var GMTDate = datePart[0]+ " " +datePart[1]+ " " +datePart[2]+ " " +datePart[3]+ " " +datePart[4] + " GMT";
	return GMTDate
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

