//Global test for support Regular Expressions
var g_RegExpSupported = 0;
if(window.RegExp)
{
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if(tempReg.test(tempStr)) 
		g_RegExpSupported = 1;
}

function TransportFn() {
	var price = Math.abs(document.getElementById('TotalPriceHelp').value)
	var sumprice = Math.abs(document.getElementById('TotalPriceAndTotalPriceHelp').value)
	
	if (document.getElementById("Transport1").checked && sumprice < 2000) {
		document.getElementById("TransportPrice").value=120;
		document.getElementById("TotalPrice").value= price + 120;
		document.getElementById("cTransportPrice").value=120;
		document.getElementById("sTransportName").value='dobírka - česká pošta';
		
	} else if(document.getElementById("Transport1").checked && sumprice > 2000) {
		document.getElementById("TransportPrice").value=0;
		document.getElementById("TotalPrice").value= price + 0;
		document.getElementById("cTransportPrice").value=0;
		document.getElementById("sTransportName").value='osobní odběr na podnikové prodejně';
		
	} else if(document.getElementById("Transport2").checked) {
		document.getElementById("TransportPrice").value=0;
		document.getElementById("TotalPrice").value= price + 0;
		document.getElementById("cTransportPrice").value=0;
		document.getElementById("sTransportName").value='osobní odběr na podnikové prodejně';
	}
}


function TransportFnPartner() {
	
	if (document.getElementById("Transport1").checked) {
		document.getElementById("sTransportName").value='Česká pošta';
		
	} else {
		document.getElementById("sTransportName").value='PPL';
	}
}


function validateOrder(ThisForm){
	var strHTML=ThisForm.TitleTextForJS.value+'\n';	
	var submitForm = true
 	var msg = ThisForm.sEmailForJS.value;	
	var str = ThisForm.sEmail.value;

	if(!g_RegExpSupported){
		if(!(str.indexOf(".") > 2) && (str.indexOf("@") > 0))
		{
			if(strHTML != ''){
			strHTML += '\n'
			}
			strHTML += msg;
			ThisForm.sEmail.focus();
			submitForm = false;
		}	
	}
	else
	{	
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
		if(!(!r1.test(str) && r2.test(str)))
		{
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += msg;
			ThisForm.sEmail.focus();
			submitForm = false;
		}
	}

	if(ThisForm.sName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}	
			strHTML += (ThisForm.sNameForJS.value);
			submitForm = false;
	}
	if(ThisForm.sSurName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sSurNameForJS.value);
			submitForm = false;
	}
	
	if(ThisForm.sStreet.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sStreetForJS.value);
			submitForm = false;
	}
	if(ThisForm.sZIP.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sZIPForJS.value);
			submitForm = false;
	}
	if(ThisForm.sCity.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sCityForJS.value);
			submitForm = false;
	}
	if(ThisForm.sPhone.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sPhoneForJS.value);
			submitForm = false;
	}
	if(ThisForm.sLoginName){
		if(ThisForm.sLoginName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sLoginNameForJS.value);
			submitForm = false;
		}
	}

//kontrola zda je platba pres fakturu - pokud ano tak musi vyplnit ICO i DICo
	if(ThisForm.sTransportName){
		if(ThisForm.sTransportName.value=='pošta|faktura' || ThisForm.sTransportName.value=='osobní odběr|faktura'){
			if(ThisForm.sICO.value==''){
					if(strHTML != ''){
					strHTML += "\n"
					}
					strHTML += (ThisForm.sICOForJS.value);
					submitForm = false;
			}
			if(ThisForm.sDIC.value==''){
					if(strHTML != ''){
					strHTML += "\n"
					}
					strHTML += (ThisForm.sDICForJS.value);
					submitForm = false;
			}
		}
	}

	if(ThisForm.sPassword && ThisForm.sPasswordConfirm){
		if(ThisForm.sPassword.value=="" && ThisForm.sPasswordConfirm.value==""){
			if(strHTML != '') strHTML += "\n\n"
			
			strHTML += (ThisForm.sPassWordForJS.value);
			submitForm = false;
		}
		
		if(ThisForm.sPassword.value!=ThisForm.sPasswordConfirm.value){
			if(strHTML != '') strHTML += "\n\n"
			
			strHTML += (ThisForm.sConfirmPassWordForJS.value);
			submitForm = false;
		}
	}
	if(!submitForm){
		alert(strHTML);
		return false
	}
	else{
		if(ThisForm.sMessage){
		//slouceni zpravy obchodnika a dopravy platby
			ThisForm.sMessage.value = ThisForm.sTransportName.value;
			ThisForm.sMessage.value += ";|;";
			ThisForm.sMessage.value += ThisForm.sAccessories.value;
			ThisForm.sMessage.value += "|||";
			ThisForm.sMessage.value += ThisForm.sMessage1.value;
		}
		
		if(document.getElementById('accessoriesform')) {
			var accessoriesform = document.getElementById('accessoriesform')
			
			if(document.getElementById('Accessories-1').style.display=='block') {
				accessoriesform.sGoodsID.value = '3095|' + (Math.abs(document.getElementById('Accessories1_Count').value.replace(/,/g, ".")) * 10).toString()
			}
			if(document.getElementById('Accessories-2').style.display=='block') {
				if(accessoriesform.sGoodsID.value!='') {accessoriesform.sGoodsID.value += ','}
				accessoriesform.sGoodsID.value += '3097|' + (Math.abs(document.getElementById('Accessories2_Count').value.replace(/,/g, ".")) * 10).toString()
			}
			if(document.getElementById('Accessories-3').style.display=='block') {
				if(accessoriesform.sGoodsID.value!='') {accessoriesform.sGoodsID.value += ','}
				accessoriesform.sGoodsID.value += '3096|' + (Math.abs(document.getElementById('Accessories3_Count').value.replace(/,/g, ".")) * 10).toString()
			}
			
			//alert(accessoriesform.sGoodsID.value)
			
			if(accessoriesform.sGoodsID.value!='') {
				accessoriesform.submit()
				return false
			} else {
				return true
			}
		}
		else {
			return true
		}
	}
}

function reklamace(typ){
	if (typ==true) {
		document.getElementById("ReklamaceText").disabled='';
		document.getElementById("ReklamaceText").style.background='white';
		
	} else{
		document.getElementById("ReklamaceText").disabled='1';
		document.getElementById("ReklamaceText").style.background='#f0f0f0';
	}

}

function reklamaceDis(typ){
	if (typ==true) {
		document.getElementById("ReklamaceText").style.background='#f0f0f0';
		document.getElementById("ReklamaceText").disabled='1';
		
	} else{
		document.getElementById("ReklamaceText").style.background='#f0f0f0';
		document.getElementById("ReklamaceText").disabled='1';
	}

}






function validateOrderPartner(ThisForm){
	var strHTML=ThisForm.TitleTextForJS.value+'\n';	
	var submitForm = true
 	var msg = ThisForm.sEmailForJS.value;	
	var str = ThisForm.sEmail.value;

	if(!g_RegExpSupported){
		if(!(str.indexOf(".") > 2) && (str.indexOf("@") > 0))
		{
			if(strHTML != ''){
			strHTML += '\n'
			}
			strHTML += msg;
			ThisForm.sEmail.focus();
			submitForm = false;
		}	
	}
	else
	{	
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
		if(!(!r1.test(str) && r2.test(str)))
		{
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += msg;
			ThisForm.sEmail.focus();
			submitForm = false;
		}
	}

	if(ThisForm.sName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}	
			strHTML += (ThisForm.sNameForJS.value);
			submitForm = false;
	}
	if(ThisForm.sSurName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sSurNameForJS.value);
			submitForm = false;
	}
	
	if(ThisForm.sStreet.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sStreetForJS.value);
			submitForm = false;
	}
	if(ThisForm.sZIP.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sZIPForJS.value);
			submitForm = false;
	}
	if(ThisForm.sICO.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sICOForJS.value);
			submitForm = false;
	}
	if(ThisForm.sCity.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sCityForJS.value);
			submitForm = false;
	}
	if(ThisForm.sPhone.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sPhoneForJS.value);
			submitForm = false;
	}
	if(ThisForm.sLoginName){
		if(ThisForm.sLoginName.value==''){
			if(strHTML != ''){
			strHTML += "\n"
			}
			strHTML += (ThisForm.sLoginNameForJS.value);
			submitForm = false;
		}
	}


	if(!submitForm){
		alert(strHTML);
		return false
	}
	
}