var ua = navigator.userAgent.toLowerCase();

if (ua.indexOf("msie") != -1) {
	var ver = parseFloat(ua.substring(ua.indexOf("msie ") + 5));
	if (ver <= 6) {
		document.write('<link rel="stylesheet" type="text/css" media="screen" href="css/styles_ie6.css" />');
	}
}

// alert("JavaScripts Directory is Active!");

/* HIDES EMAIL ADDRESS FROM SPAM SPIDERS */
function dispEmlAdr(emlPrf,emlDom,emlTld,cls,disp) {
	/* example: nobody@nowhere.com
			emlPrf = email prefix (e.g., nobody)  REQUIRED
			emlDom = email domain (e.g., nowhere)  REQUIRED
			emlTld = email top-level domain (e.g., com)  REQUIRED
		cls = class for link's CSS style  [optional]
		disp = text displayed for link  [optional; otherwise defaults to email addres]
	*/
	var q = '"';  //quote (") character (eliminates need to escape quotes)
	var s = '/';  //slash (/) character (eliminates need to escape slashes)
	document.write("<a href=" + q + "&#109;&#97;" + "&#105;&#108;" + "&#116;&#111;&#58;");
	document.write(emlPrf + "&#64;" + emlDom + "&#46;" + emlTld);
	document.write(q + " class=" + q + cls + q + ">");
	if (disp) {
		document.write(disp); //if "disp" has a value, "disp" is displayed
	} else {
		document.write(emlPrf + "&#64;" + emlDom + "&#46;" + emlTld);
		// otherwise, the actual email address is displayed on-screen
	}
	document.write("<" + s + "a>");
}


/* SELECTS A RADIO BUTTON WHEN ADJACENT FIELD IS ENTERED OR AN ADJACENT IMAGE OR ELEMENT IS CLICKED */
/*
function checkRadioBtn(id) {
	//insert name of form and radio buttons where indicated by angle brackets
	//(be sure to remove brackets)
	document.<formName>.<radioName>[id].checked = true;
}

//onfocus="checkRadioBtn(id);"  //use to select button on field entry

*/


/* FORMATS A NUMBER TO SPECIFIED NUMBER OF DECIMAL PLACES; CAN BE USED TO FORCE CURRENCY DISPLAY */
Number.prototype.toDecimals = function(n){
	//
	n=(isNaN(n))?
		2:
		n;
	var
		nT = Math.pow(10,n);
	function pad(s) {
			s = s || '.';
			return (s.length>n)?
				s:
				pad(s+'0');
	}
	return (isNaN(this))?
		this:
		(new String(
			Math.round(this*nT)/nT
		)).replace(/(\.\d*)?$/,pad);
}

//cost.toDecimals(2); //example of call to the method, where 'cost' is a previously defined variable


/* DETECTS ENTER KEY PRESS IN FORM FIELD AND PREVENT FORM SUBMISSION */
function detectEnterKey(e){ //event object passed from function invocation
	var characterCode; //stores ascii character code
	if(e && e.which){ //if which property detects Netscape
		e = e;
		characterCode = e.which; //captures ascii code for Netscape
	}else{
		e = event;
		characterCode = e.keyCode; //captures ascii code for IE
	}
	if(characterCode == 13){ //tests for ascii code for enter key
		alert("Click the \"Update\" button to modify the estimate values.");
		return false;
	}else{
		return true;
	}
}


/* TOGGLES CONTENT OF A BOX (BY ID) FROM VISIBLE TO HIDDEN */
function toggleBox(id) {
	if(!document.getElementById) return;
	var box = document.getElementById(id);
	if(box.className = 'box_hidden') {
		box.className = 'box_visible';
	}else{
		box.className = 'box_hidden';
	}
}


/* DISPLAYS ERROR MSG FOR NON-ACTIVE (NULL) LINKS */
function nullink(flag,msg) {
	if(flag == 1) {
		if(msg) {
			alert(msg);
		} else {
			//default msg if no custom msg is passed
			alert("This link is not yet active.");
		}
		return false;
	} else {
		return;
	}
}

/* REDIRECTS TO SPECIFIC URL AFTER THE SPECIFIC PROMPTED IS AGREED TO */
function confirmUrlRedirect ( url, additional_message ) {

    if ( additional_message ) {
        if ( confirm( additional_message ) ) {
            document.location = url
        }
    }
    else if ( confirm( "Are you sure you want to delete the selected item ?" ) ) {
        document.location = url
    }

}

/* SUBMITS FORM AFTER THE SPECIFIC PROMPTED IS AGREED TO */
function confirmFormSubmit( form_name, additional_message ) {

    var f = eval( 'document.' + form_name );

    if ( additional_message ) {
        if ( confirm( additional_message ) ) {
            f.submit();
        }
    }
    else if ( confirm( "Are you sure you want to delete the selected item ?" ) ) {
        f.submit();
    }

}


// Title: Tigra Color Picker
// URL: http://www.softcomplex.com/products/tigra_color_picker/
// Version: 1.1
// Date: 06/26/2003 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: picker.js and picker.html

var TCP = new TColorPicker();

function TCPopup(field, palette) {
	this.field = field;
	this.initPalette = !palette || palette > 3 ? 0 : palette;
	var w = 194, h = 240,
	move = screen ?
		',left=' + ((screen.width - w) >> 1) + ',top=' + ((screen.height - h) >> 1) : '',
	o_colWindow = window.open('picker.html', null, "help=no,status=no,scrollbars=no,resizable=no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
	o_colWindow.opener = window;
	o_colWindow.focus();
}

function TCBuildCell (R, G, B, w, h) {
	return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')"><img src="_images/color_picker/pixel.gif" width="' + w + '" height="' + h + '" border="0"></a></td>';
}

function TCSelect(c) {
	this.field.value = '#' + c.toUpperCase();
	this.win.close();
}

function TCPaint(c, b_noPref) {
	c = (b_noPref ? '' : '#') + c.toUpperCase();
	if (this.o_samp)
		this.o_samp.innerHTML = '<font face=Tahoma size=2>' + c +' <font color=white>' + c + '</font></font>'
	if(this.doc.layers)
		this.sample.bgColor = c;
	else {
		if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
		else if (this.sample.background != null) this.sample.background = c;
	}
}

function TCGenerateSafe() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i ++)
				s += this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 10);
		s += "</tr>";
	}
	return s;
}

function TCGenerateWind() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++)
				s += this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 10);
		s += "</tr>";
	}
	return s
}
function TCGenerateMac() {
	var s = '';
	var c = 0,n = 1;
	var r,g,b;
	for (j = 0; j < 15; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++){
				if(j<12){
				s += this.bldCell( 255-(Math.floor(j / 2) * 51), 255-(k * 51 + (j % 2) * 51 * 3),255-(i * 51), 8, 10);
				}else{
					if(n<=14){
						r = 255-(n * 17);
						g=b=0;
					}else if(n>14 && n<=28){
						g = 255-((n-14) * 17);
						r=b=0;
					}else if(n>28 && n<=42){
						b = 255-((n-28) * 17);
						r=g=0;
					}else{
						r=g=b=255-((n-42) * 17);
					}
					s += this.bldCell( r, g,b, 8, 10);
					n++;
				}
			}
		s += "</tr>";
	}
	return s;
}

function TCGenerateGray() {
	var s = '';
	for (j = 0; j <= 15; j ++) {
		s += "<tr>";
		for (k = 0; k <= 15; k ++) {
			g = Math.floor((k + j * 16) % 256);
			s += this.bldCell(g, g, g, 9, 7);
		}
		s += '</tr>';
	}
	return s
}

function TCDec2Hex(v) {
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}

function TCChgMode(v) {
	for (var k in this.divs) this.hide(k);
	this.show(v);
}

function TColorPicker(field) {
	this.build0 = TCGenerateSafe;
	this.build1 = TCGenerateWind;
	this.build2 = TCGenerateGray;
	this.build3 = TCGenerateMac;
	this.show = document.layers ?
		function (div) { this.divs[div].visibility = 'show' } :
		function (div) { this.divs[div].visibility = 'visible' };
	this.hide = document.layers ?
		function (div) { this.divs[div].visibility = 'hide' } :
		function (div) { this.divs[div].visibility = 'hidden' };
	// event handlers
	this.C       = TCChgMode;
	this.S       = TCSelect;
	this.P       = TCPaint;
	this.popup   = TCPopup;
	this.draw    = TCDraw;
	this.dec2hex = TCDec2Hex;
	this.bldCell = TCBuildCell;
	this.divs = [];
}

function TCDraw(o_win, o_doc) {
	this.win = o_win;
	this.doc = o_doc;
	var
	s_tag_openT  = o_doc.layers ?
		'layer visibility=hidden top=54 left=5 width=182' :
		'div style=visibility:hidden;position:absolute;left:6px;top:54px;width:182px;height:0',
	s_tag_openS  = o_doc.layers ? 'layer top=32 left=6' : 'div',
	s_tag_close  = o_doc.layers ? 'layer' : 'div'

	this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=181 align=center class=bd><tr><td align=center height=18><div id="samp"><font face=Tahoma size=2>sample <font color=white>sample</font></font></div></td></tr></table></' + s_tag_close + '>');
	this.sample = o_doc.layers ? o_doc.layers['sam'] :
		o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style

	for (var k = 0; k < 4; k ++) {
		this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding=0 cellspacing=0 border=1 align=center>' + this['build' + k]() + '</table></' + s_tag_close + '>');
		this.divs[k] = o_doc.layers
			? o_doc.layers['p' + k] : o_doc.all
				? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
	}
	if (!o_doc.layers && o_doc.body.innerHTML)
		this.o_samp = o_doc.all
			? o_doc.all.samp : o_doc.getElementById('samp');
	this.C(this.initPalette);
	if (this.field.value) this.P(this.field.value, true)
}

function CheckAccess(member_id){
	public_id = "public_"+ member_id;
	restrict_id = "restrict_sizes_"+ member_id;

	if ( document.getElementById(public_id).checked == true )
		document.getElementById(restrict_id).disabled = false;
	else{
		document.getElementById(restrict_id).checked = false;
		document.getElementById(restrict_id).disabled = true;
	}
}

function ChangeStatus(id, status){
	document.getElementById(id).innerHTML = status;
}

function ajaxUpdater(id,url) {
     new Ajax.Updater(id,url,{asynchronous:true});
}

function CheckConfirm(file) {
	 var status = confirm("Are you want to delete this entry?");
	 if ( status == true ){
	 	window.location.href = "index.php?m=ftpuploads&e=delete&csv="+file;
	 }
	 else
	 	return false;
}
