/**
 * Title    : lingduintScripts.js
 * Version  : 1.1
 * Created  : 2007/11/22
 */

// Simplify getElementById()
function $(id) {
  return document.getElementById(id);
}

/* 
 * Cross-browser event model helper function
 *
 * addEvent(window, 'load', 'functionName');
 * addEvent(window, 'load', function() { doSomething(someParam); });
 */
 
var addEvent;
if (document.addEventListener) { // Non-IE
	addEvent = function(element, type, handler) {
		element.addEventListener(type, handler, false);
	};
} else if (document.attachEvent) { // IE6+
    addEvent = function(element, type, handler) {
        element.attachEvent("on" + type, handler);
    };
} else { // Older Browsers
    addEvent = function(element, type, handler) {
		var oldHandler = element['on' + type];
		if (oldHandler === null) {
			element['on' + type] = handler;
		} else {
			element['on' + type] = function(e) { oldHandler(e); handler(e); };
		}
	};
}

function copyrightDate(startYear) {
	var d = new Date();
	var y = new Date().getFullYear();
	
	var result = (y != startYear) ? startYear + "-" + y : startYear;
	return result;
}

// NoSpamEmail Script
// Example: nospam("domain.com","info","Click here to get more information");
function nospam(domain,name,visible){
	document.write('<a href=\"mail' + 'to:' + name + '@' + domain + '\">');
	document.write(visible + '</a>');
}

// NoSpamEmail Script 2
// Example: nospam2("domain,"info","com");
function nospam2(domain,name,tld){
	document.write('<a href=\"mail' + 'to:' + name + '@' + domain + '.' + tld + '\">');
	document.write(name + '@' + domain + '.' + tld + '</a>');
}

function checkEmail (email) {
	var error = false;
	if (email === "") {
   		error = "You didn't enter an email address.\n";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(email))) { 
       error = "Please enter a valid email address.\n";
    } else {
		//test email for illegal characters
       	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
        if (email.match(illegalChars)) {
        	error = "The email address contains illegal characters.\n";
       	}
    }
	
	return error;    
}

function init_menu() {
	var menuParams = menus;
	for (var i = 0; i < menuParams.length; i++) {
		var menuObj = menuParams[i];
		var id = menuObj.id;
	   	
		if (null === $(id)) { continue; }

		var selector = "" + id + ' .menuList';
		var menuList = $S(selector);
	
		var menuId = 'menu' + i;
		menuList[0].id = menuId;
		
		for (var j = 0; j < menuObj.hilite.length; j++) {
			var theItem = $S(selector + ' .' + menuObj.hilite[j]);
			if (theItem) {
				//theItem[0].setAttribute('class', theItem[0].getAttribute('class') + ' youarehere');
				addClassName(theItem[0], 'youarehere');
			}
		}

		var opt = menuObj.menuOptions || {};
		var menu = DynarchMenu.setup(menuId, opt);
	}
}

function removeClassName(el, className) { 
	var newClass = el.className.replace(className, '').trim();
	el.className = newClass;
	//el.setAttribute('class', newClass);
}

function addClassName(el, className) { 
	var newClass = (el.className + ' ' + className).trim();
	removeClassName(el, className); 
	el.className = newClass;
	//el.setAttribute('class', newClass);
}

var nowpage = 1;
var precpage = 1;
var nextpage = 1;
var programname = "";
var url = window.location.href;
var a = url.substring(url.lastIndexOf("/")+1,url.lastIndexOf(".html"));

for(var i=0;i<a.length;i++)
{
	if(isNaN(a.substring(i,i+1)))
	{
		programname = programname+a.substring(i,i+1);
	}
}
if(url.indexOf(".html")!=-1)
{
	tmpurl = url.substring(url.lastIndexOf(programname)+programname.length,url.indexOf(".html"));

	if(tmpurl != "" && tmpurl != null && tmpurl != undefined && !isNaN(tmpurl))
	{
		nowpage = parseInt(tmpurl);
	}else{
		nowpage = 1;
	}
	precpage = nowpage-1;
	nextpage = nowpage+1;
}

function init()
{	
	
}

function fprecpage()
{
//	var object = document.getElementById("selectpage");
	var url = window.location.href;
	if(nowpage == 2)
	{
		url = url.replace(nowpage,"");
	}else {
		url = url.replace(nowpage,nowpage-1);
	}
//	if(object.selectedIndex != 0)
//	{ object.selectedIndex = object.selectedIndex-1; }
	window.location.replace(url);
}

function changepage(object)
{
	var url = window.location.href;
	var selectpage = object.selectedIndex+1;
	if(nowpage == 1)
	{
		url = url.replace(programname,programname+selectpage);
		window.location.replace(url);
	}else if(selectpage == 1)
	{
		url = url.replace(nowpage,"");
	}else {
		url = url.replace(nowpage,selectpage);
	}
	window.location.replace(url);
}

function fnextpage()
{
	var url = window.location.href;
	var tmpurl = "";

	if(nowpage == "1")
	{
		tmpurl = url.substring(0,url.lastIndexOf(".html"))+"2"+".html";
		alert(tmpurl);
		window.location.replace(tmpurl);
	}else{
		tmpurl = url.replace(nowpage,nowpage+1);
		window.location.replace(tmpurl);
	}

}

function checknull(oValue)
{
	if(oValue != null && oValue != undefined)
	{
		return true;
	}else{
		return false;
	}
}

function showIt(src) {

	var child, parent, childNum = 0;

	if (document.getElementById) {
		parent = src.parentNode;
		for (var i=0; i < parent.childNodes.length; i++) {
			if (parent.childNodes[i].nodeType != 1) { continue; }
			if (childNum != 1) { childNum++; continue; }
			else { child = parent.childNodes[i]; }
		}
	}
	else if (document.all) {
		parent = document.all[src.sourceIndex -1];
		child = document.all[src.sourceIndex + 1];
	}

//document.write(child + "<br>");
//document.write(parent.tagName + "<br>");
//document.write(child.tagName + "<br>");

	if (child != null && "LI" == parent.tagName && "UL" == child.tagName) {
//			parent.className = ("close" == parent.className ? "open" : "close");
		child.className = ('menuItemExpand' == child.className ? 'menuItemClose' : 'menuItemExpand');
	}
}

function over(object)
{
	object.src="img/home/"+object.name+"_B.jpg";
}
function out(object)
{
	object.src="img/home/"+object.name+".jpg";
}

function homeover(object)
{
	object.src="img/home/"+object.name+"_B.jpg";
}
function homeout(object)
{
	object.src="img/home/"+object.name+".jpg";
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); }