﻿// JavaScript Document
var halfX;
var halfY;
var fullX;
var fullY;

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function initial() {
	IE = document.all ? true : false;
	fox = new RegExp("Firefox","i");
	chrome = new RegExp("Chrome","i");
	safari = new RegExp("Safari","i");
	opera = new RegExp("Opera","i");
	if (IE) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else if (fox.test(navigator.userAgent) || chrome.test(navigator.userAgent) || safari.test(navigator.userAgent) || opera.test(navigator.userAgent)) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else {
		fullX = pageXOffset;
		fullY = pageYOffset;
	}
	halfX = Math.floor(fullX / 2);
	halfY = fullY / 2;
}

function setAlpha(obj,per) {
	inone = per / 100;
	if (inone >= 1) inone = 0.99;
	obj.style.opacity = inone;
	obj.style.MozOpacity = inone;
	obj.style.KhtmlOpacity = per / 100;
	obj.style.filter = "alpha(opacity=" + per + ")";
}

function goAjax(url,target,args,parent) {
	var req;
	try {
		req= new XMLHttpRequest();
	} catch (e) {
		try {
			req= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser not support!");
				return false;
			}
		}
	}
	
	if (parent != undefined) req.parent = parent;

	req.onreadystatechange = target;

	req.open("post",url);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; UTF-8');
	req.send(args);
}

function afterAjax() {
	if (this.readyState == 4 && (this.status == 200 || this.status == 304)) {
		this.parent.innerHTML = this.responseText;
	}
}

function isNum(n) {
	strChk = "1234567890.";
	n = n + "";
	for (i = 0;i < n.length;i++) {
		c = n.charAt(i);
		if (c == ',') {
			ii = n.length - i;
			nnn = ii % 4;
			if (nnn != 0) return false;
		}
		else {
			if (strChk.indexOf(c) < 0) return false;
		}
	}
	return true;
}

function isEmail(mail) {
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (mail.search(emailRegEx) == -1) {
		return false;
	}
	return true;
}

var flashID = 1;
function showFlash(filename,w,h) {
	txt = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + w + "\" height=\"" + h + "\"><param name=\"movie\" value=\"" + filename + "\"><param name=\"quality\" value=\"high\"><embed src=\"" + filename + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"  width=\"" + w + "\" height=\"" + h + "\"></embed></object>";
	flashID++;
	document.write(txt);
}

var _popBG = null;
var _popFG = null;

function callDialog(txt,w,h,padding) {
	initial();
	if (padding == undefined) padding = 20;
	if (_popBG == null) {
		_popBG = document.createElement("div");
		_popBG.style.position = "fixed";
		_popBG.style.zIndex = 1;
		_popBG.style.backgroundColor = "#000";
		setAlpha(_popBG,50);
		document.body.appendChild(_popBG);
	}
	if (_popFG == null) {
		_popFG = document.createElement("div");
		_popFG.style.position = "fixed";
		_popFG.style.zIndex = 2;
		_popFG.style.backgroundColor = "#FFF";
		document.body.appendChild(_popFG);
	}
	_popBG.style.width = fullX + "px";
	_popBG.style.height = fullY + "px";
	_popBG.style.left = "0px";
	_popBG.style.top = "0px";
	_popFG.style.width = w;
	_popFG.style.height = h;
	_popFG.style.left = Math.round((fullX - w) / 2) + "px";
	_popFG.style.top = Math.round((fullY - h) / 2) + "px";
	_popFG.innerHTML = "<div style=\"padding:" + padding + "px\">" + txt + "</div>";
	_popBG.style.display = "";
	_popFG.style.display = "";
}

function closeDialog() {
	_popFG.style.display = "none";
	_popBG.style.display = "none";
}

function shuffle(o){
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
}


/************* contact ***********/

function validate_con()
{

var dm=document.form1;

var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

if(dm.elements["name"].value==""){	
	alert("Please Enter Your Name");	
	dm.name.focus();	
	return false;
}	

if(dm.elements["email"].value==""){	
	alert("Please Enter Your Email");	
	dm.email.focus();	
	return false;
}

var str = dm.elements["email"].value;

if (!reg1.test(str) && reg2.test(str))
{ 
// if syntax is valid
   //return true;
}
else
{
alert ("Invalid Email entered. Please check it!");
dm.email.focus();
return false;
}

if(dm.elements["message"].value==""){	
	alert("Please Enter Your Message to Contact");	
	dm.message.focus();	
	return false;
}	

return true;

}  // end function

/************* end contact ***************/
