IsIE = (document.all);
IsNS = (document.layers);

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")||(parseInt(appVersion)==4)) {
    document.MM_pgW=this.innerWidth; document.MM_pgH=this.innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
//MM_reloadPage(true);

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function CheckForm(f) 
{
	var bConfirm = false;
	var bDisable = false;
	var bDisableR = false;
	var groupError = false;
	var errorMode = 0;
	//return;
	return validateForm( f, bConfirm, bDisable, bDisableR, groupError, errorMode );
}
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;
/*
<tr 
onmouseover="setPointer(this, 0, 'over', '#DDDDDD', '#CCFFCC', '#FFCC99');" 
onmouseout="setPointer(this, 0, 'out', '#DDDDDD', '#CCFFCC', '#FFCC99');" 
onmousedown="setPointer(this, 0, 'click', '#DDDDDD', '#CCFFCC', '#FFCC99');"
>
*/
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/*
 * Sets/unsets the pointer and marker in vertical browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 *
 * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
 */
function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        domDetect    = false;
    } // end 3

    var c = null;
    // 5.1 ... with DOM compatible browsers except Opera
    for (c = 0; c < rowCellsCnt; c++) {
        if (domDetect) {
            currentColor = theCells[c].getAttribute('bgcolor');
        } else {
            currentColor = theCells[c].style.backgroundColor;
        }

        // 4. Defines the new color
        // 4.1 Current color is the default one
        if (currentColor == ''
            || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
            || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
            if (theAction == 'over' && thePointerColor != '') {
                newColor              = thePointerColor;
            } else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.2 Current color is the pointer one
        else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
                 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
            if (theAction == 'out') {
                if (c % 2) {
                    newColor              = theDefaultColor1;
                } else {
                    newColor              = theDefaultColor2;
                }
            }
            else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.3 Current color is the marker one
        else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
            if (theAction == 'click') {
                newColor              = (thePointerColor != '')
                                      ? thePointerColor
                                      : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
                marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                      ? true
                                      : null;
            }
        } // end 4

        // 5. Sets the new color...
        if (newColor) {
            if (domDetect) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
            // 5.2 ... with other browsers
            else {
                theCells[c].style.backgroundColor = newColor;
            }
        } // end 5
    } // end for

     return true;
 } // end of the 'setVerticalPointer()' function

function Replace(asString, asSearch, asReplace){
	ysTemp = asString.split(asSearch);
	return ysTemp.join(asReplace);
}

function jsLeft(asString, aiLength){
	var iStrLen = asString.length;
	return asString.substring(0, aiLength);
}
function jsRight(asString, aiLength){
	var iStrLen = asString.length;
	return asString.substring(asString.length - aiLength, asString.length);
}

function jsDateAdd(asInterval, aiNumber, adtDate){
	var dtOldDate = new Date(adtDate);
	var iOldVarDate = dtOldDate.valueOf();
	var iNewVarDate = iOldVarDate;
	var iAddNum = 0;
	var iSecUnit = 1000;
	var iMinUnit = iSecUnit * 60;
	var iHourUnit = iMinUnit * 60;
	var iDayUnit = iHourUnit * 24;
	var iWeekUnit = iDayUnit * 7;
	
	switch (asInterval){
		case "s" : 
			iAddNum = aiNumber * iSecUnit;
			iNewVarDate += iAddNum;
			break;
		case "n" : 
			iAddNum = aiNumber * iMinUnit;
			iNewVarDate += iAddNum;
			break;
		case "h" : 
			iAddNum = aiNumber * iHourUnit;
			iNewVarDate += iAddNum;
			break;
		case "d" : 
			iAddNum = aiNumber * iDayUnit;
			iNewVarDate += iAddNum;
			break;
		case "w" : 
			iAddNum = aiNumber * iWeekUnit;
			iNewVarDate += iAddNum;
			break;
		case "m":
			iNewVarDate =  jsDateAddMonth(aiNumber, adtDate);
			break;
		case "y":
			iNewVarDate =  jsDateAddMonth(aiNumber * 12, adtDate);
			break;
	}
	var dtReturnDate = new Date(iNewVarDate);
//	alert(iAddNum+"\n"+dtOldDate + "\n" +dtReturnDate);
	return dtReturnDate;
}

function jsDateAddMonth(aiNumber, adtDate){
	var dtOldDate = new Date(adtDate);
	var iSec = dtOldDate.getSeconds();
	var iMin = dtOldDate.getMinutes();
	var iHour = dtOldDate.getHours();
	var iDay = dtOldDate.getDate();
	var iMonth = dtOldDate.getMonth();
	var iYear = dtOldDate.getYear();
	var iYearChange = 0;

	iMonth += aiNumber;

	iYearChange = Math.ceil(iMonth / 12);
	iYear += iYearChange;
	iMonth -= iYearChange * 12;

	var dtReturnDate = new Date(iYear, iMonth, iDay, iHour, iMin, iSec);
	return dtReturnDate.valueOf();
}

function jsFormatDate(aoDate, asStyle){
	var dtDate = new Date(aoDate);
	
	var sFormatDate = jsRight('0000'+dtDate.getFullYear(), 4) + '/' + jsRight('00'+(dtDate.getMonth()+1), 2) + '/' + jsRight('00'+dtDate.getDate(), 2);
	return sFormatDate;

}

function FormatNumber (asNum, aiDecPlace) {
	var f = CDbl(asNum);
	if (f == NaN) {
		return NaN;
	}
	var d = Math.pow(10, aiDecPlace);
	f *= d;
	f = Math.round(f) / d;
	s = f.toString();
	dp = s.indexOf(".");
	if (dp == -1) {
		dp = s.length;
	}

	intPart = s.substr(0, dp);
	decPart = s.substr(dp+1, s.length) + RepeatString("0", aiDecPlace);
	decPart = decPart.substr(0, aiDecPlace);

	return AddComma(intPart, 3) + "." + decPart;
}
function AddComma(asString, aiPartLength){
	var ysTemp = String2Array(asString, aiPartLength);
	return ysTemp.join(",");
}

function String2Array(asString, aiPartLength){
	var iStrLen = asString.length;
	var ysArray = new Array();
	var sTemp = asString;
	var i = 0;
	var j = 0;
	
	do {
		var start = asString.length-aiPartLength;
		if (start < 0) {
			start = 0;
		}
		sTemp = asString.substr(start, asString.length);
		if (sTemp == ""){
			break;
		}
		ysArray[i] = sTemp;
		j += aiPartLength;
		asString = asString.substr(0, asString.length-aiPartLength);
		i++;
	} while (j <= iStrLen);
	ysArray.reverse();
	return ysArray;
}

function RepeatString(asString, iNoOfTime){
	var s = "";
	for (var i = 0; i<iNoOfTime; i++){
		if (i>5)
		{
			return;
		}
		s += asString;
	}
	return s;
}
function CDbl(asNum){
	var x = Replace(asNum + '', ",", "");

	return parseFloat(x);
}
function CDbl_to_0(asNum){
	var x = CDbl(asNum);
	if ( isNaN(x) )
	{
		x = 0.0;
	}
	return x;
}

function PreviewHTML(oText) {
	var s = oText.value;
	win = window.open(", ", 'Preview', 'toolbar = no, status = no');
	win.document.write("" + s + "");
	win.document.close();
	win.window.focus();
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
	countfield.value = maxlimit - field.value.length;
}

function IsValidEmail(asTempString)
{
   var atCount = 0;
   var periodCount = 0;
   var strLen = asTempString.length;
   var i;
   var temp;
   var validchar= /^\w|[@.-]$/; //valid char = a-z, A-Z, @ , . , _ , -

   if (asTempString == '')
     return false;
     
   for (i = 0; i < strLen; i++)
      {
      temp = asTempString.substring(i, i+1);
	  if (temp == '@') 
         atCount++;
      if (temp == '.') 
         periodCount++;
	  if (!validchar.test(temp)){
//		alert(temp)
		return false;
		}
	  }
   if ((atCount == 1) && (periodCount > 0))
      return true;
   else
      return false;

}


function SetSelectedIndex(aoSelect, asFindValue){
	for (i=0; i < aoSelect.options.length; i++) {
		if (asFindValue == aoSelect.options[i].value) {
			aoSelect.options.selectedIndex = i;
			return;
		}
	}
}


function ClearFormValues(f, asExceptNameList) {
	var ysNameList = new Array();
	if (asExceptNameList != "") {
		ysNameList = asExceptNameList.split(",");
	}
	for (var i = 0; i < f.elements.length; i++) {
		var bClear = true;
		for (var j = 0; j < ysNameList.length; j++) {
			if (f.elements[i].name == ysNameList[j]) {
				bClear = false;
				break;
			}
		}
		if (bClear) {
			f.elements[i].value = "";
		}
	}
}
var iLastCheckedIndex = -1;
function AtLeastCheckedOne(objCheckboxRadio){
	var bCheckedOne = 0;
	iLastCheckedIndex = -1;

	if (objCheckboxRadio.length) {
		for (var i = 0; i < objCheckboxRadio.length; i++) {
			if (objCheckboxRadio[i].checked) {
				bCheckedOne = 9;
				iLastCheckedIndex = i;
				break;
			}
		}
	} else {
		if (objCheckboxRadio.checked) {
				bCheckedOne = 1;
				iLastCheckedIndex = 0;
		}
	}
	return bCheckedOne;
// 0 = no selected
// 1 = selected and the radio / checkbox has only ONE option
// 9 = selected and the radio / checkbox has MORE THAN ONE options

}

function Check_All(aoform, sParentName, sChildName, IsChecked){
	var CallUserFunction = null;
	if (arguments.length > 4) {
		CallUserFunction = arguments[4];
	}
	for (var i=0;i<aoform.elements.length;i++) {
		var e = aoform.elements[i];
		if (e.type == 'checkbox' && (e.name == sParentName || e.name == sChildName)) {
			e.checked = IsChecked;
			if ( e.name == sChildName && CallUserFunction) {
				CallUserFunction(e);
			}
		}
	}
}
function Remove_Check_All(aoCheckboxEle, aoform, sParentName){
	if (!aoCheckboxEle.checked){
		for (var i=0;i<aoform.elements.length;i++) {
			var e = aoform.elements[i];
			if (e.type == 'checkbox' && (e.name == sParentName)) {
				e.checked = false;
			}
		}
	}
}
function OptionSelectedValue(aoSelect){
	return aoSelect.options[aoSelect.options.selectedIndex].value;
}


function SetAllDisabled(sExceptList) {
	//use readonly -> disabled
	var elm = document.form1.elements;
	var b = false;
	if (!elm ) {
			return;
	}
	var l = sExceptList.split(",");

	for (var i = 0; i < elm.length; i++) {
		switch (elm[i].type) {
			case "select-one":
			case "select-multiple":
			case "text":
			case "textarea":
			case "file":
			case "checkbox":
			case "radio":
				b = false;
				for (var j =0; j < l.length; j++) {
					if (l[j].length > 0 && l[j] == elm[i].name) {
						b = true;
						break;
					}
				}
				if (!b) {
					elm[i].disabled = true;
//					elm[i].readonly = true;
				}
				break;
		}
	}
}



// function to check a valid date
//------------------------------------------------------------------------------
var lsDateIn="", lsMonthIn ="", lsYearIn="" //local variables

function IsDate(asDateStringIn){ //return error message
	if (!ValidDateFormat(asDateStringIn)) return "Invalid Format";

	if (!GetDateMonthYear(asDateStringIn)) return "Data Missing...";
	var dDate = new Date(lsYearIn,lsMonthIn-1,lsDateIn);

	var sDateStringOut = dDate.getFullYear() + "\/" + (dDate.getMonth()+ 1) + "\/" + dDate.getDate();
	var sDateStringIn = lsYearIn + "\/" + lsMonthIn + "\/" + lsDateIn ;
	if (sDateStringOut != sDateStringIn) return "Out Of Range" ;
	return "";
}

function ValidDateFormat(asDateStringIn){
	opatternDateFormat = /^(\d{4}\/\d{1,2}\/\d{1,2})$/; // mm/dd/yyyy 
	return opatternDateFormat.test(asDateStringIn);
}

function GetDateMonthYear (asDateStringIn){
	var yDateString = asDateStringIn.split("/");
	if (yDateString.length != 3 ) return false;
	
	lsYearIn = yDateString[0];
	lsMonthIn = parseInt(yDateString[1], 10);
	lsDateIn = parseInt(yDateString[2], 10);
	return true;
}
//------------------------------------------------------------------------------

//function to check a valid time
//------------------------------------------------------------------------------
var lsHourIn = "", lsMinuteIn = "", lsSecondIn = "";

function IsTime(asTimeStringIn){ //return error message
	if (!ValidTimeFormat(asTimeStringIn)) return "Invalid Format";

	if (!GetHourMinuteSecond(asTimeStringIn)) return "Data Missing...";
	
	if ((lsHourIn > 23) || (lsHourIn < 0)) return "Out Of Range" ;
	if ((lsMinuteIn > 59) || (lsMinuteIn < 0)) return "Out Of Range" ;
	if ((lsSecondIn > 59) || (lsSecondIn < 0)) return "Out Of Range" ;
	return "";
}

function ValidTimeFormat(asTimeStringIn){
	opatternTimeFormat = /^(\d{2}:\d{2}|\d{2}:\d{2}:\d{2})$/; // 00:00 or 00:00:00
	return opatternTimeFormat.test(asTimeStringIn);
}

function GetHourMinuteSecond (asTimeStringIn){
	var yTimeString = asTimeStringIn.split(":");
	if (yTimeString.length == 2) {
		lsHourIn = parseInt(yTimeString[0], 10);
		lsMinuteIn = parseInt(yTimeString[1], 10);
		lsSecondIn = 0;
		return true
		}
	if (yTimeString.length == 3) {
		lsHourIn = parseInt(yTimeString[0], 10);
		lsMinuteIn = parseInt(yTimeString[1], 10);
		lsSecondIn = parseInt(yTimeString[2], 10);
		return true
		}
	return false;
}
//------------------------------------------------------------------------------


var expDays = 1; // number of days the cookie should last
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
   }
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function form_get_value ( elem )
{
	var args = arguments;  

	var return_string_value = (args.length > 1) ? args[1] : false;
	var return_string_value_join_with = (args.length > 2) ? args[2] : ",";

	if (typeof(elem) == 'undefined')
	{
		return '';
	}

	if ( elem.length && (elem.type != 'select-one' && elem.type != 'select-multiple') )
	{
		choice = ( elem[0].type == 'checkbox' || elem[0].type == 'radio' ) ? "checked" : "selected";
		var returnValues = new Array();
		for ( var i = 0; i < elem.length; i++ )
		{
			if ( elem[i][choice] )
			{
				returnValues.push( elem[i].value );
			}
		}
		if (return_string_value)
		{
			return returnValues.join(return_string_value_join_with);
		}
		else
		{
			return returnValues;
		}
	}
	else
	{
		switch ( elem.type )
		{
			case 'text' :
			case 'password' :
			case 'textarea' :
			case 'hidden' :
			case 'file' :
				return elem.value;
			case 'radio':
			case 'select-one':
				if ( typeof elem.length == 'undefined' )
				{
					return elem.value;
				} else {
					for ( var i = 0; i < elem.length; i++ )
					{
						choice = ( elem.type == 'radio' ) ? "checked" : "selected";
						if ( elem[i][choice] )
						{
							return elem[i].value;
						}
					}
				}
			case 'select-multiple' :
			case 'checkbox' :
				if ( typeof elem.length == 'undefined' )
				{
					if (elem.checked) {
						return elem.value
					}
					else {
						return '';
					}
				} else {
					var returnValues = new Array();
					for ( var i = 0; i < elem.length; i++ )
					{
						choice = ( elem.type == 'checkbox' ) ? "checked" : "selected";
						if ( elem[i][choice] )
						{
							returnValues.push( elem[i].value );
						}
					}
					if (return_string_value)
					{
						return returnValues.join(return_string_value_join_with);
					}
					else
					{
						return returnValues;
					}

				}
			default: return '';
		}
	}
}

function set_options(obj_sel, select_options) {
     var op = null;
	 
	 obj_sel.length = 0;
	 for (var i =0; i < select_options.length; i++) {
          op = new Option();
          op.value = select_options[i][0];
          op.text = select_options[i][1];
          obj_sel[i] = op;
     }
}

function date_convert(input)
{
	var a = input.value;
	if (a.length != 10)
	{
		day = a.substring(0,2);
		month = a.substring(2,4);
		year = a.substring(4,8);
//		alert("year:"+year);
//		alert("month:"+month);
//		alert("day:"+day);
		datestring = day + "/" + month + "/" + year;
		if(datestring.length ==2)
		{
			datestring = "";
		}
		input.value = datestring;
	}
}

function date_unconvert(input)
{
	var a = input.value;
	if (a.length == 10)
	{
		day = a.substring(0,2);
		month = a.substring(3,5);
		year = a.substring(6,10);
//		alert("year:"+year);
//		alert("month:"+month);
//		alert("day:"+day);
		datestring = day +  month +  year;

		input.value = datestring;
	}
}

function checkbox_radio_set_checked_by_value (obj, values, reset_all_to_unchecked) {
	if ( obj.length == undefined )
	{
		if ( reset_all_to_unchecked )
		{
			obj.checked = false;
		}
		for (var k =0; k< values.length; k++)
		{
			if ( values[k] == obj.value ) {
				obj.checked = true;
			}
		}
	}
	else
	{
		for (var i = 0; i < obj.length; i++)
		{
			if ( reset_all_to_unchecked )
			{
				obj[i].checked = false;
			}
			for (var k =0; k < values.length; k++)
			{
				if ( values[k] == obj[i].value ) {
					obj[i].checked = true;
				}
			}

		}
	}
}

function ChangeLang(lang) {
	var u = window.location.href;
	var s = 'updatelang.php?lang=' + lang + '&url=' + escape(u);
	top.location.replace(s);
}

function addToCart(f,qty_elm){
	f.qty.value=document.getElementById(qty_elm).value;
	f.submit();
}