// JavaScript Document
var flagVisible=0;
var newdiv;


function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}
function formCheck() {
	var form=document.getElementById('contactForm');
	
	var Name=form.Name.value;
	var Email=form.Email.value;
	var Enquiry=form.Enquiry.value;
	
	email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))$/;
	
	if (Name.length==0 || Email.length==0 || !email.test(Email) || Enquiry.length==0) {
		document.getElementById('Name').className='InputBlock';
		document.getElementById('Email').className='InputBlock';
		document.getElementById('Enquiry').className='InputBlock';
		
		if(Name.length==0) {
			document.getElementById('Name').className='InputBlock Error';
		}
		if(Email.length==0 || !email.test(Email)) {
			document.getElementById('Email').className='InputBlock Error';
		}
		if(Enquiry.length==0) {
			document.getElementById('Enquiry').className='InputBlock Error';
		}
	}		
	else {
		form.submit();
	}
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}
function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.appendChild) {
		var strNewWindowAlert = "";
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (/\bnew\-win\b/.test(link.className)) {	
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);


//manage div
function showDiv(id,width,height,url){
	if(flagVisible) {hideDiv();}
	
	newdiv = document.createElement('div');
  newdiv.setAttribute('id',id);	
	document.body.appendChild(newdiv);
	
	newdiv.style.position = "absolute";
	newdiv.style.left='-1500px';          
  newdiv.style.top='-1500px'; 
  newdiv.style.background = "#fff";
	newdiv.style.overflow = "hidden";
	newdiv.style.border = "solid 1px #ddd";
	
	newdiv.innerHTML='<img src="images/loading.gif" alt="" id="loading" />';
	
	if(width) {
   newdiv.style.width = width+'px';
 	}
 	if(height) {
   newdiv.style.height = height+'px';
	}
	
	ajaxLoader(url,id); 
 	centerDiv(id,width,height);	
	flagVisible=1;
	refreshlocation(id,width,height);
}

function hideDiv(id){
		document.body.removeChild(newdiv);
		flagVisible=0;
}

function centerDiv(id,myWidth,myHeight){
		var suffix="";
		if(FIND(id).style.left.indexOf('px')>=0){
			suffix="px";
		}
		FIND(id).style.left=Math.floor((returnWindowSize('width')-myWidth)/2)+suffix;
		FIND(id).style.top=Math.floor(returnWindowSize('height')/2-(myHeight/2))+getTop()+suffix;
}

function returnWindowSize(dim) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(dim == 'width') return myWidth;
	if(dim == 'height') return myHeight;
}
function getTop(){
		if (navigator.appName == "Netscape") {
			return window.pageYOffset;
		}
		else {
			return (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
		}
}
function refreshlocation(id,myWidth,myHeight){
		if(flagVisible){
			centerDiv(id,myWidth,myHeight);
		} else {
			if(!flagVisible) {
				if(st1) clearTimeout(st1);
				return;
			}
		}
		st1=setTimeout(function(){refreshlocation(id,myWidth,myHeight)},10);
}

function ajaxLoader(url,id) {
  if (document.getElementById) {
			
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
      }
    }
    x.open("http://www.dastudio.biz/GET", url, true);
    x.send(null);
  }
}

function showHide(e){
	obj = document.getElementById(e);
	if(obj.style.display=='none'){
		obj.style.display='block';
	}else{
		obj.style.display='none';
	}
}

var emailexp = /^[a-z_0-9\-\.]+@[a-z_0-9\.\-]+\.[a-z]{2,3}$/i;
function validateForm(){
	name = document.getElementById('name')
	email = document.getElementById('email')
	phone = document.getElementById('phone')
	captcha = document.getElementById('captcha')
	message = document.getElementById('message')
	if(name.value==' Name:' || email.value==' E-mail:' || phone.value==' Telephone:' || captcha.value==''  || message.value=='Message:' ){
		alert('Please fill up all input fields.')
		return false;
	}
	if (!emailexp.test(email.value, 1, 0)) {
		alert("Your e-mail address is not valid.");
		return false;
	}
}

function clearText(obj,text,type){
	if(type==undefined){type='text'}
	if(type=='text'){
		if(obj.value==text){obj.value=''}
	}
	if(type=='textarea'){
		if(obj.innerHTML==text){obj.innerHTML='';obj.value=''}
	}
}
function setText(obj,text,type){
	if(type==undefined){type='text'}
	if(type=='text'){
		if(obj.value==''){obj.value=text}
	}
	if(type=='textarea'){
		if(obj.value==''){obj.innerHTML=text}
	}
}
