var useragent = navigator.userAgent.toLowerCase();
var IE = useragent.indexOf('msie') > 0 ? true : false;
var OPERA = useragent.indexOf('opera') > 0 ? true : false;
var mouseposX = 0;
var mouseposY = 0;







/**********************************************************************/
function detectBrowserClass(modern) {
	var nBrowser	= navigator.appName;
	var nVersion	= navigator.appVersion;
	var nAgent		= navigator.userAgent;
	this.version;
	this.browser;
	this.os;
	this.modern = (typeof modern == 'object') == true ? modern : 0;
	
	if(nVersion.indexOf('Windows') != -1) {
		this.os = 'win';
	}
	else{
		this.os = (nVersion.indexOf('Macintosh') != -1) == true ? 'mac' : 'other';
	}
	
	if(nAgent.indexOf('Opera') != -1) {
		var strIndex = nAgent.indexOf('Opera');
		this.version = nAgent.substring((strIndex + 6), (strIndex + 9));
		this.browser = 'opera';
	}
	else if(nAgent.indexOf('Firefox') != -1) {
		var strIndex = nAgent.indexOf('Firefox');
		this.version = nAgent.substring((strIndex + 8), (strIndex + 11));
		this.browser = 'firefox';
	}
	else if(nAgent.indexOf('MSIE') != -1) {
		var strIndex = nAgent.indexOf('MSIE');
		this.version = nAgent.substring((strIndex + 5), (strIndex + 8));
		this.browser = 'ie';
	}
	else if (nAgent.indexOf('Safari') != -1) {
		if (nAgent.indexOf('Version') != -1) {
			var strIndex = nAgent.indexOf('Version')
			this.version = nAgent.substring((strIndex + 8), (strIndex + 11))
		}
		else {
			this.version = 2;
		}
		this.browser = 'safari';
	}
	else if (nAgent.indexOf('Netscape') != -1) {
		var strIndex = nAgent.indexOf('Netscape');
		this.version = nAgent.substring((strIndex + 9), (strIndex + 12));
		this.browser = 'netscape';
	}
	else {
		this.browser = nBrowser.toLowerCase();
		this.version = null;
	}
	
	this.whichBrowser = function() {
		return this.browser;
	}
	
	this.whichVersion = function() {
		return this.version;
	}
	
	this.whichOS = function() {
		return this.os;
	}
	
	this.getInfo = function() {
		var info = "Browser name: " + nBrowser + "<br />" +
		"Browser version: " + nVersion + "<br />" +
		"User Agent: " + nAgent;
		return info;
	}
	
	this.modernBrowser = function() {
		var isModern = false;
		if(typeof(this.modern[this.browser]) == 'number' || this.version === null) {
			isModern = (this.modern[this.browser] <= this.version || this.version === null ) == true ? true :0;
		}
		return isModern;
	}
}
/**********************************************************************/
var detectBrowser = new detectBrowserClass({
	'opera': 9,
	'safari': 2,
	'firefox': 2,
	'ie': 7
});





//alert('raar')
function setEvent(e) {
	if(!e) var e = window.event
	
	if(e.pageX || e.pageY) {
		mouseposX = e.pageX
		mouseposY = e.pageY
	}
	else if(e.clientX || e.clientY) {
		mouseposX = e.clientX + document.body.scrollLeft
		mouseposY = e.clientY + document.body.scrollTop
	}
		//alert(mouseposY)
}


function makeInput(id, styleClass, encrypt) {
	var field = document.createElement('input');
	field.setAttribute('type', 'input');
	field.setAttribute('id', id);
	field.style.position = 'absolute';
	if(styleClass) {field.className = styleClass;}
	
	if(encrypt) {
		field.removeAttribute('type');
		field.setAttribute('type', 'password');
	}
	return field;
}


function makeButton(val, styleClass) {
	var btn = document.createElement('div');
	btn.className = styleClass;
	btn.innerHTML = val;
	btn.style.textAlign = 'center';
	btn.style.cursor = 'pointer';
	btn.style.position = 'absolute';
	btn.style.border = '2px outset #dee3ff';
	btn.onselectstart = function() {return false;}
	btn.onmousedown = new Function("this.style.border = '#dee3ff 2px inset';");
	btn.onmouseup = new Function("this.style.border = '#dee3ff 2px outset';");
	return btn
}


/* ========================
	External links function
======================== */
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
			anchor.target = "_blank"; 
	} 
} 

/* ================
	Subnavigation 
================ */
function sfHover() {
	if(typeof(document.getElementById("navMain")) != "undefined") {
		try {
			var sfEls = document.getElementById("navMain").getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover = function() {
					this.className+=" sfhover";			
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		} catch(e) {
			
		}
	}
}

/* =====================
	PNG Transparacy
===================== */
// correctly handle PNG transparency in Win IE 5.5 or higher.
function correctPNG() { 
	var ie = false;
	try {
		var nav = navigator.userAgent.toLowerCase();
		var sub = nav.substr(nav.indexOf("msie"), nav.indexOf("."));
		sub = sub.substr(4, 2);
		
		if(parseInt(sub) < 7) {
			ie = true;
		}
	} catch(e){}
	
	if(ie) {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i]
			  var imgName = img.src.toUpperCase()
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
					var imgClass = (img.className) ? "class='" + img.className + "' " : ""
					var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
					var imgStyle = "display:inline-block;" + img.style.cssText 
					if (img.align == "left") imgStyle = "float:left;" + imgStyle
					if (img.align == "right") imgStyle = "float:right;" + imgStyle
					if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle                        
					var strNewHTML = "<span " + imgID + imgClass + imgTitle 
					+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
						 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
					i = i-1
			}
		}
	}
}

function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

function onLoadPage() {
	externalLinks();
	if(IE)	{
		sfHover();
		
		if(detectBrowser.whichVersion() < '7.0') {
			correctPNG();
		}
	}
	sfHover();
	
}

if(window.attachEvent)
	window.attachEvent("onload", onLoadPage);
else if(window.attachEventListener)
	window.attachEventListener("onload", onLoadPage);
	

/* ================
	Email Check,added by Volkan
================ */
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}
