try{
	window.addEvent('domready', function(){
		//$('input_div').fade('hide');
		//$('email').fade('hide');
		//$('submit').fade('hide');
		if($('input_div') != null){
			$('input_div').fade('hide');
			$('input_div').style.display = 'block';
		}
		
		if($('input_video') != null){
			$('input_video').fade('hide');
			$('input_video').style.display = 'block';
		}
		
		if($('input_art') != null){
			$('input_art').fade('hide');
			$('input_art').style.display = 'block';
		}
	});
}
catch(e){
}
function onTextFocus(obj,txt){
	if(obj.value == txt) obj.value = '';
}

function onTextBlur(obj,txt){
	var checkString = obj.value;
	while(checkString.search(' ') >= 0){
		checkString = checkString.replace(' ','');
	}
	if(obj.value == txt || checkString == ''){
		obj.value = txt;
	}
}


function onChangeFile(obj,txt){
	var checkString = obj.value;
	while(checkString.search(' ') >= 0){
		checkString = checkString.replace(' ','');
	}
	if(obj.value == txt || checkString == ''){
		obj.value = txt;
	}
	else{
		var ext = obj.value.substr(-4,4);
		if(ext == ".png" || ext == ".jpg"){
			$('submit_art').style.display = 'block';
			$('select').style.display = 'none';
		}
		else{
			$('selectFile').value = '';
			obj.value = txt;
			alert('Please, select Image file (.PNG or .JPG)');
		}
	}
	obj.blur();
}

function checkForm(obj){
	if(obj.email.value == ""){
		alert("Email Address is required");
		obj.email.focus();
		return false;
	}
	if(!emailCheck(obj.email.value)){
		obj.email.focus();
		return false;
	}
	return true;
}

function checkVideoForm(obj){
	if(obj.link.value == "" || obj.link.value == "Video URL"){
		alert("Video URL is required");
		obj.link.focus();
		return false;
	}
	return true;
}

function checkArtForm(obj){
	if(obj.filename.value == "" || obj.filename.value == "Select File"){
		alert("Select File");
		obj.link.focus();
		return false;
	}
	$('submit_art').style.display = 'none';
	return true;
}


//Email Checker
function emailCheck (emailStr) {	
	var checkTLD=1;		
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;	
	var emailPat=/^(.+)@(.+)$/;	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";	
	var validChars="\[^\\s" + specialChars + "\]";	
	var quotedUser="(\"[^\"]*\")";	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;	
	var atom=validChars + '+';	
	var word="(" + atom + "|" + quotedUser + ")";	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {	
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
	   	}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	
	if (user.match(userPat)==null) {	
		alert("The username doesn't seem to be valid.");
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {		
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   	}
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
		
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}

var ID;

function click_getit(){
	try{clearTimeout(ID);}catch(e){}
	$('input_div').style.zIndex = 5;
	if(isIE())
		$('input_div').fade('show');
	else
		$('input_div').fade('in');
}

function click_cancel(name){
	try{clearTimeout(ID);}catch(e){}
	try{
		if(name != 'all'){
			ID = setTimeout(1000,function(){
				if($('input_div')!=null)$('input_div').style.zIndex = 1;
				if($('input_video')!=null)$('input_video').style.zIndex = 1;
				if($('input_art')!=null)$('input_art').style.zIndex = 1;
			});
		}
	}catch(e){}
	if($('input_div')!=null){
		if(isIE())
			$('input_div').fade('hide');
		else
			$('input_div').fade('out');
	}
	if($('input_video')!=null){
		if(isIE())
			$('input_video').fade('hide');
		else
			$('input_video').fade('out');
	}
	if($('input_art')!=null){
		if(isIE())
			$('input_art').fade('hide');
		else
			$('input_art').fade('out');
	}
}

function click_video(){
	click_cancel('all');
	try{clearTimeout(ID);}catch(e){}
	$('input_video').style.zIndex = 5;
	if(isIE())
		$('input_video').fade('show');
	else
		$('input_video').fade('in');
}

function click_art(){
	click_cancel('all');
	try{clearTimeout(ID);}catch(e){}
	$('select').style.display = 'block';
	$('submit_art').style.display = 'none';
	$('input_art').style.zIndex = 5;
	if(isIE())
		$('input_art').fade('show');
	else
		$('input_art').fade('in');
}

function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
