﻿function numbersonly(myfield, e) {

    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if (iscontrolkey(key)) return true;
    // numbers or decimal
    else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else return false;
}

function numbersonlyPlus(myfield, e) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if (iscontrolkey(key)) return true;
    // numbers or decimal
    else if ((("0123456789+").indexOf(keychar) > -1)) return true;
    else return false;
}

function numbersonlyExtention(myfield, e) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if (iscontrolkey(key)) return true;
    // numbers or decimal
    else if ((("0123456789x").indexOf(keychar) > -1)) return true;
    else return false;
}

function iscontrolkey(key) {
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) ||
			(key == 63232) || (key == 63233) || (key == 63234) || (key == 63235) || (key == 63272)) return true;
}

function changeform() {
    //alert(Page_Validators[0].isvalid);
    for (i = 0; i < Page_Validators.length; i++) {
        flag_vali = false;
        for (j = 0; j < i; j++) {
            if (Page_Validators[j].controltovalidate == Page_Validators[i].controltovalidate) {
                flag_vali = true;
                if (Page_Validators[j].isvalid == true) {
                    if (Page_Validators[i].isvalid == true) {
                        $("#" + Page_Validators[i].controltovalidate).removeClass('required');
                    }
                    else {
                        $("#" + Page_Validators[i].controltovalidate).addClass('required');
                    }
                }
            }
        }
        if (flag_vali == false) {
            if (Page_Validators[i].isvalid == true) {
                $("#" + Page_Validators[i].controltovalidate).removeClass('required');
            }
            else {
                $("#" + Page_Validators[i].controltovalidate).addClass('required');
            }
        }


    }
}

function showhidePanel(objDiv) {
    var divsearch = document.getElementById(objDiv).style;
    if (divsearch.display == "none")
        divsearch.display = "block";
    else
        divsearch.display = "none";
};

/*
Created By: Chris Campbell
Website: http://particletree.com
Date: 2/1/2006

Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
*/
//var enableDeactive=1;
//Event.observe(window, 'load', initializeCProject, false);
//function initializeCProject()
//{
//    //initialize();
//   
//};
/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, total, thestring;

/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
    if (checkIt('konqueror')) {
        browser = "Konqueror";
        OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari";
    else if (checkIt('omniweb')) browser = "OmniWeb";
    else if (checkIt('opera')) browser = "Opera";
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab";
    else if (checkIt('msie')) browser = "Internet Explorer";
    else if (!checkIt('compatible')) {
        browser = "Netscape Navigator";
        version = detect.charAt(8);
    }
    else browser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);

    if (!OS) {
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac";
        else if (checkIt('win')) OS = "Windows";
        else OS = "an unknown operating system";
    }
};

getBrowserInfo();

function checkIt(string) {
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
};

/*-----------------------------------------------------------------------------------------------*/


// -------------------- move.js --------------------//

/* This script moves the quick nav layer up and down */

var ypos=-275;
var endPos = -1;
var Id=0;
var direction = "down"
var topMenu = "up";

function startmove(dir) {
	// set direction and start
	direction = dir;
	if (direction == "down") {
		MM_showHideLayers('qnd','','hide');
		MM_showHideLayers('qnu','','show');
		endPos = -60;
		playFlash("false");
	} else {
		MM_showHideLayers('qnd','','show');
		MM_showHideLayers('qnu','','hide');
		endPos = -190;
	}
	if (!Id) {
		movemenu();
	}	
};

function movemenu() {
	yPos1 = ypos;
	yPos2 = endPos;
	yTotalDist = yPos2-yPos1;
	ySpeed = yTotalDist/4;
	ypos += ySpeed;
	if (document.layers) {
		document.hContainer.top=ypos;
	}
	if (document.all) {
		document.all.hContainer.style.top=ypos;
	}
	if (!document.all && document.getElementById) {
		document.getElementById("hContainer").style.top=ypos+"px";
	}
	if ((ypos>=(endPos-1) && direction == "down") || (ypos<=(endPos+1) && direction == "up")) {
		window.clearTimeout(Id);Id=0;
		if (document.layers) {
			document.hContainer.top=endPos;
		}
		if (document.all) {
			document.all.hContainer.style.top=endPos;
		}
		if (!document.all && document.getElementById) {
			document.getElementById("hContainer").style.top=endPos+"px";
		}
		
		if (direction == "down") {
			opacity("hCont", 0, 100, 500);
			topMenu = "down";
			
		} else {
			topMenu = "up";
			playFlash("true");
		}
	} else {
		Id = window.setTimeout("movemenu();",50);
	}
};

function KeyValue(value) {
	if(value == "u" || value == "U") {
		startmove('up');
		return false;
	} else if (value == "d" || value == "D") {
		startmove('down');
		return false;
	}
};

function playFlash(bPlay) 
{
};

if(typeof(setOpacity) !=  "undefined")
{
    setOpacity(0, "hCont");
};

// --------------------- move.js --------------------//

function fillFacadeForm(fileId,textboxId,spanId) {
    document.getElementById(textboxId).value= document.getElementById(fileId).value;
    var filename = document.getElementById(fileId).value;
    if (filename!='' && filename.lastIndexOf("\\")>=0) {
        filename = filename.substring(filename.lastIndexOf("\\")+1);
        document.getElementById(spanId).innerHTML = filename;
    }
    else
        document.getElementById(spanId).innerHTML = '';
};
/* End - Browser Button */

//Start - Add File control
function addFile(obj) {
    var numi = document.getElementById(obj + 'Value');
    var num = (document.getElementById(obj + 'Value').value -1)+ 2;
    numi.value = num;
    var strFileUploadClass;
    strFileUploadClass = "fileUpload";
    var spnClass;
    if(browser=="Opera")
        spnClass='browO';
    else if (browser=="Safari")
        spnClass='browS';
    else
        spnClass='brow';
    
    document.getElementById("p" + num).style.display = 'block';
    if (num >= 2)
        document.getElementById(obj + 'Remove').style.display="inline";
    if (num >= g_maxFileNumber)
        document.getElementById(obj + 'Add').style.display="none";
};

function removeFile(obj) {
    var num = document.getElementById(obj + 'Value').value;
    document.getElementById("p" + num).style.display = 'none';
    document.getElementById("projectFile" + num).value ='';
    document.getElementById("projectFileimg" + num).src = '/CProject/images/spacer.gif';
    document.getElementById(obj + 'Value').value=num-1;
    if (num <= 2)
        document.getElementById(obj + 'Remove').style.display="none";
    if (num <= g_maxFileNumber)
        document.getElementById(obj + 'Add').style.display="inline";
};
//End - Add File control

function alterDisplay(obj)
{
    if($(obj).style.display=='none')
        $(obj).style.display = 'block';
    else
        $(obj).style.display = 'none';
};

function alterVisibility(obj)
{
    if($(obj).style.visibility=='visible')
        $(obj).style.visibility = 'hidden';
    else
        $(obj).style.visibility = 'visible';
};
