///////////////////////////////////////////////////////////////////////
function doWork(){

var name=document.register_user.name.value;
		var surname=document.register_user.surname.value;
		var address=document.register_user.address.value;
		var city=document.register_user.city.value;
		var ps=document.register_user.ps.value;
		var tel=document.register_user.tel.value;
		var country=document.register_user.country.value;
		var email=document.register_user.email.value;

if (name.length==0){
		document.register_user.name.style.backgroundColor="#FFFF99";
		document.register_user.name.focus();
		alert ('Pls enter your name.');
		return false;
		}
		else {
		document.register_user.name.style.backgroundColor="#FFFFFF";
		}
	
		if (surname.length==0){
		document.register_user.surname.style.backgroundColor="#FFFF99";
		document.register_user.surname.focus();
		alert ('Pls enter your surname.');
		return false;
		}
		else {
		document.register_user.surname.style.backgroundColor="#FFFFFF";
		}

		if (address.length==0){
		document.register_user.address.style.backgroundColor="#FFFF99";
		document.register_user.address.focus();
		alert ('Pls enter street address.');
		return false;
		}
		else {
		document.register_user.address.style.backgroundColor="#FFFFFF";
		}

		if (city.length==0){
		document.register_user.city.style.backgroundColor="#FFFF99";
		document.register_user.city.focus();
		alert ('Pls enter city.');
		return false;
		}
		else {
		document.register_user.city.style.backgroundColor="#FFFFFF";
		}


		if (ps.length==0 || ps.length>20){
		document.register_user.ps.style.backgroundColor="#FFFF99";
		document.register_user.ps.focus();
		alert ('Pls enter Valid P.S.Code');
		return false;
		}
		else {
		document.register_user.ps.style.backgroundColor="#FFFFFF";
		}

		//if (tel.length<10 || tel.length>20 || isNaN(tel)){
		//document.register_user.tel.style.backgroundColor="#FFFF99";
		//document.register_user.tel.focus();
		//alert ('Pls enter valid telephone number (10-20 digits,including area,country code)');
		//return false;
		//}
		//else {
		//document.register_user.tel.style.backgroundColor="#FFFFFF";
		//}

		if (country==0 ){
		document.register_user.country.style.backgroundColor="#FFFF99";
		document.register_user.country.focus();
		alert ('Pls Select Country');
		return false;
		}
		else {
		document.register_user.country.style.backgroundColor="#FFFFFF";
		}

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
		document.register_user.email.style.backgroundColor="#FFFF99";
		document.register_user.email.focus();
		alert("Pls enter valid email address");
		return false;	}
		else {
		document.register_user.email.style.backgroundColor="#FFFFFF";
		}


if (window.ActiveXObject) { 
httpObject = new ActiveXObject("Microsoft.XMLHTTP");
httpObject2 = new ActiveXObject("Microsoft.XMLHTTP");
} //telos if
else if (window.XMLHttpRequest) {
httpObject = new XMLHttpRequest(); 
httpObject2 = new XMLHttpRequest();
} //TELOS ELSE IF
// ORISA TO OBJECT GIA TON IE kai GIA TOUS ALLOUS BROWSERS
httpObject.open("GET", "get_all.php?username="+document.getElementById("username").value, true);
httpObject2.open("GET", "get_all.php?email="+document.getElementById("email").value, true);

httpObject.onreadystatechange   = function() {
        if (httpObject.readyState == 1)
   		{
       document.getElementById("username_verification").value = "wait";
		}
      	else if (httpObject.readyState == 4 && httpObject.status==200)
        {
        document.getElementById("username_verification").value = httpObject.responseText;
		}
		} // telos xmlhttp.onreadystatechange 
httpObject2.onreadystatechange   = function() {
        if (httpObject2.readyState == 1)
   		{
	    document.getElementById("email_verification").value = "wait";
		}
      	else if (httpObject2.readyState == 4 && httpObject2.status==200)
        {
        document.getElementById("email_verification").value = httpObject2.responseText;
		}
		} // telos xmlhttp.onreadystatechange 


httpObject.send(null);
httpObject2.send(null);



setTimeout("some()", 800);

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function some(){
if (document.getElementById("email_verification").value =='1' && document.getElementById("username_verification").value =='1'){
document.getElementById("username").style.backgroundColor="#FFFF99";
document.getElementById("email").style.backgroundColor="#FFFF99";
alert ("Username and email exists!Pls choose other.");
document.getElementById("username").focus();
return false;
} // KLEINEI TO IF

else if (document.getElementById("username_verification").value =='1'){
document.getElementById("username").style.backgroundColor="#FFFF99";
document.getElementById("email").style.backgroundColor="#FFFFFF";
alert ("Username exists!Pls choose another.");
document.getElementById("username").focus();
return false;
} // KLEINEI TO IF

else if (document.getElementById("email_verification").value =='1'){
document.getElementById("email").style.backgroundColor="#FFFF99";
document.getElementById("username").style.backgroundColor="#FFFFFF";
alert ("Email exists!Pls use another.");
document.getElementById("email").focus();
return false;
} // KLEINEI TO IF

else {
	
	
		var username=document.register_user.username.value;
		var password=document.register_user.password.value;
		var password2=document.register_user.password2.value;

		if (username.length<5 || username.length>15 || isNaN(username)==false){
		document.register_user.username.style.backgroundColor="#FFFF99";
		document.register_user.username.focus();
		alert ('Username must be 5-15 characters long');
		return false;
		}
		else {
		document.register_user.username.style.backgroundColor="#FFFFFF";
		}


if (password.length<5 || password.length>15){
		document.register_user.password.style.backgroundColor="#FFFF99";
		document.register_user.password.focus();
		alert ('Password must be 5-15 characters long');
		return false;
		}
		else {
		document.register_user.password.style.backgroundColor="#FFFFFF";
		}


if (password2!=password){
		document.register_user.password2.style.backgroundColor="#FFFF99";
		document.register_user.password2.focus();
		alert ('Invalid password confirmation');
		return false;
		}
		else {
		document.register_user.password2.style.backgroundColor="#FFFFFF";
		}

document.register_user.submit(); 
} // KLEINEI TO ELSE
} // KLEINEI TO SOME
//////////////////////////////////////////////////////////////////////////////////////////////////
function clearText(field){
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function validate_contact(){
var name=document.contact.name.value;
//var tel=document.contact.tel.value;
var email=document.contact.email_contact.value;
var comments=document.contact.comments.value;

if (name.length<5 || isNaN(name)==false){
alert ('Pls enter your full name.');
return false;
}

//if (tel.length<10 || isNaN(tel)==true){
//alert ('Pls enter telephone number.');
//return false;
//}

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
	alert("Pls enter valid email address");
	return false;
	}

if (comments=="" || comments=="Message"){
alert ('Pls enter comment.');
return false;}

document.contact.submit();
}
//////////////////////////////////////////////////////////////////////////////
function validate_login(){
var username=document.login.username.value;
var password=document.login.password.value;

if (username.length<5 || username.length>15 || username=='username'){
return false;
}

if (password.length<5 || password.length>15 || password=='password'){
return false;
}

document.login.submit();
}
//////////////////////////////////////////////////////////////////////////////
function calculate_price(){
var product_qty=document.getElementById('product_qty').value;
var product_price=document.getElementById('product_price').value;
var product_total_price=product_qty*product_price;

var zero=0;
var one=1;

if (isNaN(product_qty) || product_qty<0.5 || product_qty>1000){
document.getElementById('show_price_result').style.display='block';
document.getElementById('product_total_price').value=zero.toFixed(2);
}
else {
document.getElementById('show_price_result').style.display='none';
document.getElementById('product_total_price').value=product_total_price.toFixed(2);
}

}
//////////////////////////////////////////////////////////////////////////////
function calculate_basket(x){

//alert (x);
//document.forms['frmMyForm' + intIndex]
var product_qty=document.forms['basket'+x+'_'+1].product_qty.value;
//alert (product_qty);
//var product_price=document.getElementById('product_price').value;
//var product_total_price=product_qty*product_price;

//var zero=0;
//var one=1;

if (isNaN(product_qty) || product_qty<0.5 || product_qty>1000){
document.getElementById('order').innerHTML="<a href='javascript:void(0);' class='button1 floatright'><span>Order</span></a>";
document.getElementById('show_price_result'+x).style.display='block';
//document.getElementById('product_total_price').value=zero.toFixed(2);
}
else {
document.getElementById('show_price_result'+x).style.display='none';
document.getElementById('order').innerHTML="<a href='javascript:void(0);user_ok();' class='button1 floatright' ><span>Order</span></a>";
//document.getElementById('product_total_price').value=product_total_price.toFixed(2);
}

}
//////////////////////////////////////////////////////////////////////////////
function calculate_basket2(x){

//alert (x);
var product_qty_sample=document.getElementById('product_qty_sample'+x).value;

if (isNaN(product_qty_sample) || product_qty_sample<1 || product_qty_sample>20){
document.getElementById('order').innerHTML="<a href='javascript:void(0);' class='button1 floatright'><span>Order</span></a>";
document.getElementById('show_price_result_sample'+x).style.display='block';
//document.getElementById('product_total_price').value=zero.toFixed(2);
}
else {
document.getElementById('show_price_result_sample'+x).style.display='none';
document.getElementById('order').innerHTML="<a href='javascript:void(0);user_ok();' class='button1 floatright' ><span>Order</span></a>";
//document.getElementById('product_total_price').value=product_total_price.toFixed(2);
}

}
//////////////////////////////////////////////////////////////////////////////
function user_ok(){
if (document.getElementById('user_ok').value=="" || document.getElementById('user_ok').value==null
|| document.getElementById('user_ok').value=="0" || isNaN(document.getElementById('user_ok').value) ) {
	//alert ('Pls Login first to continue with your order');
	document.getElementById('alert_msg').style.display='block';
	}

else if (document.getElementById('items_bag').value==0 ) {
	alert ('No products in your bag');
	}

else {
window.location="basket-step2.php";
	}


}


//////////////////////////////////////////////////////////////////////////////




function pro_change(){
var change_product=document.getElementById('change_product').value;
window.location=change_product;

}
//////////////////////////////////////////////////////////////////////////////
function add_product(){
var product_id=document.getElementById('product_id').value;
var product_total_price=document.getElementById('product_total_price').value;

if (product_total_price==0){
	alert ('Pls select how many meters of fabric you want to order');
	}
else 	{
		document.addproduct.submit();
		}
}
//////////////////////////////////////////////////////////////////////////////
function change_pass_state(){

if (document.getElementById('change_pass').checked==true){
document.getElementById('password').disabled=false;
document.getElementById('password2').disabled=false;
}
else if (document.getElementById('change_pass').checked==false){
document.getElementById('password').disabled=true;
document.getElementById('password2').disabled=true;
}
}
/////////////////////////////////////////////////////////////////
function doWork2(){

var name=document.updateuser.name.value;
		var surname=document.updateuser.surname.value;
		var address=document.updateuser.address.value;
		var city=document.updateuser.city.value;
		var ps=document.updateuser.ps.value;
		var tel=document.updateuser.tel.value;
		var country=document.updateuser.country.value;
		var email=document.updateuser.email.value;


if (name.length==0){
		document.updateuser.name.style.backgroundColor="#FFFF99";
		document.updateuser.name.focus();
		alert ('Pls enter your name.');
		return false;
		}
		else {
		document.updateuser.name.style.backgroundColor="#FFFFFF";
		}
	
		if (surname.length==0){
		document.updateuser.surname.style.backgroundColor="#FFFF99";
		document.updateuser.surname.focus();
		alert ('Pls enter your surname.');
		return false;
		}
		else {
		document.updateuser.surname.style.backgroundColor="#FFFFFF";
		}

		if (address.length==0){
		document.updateuser.address.style.backgroundColor="#FFFF99";
		document.updateuser.address.focus();
		alert ('Pls enter street address.');
		return false;
		}
		else {
		document.updateuser.address.style.backgroundColor="#FFFFFF";
		}

		if (city.length==0){
		document.updateuser.city.style.backgroundColor="#FFFF99";
		document.updateuser.city.focus();
		alert ('Pls enter city.');
		return false;
		}
		else {
		document.updateuser.city.style.backgroundColor="#FFFFFF";
		}


		if (ps.length==0 || ps.length>20){
		document.updateuser.ps.style.backgroundColor="#FFFF99";
		document.updateuser.ps.focus();
		alert ('Pls enter Valid P.S.Code');
		return false;
		}
		else {
		document.updateuser.ps.style.backgroundColor="#FFFFFF";
		}

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
		document.updateuser.email.style.backgroundColor="#FFFF99";
		document.updateuser.email.focus();
		alert("Pls enter valid email address");
		return false;	}
		else {
		document.updateuser.email.style.backgroundColor="#FFFFFF";
		}


if (window.ActiveXObject) { 
httpObject2 = new ActiveXObject("Microsoft.XMLHTTP");
} //telos if
else if (window.XMLHttpRequest) {
httpObject2 = new XMLHttpRequest();
} //TELOS ELSE IF
// ORISA TO OBJECT GIA TON IE kai GIA TOUS ALLOUS BROWSERS
httpObject2.open("GET", "get_all.php?changeemail="+document.getElementById("email").value, true);

httpObject2.onreadystatechange   = function() {
        if (httpObject2.readyState == 1)
   		{
	    document.getElementById("email_verification").value = "wait";
		}
      	else if (httpObject2.readyState == 4 && httpObject2.status==200)
        {
        document.getElementById("email_verification").value = httpObject2.responseText;
		}
		} // telos xmlhttp.onreadystatechange 

httpObject2.send(null);


setTimeout("some2()", 800);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function some2(){

if (document.getElementById("email_verification").value =='1'){
document.getElementById("email").style.backgroundColor="#FFFF99";
alert ("Email exists!Pls use another.");
document.getElementById("email").focus();
return false;
} // KLEINEI TO IF

else {
		
	if (document.getElementById('change_pass').checked==true){

		var password=document.updateuser.password.value;
		var password2=document.updateuser.password2.value;

		if (password.length<5 || password.length>15){
		document.updateuser.password.style.backgroundColor="#FFFF99";
		document.updateuser.password.focus();
		alert ('Password must be 5-15 characters long');
		return false;
		}
		else {
		document.updateuser.password.style.backgroundColor="#FFFFFF";
		}

		if (password2!=password){
		document.updateuser.password2.style.backgroundColor="#FFFF99";
		document.updateuser.password2.focus();
		alert ('Invalid password confirmation');
		return false;
		}
		else {
		document.updateuser.password2.style.backgroundColor="#FFFFFF";
		}

	} // KLEINEI TO AN THELEI NA ALLAXEI PASS

document.updateuser.submit(); 
} // KLEINEI TO ELSE
} // KLEINEI TO SOME
//////////////////////////////////////////////////////////////////////////////////////////////////
function forgot_pass(){

var email=document.forgotpass.email.value;

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
	alert("Pls enter valid email address");
	return false;
	}

document.forgotpass.submit();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function check_shipping(){

if (document.basket2.radio[1].checked==true){
	document.getElementById('new_info').style.display='block';
	}
if (document.basket2.radio[0].checked==true){
	document.getElementById('new_info').style.display='none';
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
function validate_new_shipping(){

if (document.basket2.radio[1].checked==true){

		var first_name2=document.basket2.first_name2.value;
		var last_name2=document.basket2.last_name2.value;
		var address_12=document.basket2.address_12.value;
		var city2=document.basket2.city2.value;
		var zip2=document.basket2.zip2.value;
		var tel2=document.basket2.tel2.value;
		var email2=document.basket2.email2.value;

		if (first_name2.length==0){
		document.basket2.first_name2.style.backgroundColor="#FFFF99";
		document.basket2.first_name2.focus();
		alert ('Pls enter your name.');
		return false;
		}
		else {
		document.basket2.first_name2.style.backgroundColor="#FFFFFF";
		}
	
		if (last_name2.length==0){
		document.basket2.last_name2.style.backgroundColor="#FFFF99";
		document.basket2.last_name2.focus();
		alert ('Pls enter your surname.');
		return false;
		}
		else {
		document.basket2.last_name2.style.backgroundColor="#FFFFFF";
		}

		if (address_12.length==0){
		document.basket2.address_12.style.backgroundColor="#FFFF99";
		document.basket2.address_12.focus();
		alert ('Pls enter street address.');
		return false;
		}
		else {
		document.basket2.address_12.style.backgroundColor="#FFFFFF";
		}

		if (city2.length==0){
		document.basket2.city2.style.backgroundColor="#FFFF99";
		document.basket2.city2.focus();
		alert ('Pls enter city.');
		return false;
		}
		else {
		document.basket2.city2.style.backgroundColor="#FFFFFF";
		}

		if (zip2.length==0 || zip2.length>20){
		document.basket2.zip2.style.backgroundColor="#FFFF99";
		document.basket2.zip2.focus();
		alert ('Pls enter Valid P.S.Code');
		return false;
		}
		else {
		document.basket2.zip2.style.backgroundColor="#FFFFFF";
		}

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email2)==false){
		document.basket2.email2.style.backgroundColor="#FFFF99";
		document.basket2.email2.focus();
		alert("Pls enter valid email address");
		return false;	}
		else {
		document.basket2.email2.style.backgroundColor="#FFFFFF";
		}

} // KLEINEI TO IF SHIPPING 2
document.basket2.submit();
}
////////////////////////////////////////////////////////////////////////////////////////////
function change_post(){
var country_kg=document.basket2.country_kg.value;	
	
	if (document.basket2.select2.value=='Post'){
		document.basket2.post_cost.value=(country_kg*9.5).toFixed(2);
	}
if (document.basket2.select2.value=='Courier (DHL)'){
		document.basket2.post_cost.value=(country_kg*27).toFixed(2);
	}
}
////////////////////////////////////////////////////////////////////////////////////////////
