var fullImages = new Array();

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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
function getPageSize() {
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll) 
	return arrayPageSize;
}

function idFromString(str){
	var id = "";
	if (str != null){
		var regexp=/^[A-Za-z0-9]$/;
		for (var i=0; i < str.length; i++){
			if (str.charAt(i).match(regexp) != null){
				id += str.charAt(i);
			}
		}
	}
	return id;
}

function fullImageShow(src, w, h){
	if ((containerObj = MM_findObj("fullImageContainer")) != null 
		&& (obj = MM_findObj("fullImage")) != null 
		&& (holderObj = MM_findObj("fullImageHolder")) != null 
		&& (coverObj = MM_findObj("cover")) != null
	){
		if (w == null){
			var w = 0;
		}
		else{
			w = Number(w);
			containerObj.style.width = w + 10;
		}
		if (h == null){
			var h = 0;
		}
		else{
			h = Number(h);
		}
		if (offset_x == null) var offset_x = 0;
		if (offset_y == null) var offset_y = 0;

		var arr = getPageSize();
		var id = idFromString(src);

		if ((imgObj = MM_findObj(id)) == null){
			var img = document.createElement("img");

			img.id = id;
			img.border = 0;
			img.width = w;
			img.height = h;
			img.title = "Click to close";
			img.alt = "";
			img.src = src;
			holderObj.appendChild(img);

			if ((imgObj = MM_findObj(id)) != null){
				fullImages[fullImages.length] = id;
				if (imgObj.attachEvent){
					imgObj.attachEvent("onclick", fullImageHide);
				}
				else{
					imgObj.addEventListener("click", fullImageHide, true);
				}
			}
		}
		else{
			imgObj.src = src;
			imgObj.width = w;
			imgObj.height = h;
			imgObj.style.display = "block";
		}

		obj.style.left = Math.max(0, (arr[2]/2 - (w+24)/2 + offset_x/2)) + "px";
		obj.style.top = Math.max(20, (arr[3]/2 - (h+24)/2 + offset_y/2)) + "px";
		obj.style.display = "block";
		coverObj.style.height = arr[1] + "px";
		coverObj.style.display = "block";
	}
	else{
		return false;
	}
}

/*
function fullImageShow(src, w, h){
	if ((containerObj = MM_findObj("fullImageContainer")) != null 
		&& (obj = MM_findObj("fullImage")) != null 
		&& (imgObj = MM_findObj("fullImageImg")) != null 
		&& (coverObj = MM_findObj("cover")) != null
	){
		if (w == null){
			var w = 0;
		}
		else{
			w = Number(w);
			containerObj.style.width = w + 10;
		}
		if (h == null){
			var h = 0;
		}
		else{
			h = Number(h);
		}
		if (offset_x == null) var offset_x = 0;
		if (offset_y == null) var offset_y = 0;
		var arr = getPageSize();

		imgObj.src = "img/spacer.gif";

		obj.style.left = Math.max(0, (arr[2]/2 - (w+24)/2 + offset_x/2)) + "px";
		obj.style.top = Math.max(20, (arr[3]/2 - (h+24)/2 + offset_y/2)) + "px";
		obj.style.display = "block";
		coverObj.style.height = arr[1] + "px";
		coverObj.style.display = "block";

		imgObj.style.width = w;
		imgObj.style.height = h;
		imgObj.src = src;
	}
	else{
		return false;
	}
}
*/

function fullImageHide(){
	if ((obj = MM_findObj("fullImage")) != null
		&& (coverObj = MM_findObj("cover")) != null
//		&& (imgObj = MM_findObj("fullImageImg")) != null
	){
		obj.style.display = "none";
		coverObj.style.display = "none";
		for (var i=0; i < fullImages.length; i++){
			if ((imgObj = MM_findObj(fullImages[i])) != null){
				imgObj.style.display = "none";
			}
		}
	}
	else{
		return false;
	}
}

function findObj(n,d){
	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=findObj(n,d.layers[i].document);
	if (!x && d.getElementById)
		x=d.getElementById(n);
	return x;
	delete p;
	delete i;
	delete x;
}

function getLength(str){
	var strLength=0;
	if (str != null){
		for (var i=0; i < str.length; i++){
			if (str.charAt(i) != " "){
				strLength++;
			}
		}
	}
	return strLength;
}

function trim(str){
	if (str != null){
		return ltrim(rtrim(str));
	}
	else{
		return "";
	}
}

function ltrim(str){
	if (str != null){
		var idx = 0;
		for (var i=0; i < str.length; i++){
			if (str.charAt(i) != " " && str.charAt(i) != "\n" && str.charAt(i) != "\r" && str.charAt(i) != "\t" && str.charAt(i) != "\0" && str.charAt(i) != "\x0B"){
				idx = i;
				break;
			}
		}
		return str.substring(idx, str.length);
	}
	else{
		return "";
	}
}

function rtrim(str){
	if (str != null){
		var idx = str.length;
		for (var i=str.length-1; i >= 0; i--){
			if (str.charAt(i) != " " && str.charAt(i) != "\n" && str.charAt(i) != "\r" && str.charAt(i) != "\t" && str.charAt(i) != "\0" && str.charAt(i) != "\x0B"){
				idx = i;
				break;
			}
		}
		return str.substring(0, idx+1);
	}
	else{
		return "";
	}
}

function validateEmail(str){
	if (str.length <= 0){
		return true;
	}
	var splitted = str.match("^(.+)@(.+)$");
	if (splitted == null) return false;
	if (splitted[1] != null){
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if (splitted[1].match(regexp_user) == null) return false;
	}
	if (splitted[2] != null){
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if (splitted[2].match(regexp_domain) == null){
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if (splitted[2].match(regexp_ip) == null) return false;
		}
		return true;
	}
	return false;
}

function validatePhone(str){
	RefString = "-+. ()1234567890";
	DecimalPoints = 0;
	for (i=0; i<str.length; i++){
		TempChar = str.substring ( i, i+1 );
//		if (TempChar == ".") DecimalPoints++;		// Can only have zero or one decimal points in a number
//		if (TempChar == "-" && i != 0) return false;	// Minus Sign must be first character
//		if (TempChar == "+" && i != 0) return false;	// Plus Sign must be first character

		// Check if current character is valid
		if (RefString.indexOf(TempChar,0) == -1) return false;
	}
	//if (DecimalPoints > 1) return false;
	return true;
}

function headNavToggle(id, div1, div2, state){
	if (id != null && id != ""){
		if ((obj = findObj(id)) != null){
			if (obj.style != null){
				obj.className = (state == 1 ? "navOn" : "navOff");
			}
		}
	}
	if (div1 != null && div1 != ""){
		if ((obj_div1 = findObj(div1)) != null){
			if (obj_div1.style != null)
				obj_div1.className = (state == 1 ? "navOn" : "navOff");
		}
	}
	if (div2 != null && div2 != ""){
		if ((obj_div2 = findObj(div2)) != null){
			if (obj_div2.style != null)
				obj_div2.className = (state == 1 ? "navOn" : "navOff");
		}
	}
}