// JavaScript Document

function openWindow(url) 
{
	popupWin = window.open(url,"likolPopUp","top=25,left=50,resizable=yes,width=500,height=400,scrollbars=0,menubar=no")
}

function frmClearFields(){
	document.getElementById('cname').value='';
	document.getElementById('cfone').value='';
	document.getElementById('cmail').value='';
	document.getElementById('ctext').value='';
}

function backToFrameset(){
	if(top.location.href.indexOf('page')>0 && document.location.href == top.location.href){
		
		//top.location.href="http://we.com/Project/likol/index.php?rel="+top.location.href;
		//top.location.href="http://www.likol.bg/dev/index.php?rel="+top.location.href;
		if(top.location.href.indexOf('likol.bg/dev/')>0){
			top.location.href="http://www.likol.bg/dev/index.php?rel="+top.location.href
		} 
		else if(top.location.href.indexOf('likol.bg')>0){
			top.location.href="http://www.likol.bg/index.php?rel="+top.location.href
		}
		else if(top.location.href.indexOf('we.com')>0){
			top.location.href="http://we.com/Project/likol/index.php?rel="+top.location.href;
		}		
	}	
}



function SubmitForm(){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.forms["contactForm"].elements["cmail"].value;
	
	if (reg.test(address) == false) {
		alert(document.getElementById('msgMissingMail').value);
	}
	else if (document.forms["contactForm"].elements["cname"].value.length < 1) {
		alert(document.getElementById('msgMissingName').value);
	}
	else {
		document.forms['contactForm'].submit();
	}
}
		
		
		
/******************************************************
**************** Configurator *************************
******************************************************/

var spacer='../image/spacer.gif';
function LoadingSignOn(){ LoadingSignToggle('on'); }
function LoadingSignOff(){ LoadingSignToggle('off');};

function LoadingSignToggle(mode){ document.getElementById('img_loading').className= (mode=='on')?'visibleOn':'visibleOff'; }


function SetFore(imgSrc){ SetImage('img_fore',imgSrc); }
function SetBack(imgSrc){ SetImage('img_back',imgSrc); }

function SetImage(imgId,imgSrc){
	if(!configuratorIsReady()){
		alert(document.getElementById('inp_notReadyMsg').value);
		return false;
	}
	
	if(document.getElementById('inp_'+imgId).value == imgSrc){
		document.getElementById('inp_'+imgId).value = "";
		document.getElementById(imgId).src = spacer;
		toggleOrderButton();
		return;
	}
	
	LoadingSignOn();
	
	imgSrc= imgSrc+'';
	imgSrc= (imgSrc.length==0)?spacer:imgSrc;
	
	var image = new Image();
	image.onload=function(){
		document.getElementById('inp_'+imgId).value = imgSrc;
		LoadingSignOff();
		document.getElementById(imgId).src = image.src;
		
		toggleOrderButton();			
	}
		
	image.src = imgSrc +"";
}

function configuratorIsReady(){
	try {if(document.getElementById('inp_isPageReady').value == '1') {return true;}}
	catch (e) {}
	
	return false;
}

function toggleOrderButton(){
	var tie="";
	var shirt="";

	if((document.getElementById('inp_img_fore').value.length + document.getElementById('inp_img_back').value.length)>2){
		document.getElementById('configOrder').style.display="block";
		
		shirt= document.getElementById('inp_img_back').value;
		tie= document.getElementById('inp_img_fore').value;
		
		shirt= shirt.substr(shirt.lastIndexOf("/")+1);
		tie= tie.substr(tie.lastIndexOf("/")+1);
		
		document.getElementById('configOrder').href= "contacts.php?act=configorder&confshirt=" +shirt +"&conftie=" +tie;
	} else {
		document.getElementById('configOrder').style.display="none";
	}	
}

/******************************************************
****************** Site map ***************************
******************************************************/

