// ========================================================================
//	TES JavaScripts Library V1.0
//	
//	File default.js
//	
//	Copyright (c) 2002-2005 John Wiley and Sons, Inc.
// ========================================================================

function validSubmit(in_form){
	if (validate(in_form)){
		in_form.submit();
	}
}

function checkPwdLength(in_inputObj){
	var s_maxLength = 25;
	if (in_inputObj.value.length > s_maxLength){
		alert("Please choose a new password that is fewer than "+ s_maxLength +" characters.");
		in_inputObj.value = "";
	}
}

function checkTextAreaLength(in_inputObj){
	var s_maxLength = 10000;
	var s_valueStore = in_inputObj.value;
	if (in_inputObj.value.length > s_maxLength){
		alert("This assignment type has a maximum character limit of 10000.");
		in_inputObj.value = s_valueStore.substring(0, 9999);
		return true;
	}
}

function itemsSelect(in_form, in_controlObj, in_itemName){
	var switcherState = in_controlObj.checked;
	var curElm = null;
	for(var i=0; i< in_form.length; i++)
	{
		curElm = in_form.elements[i];
		if ((in_form.elements[i].name == in_itemName) || 
				((arguments[3] != null) && (in_form.elements[i].name == arguments[3])))
		{
			if (in_form.elements[i].type == 'checkbox'){
				curElm.checked = switcherState;
			}	
		}
	}
}

function containsWsOnly(in_str){
	var s_result = true;
	for(var i=0; i < in_str.length; i++)
	{
		if (in_str.charAt(i) != " " ){
			s_result = false;
			break;
		}
	}
	return s_result;
}

function notImp(feature)
{
	alert("The '" + feature + "' is not implemented yet.");
}

var s_is = new Is();

function Is() {
	var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
	this.ns2 = (this.ns && (this.major == 2));
	this.ns3 = (this.ns && (this.major == 3));
	this.ns4 = (this.ns && (this.major == 4));
	this.ns5 = (this.ns && (this.major > 4));
	this.ns6 = (this.ns && (agent.indexOf('netscape6')!=-1) );
	this.ns7 = (this.ns && (agent.indexOf('netscape/7')!=-1) );
	this.ns7pr = (this.ns && (agent.indexOf('netscape/7.0b1')!=-1) );
	this.ns71 = (this.ns && (agent.indexOf('netscape/7.1')!=-1) );
	this.ns72 = (this.ns && (agent.indexOf('netscape/7.2')!=-1) );
	this.ie = (agent.indexOf("msie") != -1);
	this.ie3 = (this.ie && (this.major == 2));
	this.ie4 = (this.ie && (this.major >= 4));
	this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
	this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
	this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1));
	this.op3 = (agent.indexOf("opera") != -1);
	this.pc  = (agent.indexOf("win") != -1);
	this.mac = (agent.indexOf("mac")!=-1); // Mac detect
	this.client = ( (navigator.userAgent.indexOf('AOL')!=-1) || (navigator.userAgent.indexOf('CS 2000')!=-1) )? 1 : 0;
	this.moz = ( this.ns && (agent.indexOf("netscape/") == -1) );
	if (this.moz) this.ns = 0;
}


function gotoURL(in_url){
	window.location = in_url;
}

function switchTabs(in_id, in_step)
{
	var i = 1;
	var tips_is_exists = true;
	while(tabs = document.getElementById(in_id + "-tabs-tab" + i))
	{
		if(i != in_step)
		{
			tabs.style.background = "#ffffff";
			tabs.style.color = i < in_step ? "#086EC4" : "#cccccc";
			try
			{
				document.getElementById(in_id + "-tabs-page" + i).style.display = "none";
			}
			catch(e){}
			try
			{
				document.getElementById(in_id + "-tabs-tips" + i).style.display = "none";
			}
			catch(e){}
		}
		else
		{
			tabs.style.background = "#EFEFEF";
			tabs.style.color = "#000000";
			try
			{
				document.getElementById(in_id + "-tabs-page" + i).style.display = "block";
			}
			catch(e){}
			try
			{
				document.getElementById(in_id + "-tabs-tips" + i).style.display = "block";
			}
			catch(e)
			{
				tips_is_exists = false;
			}
		}
		i++;
	}
	if(!tips_is_exists)
	{
		try
		{
			document.getElementById(in_id + "-tabs-tips1").style.display = "block";
		}
		catch(e){}
	}
}

var pastControlID = pastControlValue = null;
var pastControlTimer = false;
var is_past_action = false;

function initPastControl(in_past_control_id)
{
    if(!s_is.mac)
    {
        if(in_past_control_id.length > 0)
        {
            pastControlID = in_past_control_id;

            pastControlValue = new Array();
            for(var index in pastControlID)
                pastControlValue[index] = document.getElementById(pastControlID[index]).value;

            setTimeout("pastControlHandler()",100);
            pastControlTimer = true;
        }
    }
}

function pastControlChangeValue(in_object)
{
	if(pastControlID.length > 0)
	{
		for(var index in pastControlID)
		{	
			if(pastControlID[index]==in_object.id)
			{
				pastControlValue[index] = in_object.value;
				break;
			}
		}
	}
	pastControlTimer = true;
}

function pastControlHandler()
{
	if(pastControlTimer)
	{
		for(var index in pastControlID)
		{
            var obj = document.getElementById(pastControlID[index]);
        	if(pastControlValue[index] != obj.value || is_past_action)
			{
                alert("Please type this field manually.");
				obj.value = "" ;
                pastControlValue[index] = "";

                is_past_action = false;
				break;
			}
		}
	}
	setTimeout("pastControlHandler()",100);
}

if (document.captureEvents)
	document.captureEvents(Event.KEYDOWN)


document.onkeydown=function(e)
{
    if(!s_is.mac)
    {
        if(window.event)
        {
			if(isExistsControlID(event.srcElement.id))
			{   
				pastControlTimer = false;
				
	            if(event.ctrlKey && event.keyCode == 86)
	                is_past_action = true;
			}
        }
        else
        {
			if(isExistsControlID(e.target.id))
			{   
				pastControlTimer = false;
				
	            if(e.ctrlKey && e.keyCode == 86)
	                is_past_action = true;
			}	
        }
    }
}

function isExistsControlID(in_id)
{
	for(var index in pastControlID)
	{
		if(pastControlID[index]==in_id)
			return true;
	}
	return false;
}


function transcoding(str){
    str = str.replace("&#039;","'");
    str = str.replace("&amp;","&");
    str = str.replace("&lt;","<");
    str = str.replace("&gt;",">");
    str = str.replace("&#034;",'"');
    return str;
}




// ========================================================================
