

 var websiteURL="http://www.mgmanager.gr/";
// var websiteURL="http://www.beautyworks.gr/";
	var dtCh= ".";
	var minYear=1900;
	var maxYear=2100;

function prepare_submit(act,st,o,et,q) {
	var frm=document.srtfrm;
	
	frm.start.value=st;
	frm.ord.value=o;
	frm.query.value=q;
	frm.e.value=et;
	
	frm.action=act;
	frm.submit();
 
}

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function print_me(){
	printwindow=window.open(websiteURL+'shop/templates/print.html','printwindow'); 
	printwindow.document.write(this.document.getElementById('toprint').innerHTML);
	printwindow.print();
}

function submit_mail_form(frm,err1,err2){
	f=frm;
	if (
		EmptyString(f.name.value) ||
		EmptyString(f.sname.value) ||
		EmptyString(f.email.value) ||
		EmptyString(f.msg.value)
		) alert(err1);		
	else if (f.msg.value.length>500) alert(err2);
	else f.submit();
	
}

function submit_review(tit,txt,frm,err1,err2){
	if (EmptyString(tit.value) || EmptyString(txt.value)) alert(err1);
	else if (txt.value.length>500) alert(err2);
	else frm.submit();
	
}

function show_details(id){	
	for (i=1;i<=4;i++){
		document.getElementById('tab-'+i).className='';
		$('#div-'+i).hide();
	}
	document.getElementById('tab-'+id).className='on';
	$('#div-'+id).show('show');
}

function add2basket(pid,msg) {
		var q=1;	
		/*if (document.getElementById('qty').value>0){
			q=document.getElementById('qty').value;
			if (document.getElementById('qty').value>1){
				document.getElementById('num_of_prods').innerHTML = text12 + ' '+ q + ' ' + text2;
			}
			else{
				document.getElementById('num_of_prods').innerHTML = text11 + ' '+ q + ' ' + text2;;
			}	
		}	
		else{
			q=0;	
		}*/	
		a = new sack();
		a.requestFile = websiteURL+'shop/x_add2basket.php?r='+Math.random();
		a.setVar('id',pid);
		a.setVar('act','add');
		a.setVar('q',q);
		a.onCompletion = function(){ if(a.response=='OK') { 
				alert(msg);
				showBasketContents(false,pid);
			} else{ 
				//document.getElementById('layera').style.display="block";
				//document.getElementById('num_of_prods').innerHTML = a.response;
				alert(a.response);
			}
		}	
		a.runAJAX();				
}

function pdf2print(){
	pid=document.pdf2p_form.pid.value;
	old_code=document.pdf2p_form.old_code.value;
	a = new sack();
	a.requestFile = websiteURL+'shop/x_pdf2print.php?r='+Math.random();
	a.setVar('pid',pid);
	a.onCompletion = function(){ 
		if (a.response=='ok'){
			//window.open(websiteURL + 'assets/media/PDF2PRINT/mgmanager'+old_code+'.pdf','Download'); 
			//window.open=(websiteURL + 'assets/media/PDF2PRINT/mgmanager'+old_code+'.pdf','Download');
			window.open(websiteURL + 'assets/media/PDF2PRINT/mgmanager'+old_code+'.pdf',"width=800,height=1000,scrollbars=yes,alwaysraised=yes,resizable=yes");
		}
		else 
			alert(a.response);
	}		
	a.runAJAX();	
}		

function close_layera() {
	document.getElementById('layera').style.display="none";
}
	
function add2newsletter(){
	var email;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	email=document.getElementById('email').value;
	if (filter.test(email)){
		a = new sack();
		a.setVar('email',email);
		a.requestFile = websiteURL+'shop/saveNewsletter.php?r='+Math.random();
		a.onCompletion = function(){ alert(a.response); }
		a.runAJAX();				
	}
}

function showBasketContents(scr,pid) {
		var sp;
		a = new sack();
		a.setVar('id',pid);
		a.requestFile = websiteURL+'shop/x_showbasket.php?r='+Math.random();
		a.onCompletion = function(){ 
				if(document.getElementById('total-prods')) d1=document.getElementById('total-prods');
				if(document.getElementById('total_prc')) d2=document.getElementById('total_prc');
				else {d1=''; d2='';}
					if(d1&&d2) {
						sp=a.response.split('_');
						d1.innerHTML=sp[0];
						d2.innerHTML=sp[1]; 
					}
			}
		a.runAJAX();		
}

function add2wishlist(pid,msg) {

		var q=1;	
		
		a = new sack();
		a.requestFile = websiteURL+'shop/x_add2wishlist.php?r='+Math.random();
		a.setVar('id',pid);
		a.setVar('act','add');
		a.setVar('q',q);
		a.onCompletion = function(){ if(a.response=='OK') { 
				alert(msg); 
				showWishlistContents(false,pid);
			} else alert(a.response); }
		a.runAJAX();				
}

function showWishlistContents(scr,pid) {
		a = new sack();
		a.setVar('id',pid);
		a.requestFile = websiteURL+'shop/x_showwishlist.php?r='+Math.random();
		a.onCompletion = function(){ 
				if(document.getElementById('wishlist_contents_div')) d=document.getElementById('wishlist_contents_div');
				else d='';
					if(d) {
						d.innerHTML=a.response; 
					}
			}
		a.runAJAX();		
}



function updatebasketitem(pids,msg) {
		var q=0;
		var rmv=0;
		var rmv_vals="";
		var q_vals=0;
		var pid=pids.split(",");
		for (i=0;i<pid.length;i++)
			if(document.getElementById('bq_'+pid[i])){
				q=document.getElementById('bq_'+pid[i]).value;
				rmv=document.getElementById('rmv_'+pid[i]).value;
				if(q<=0 || !isInteger(q)) {
					alert(msg);
					return false;
				} else q_vals=q_vals+document.getElementById('bq_'+pid[i]).value+'_';
				if (rmv=='yes')
					rmv_vals=rmv_vals+document.getElementById('rmv_'+pid[i]).value+'_';	
				else	
					rmv_vals=rmv_vals+'no'+'_';		
			}
		location.href=websiteURL+'shop/x_updatebasket.php?qvals='+q_vals+'&rmvvals='+rmv_vals;
	}

function updatewishlist(pids,msg) {
	var q=0;
	var q_vals=0;
	var pid=pids.split("_");
	for (i=0;i<pid.length;i++)
		if(document.getElementById('bq_'+pid[i])){
			q=document.getElementById('bq_'+pid[i]).value;
			if(q<=0 || !isInteger(q)) {
				alert(msg);
				return false;
			} else q_vals=q_vals+document.getElementById('bq_'+pid[i]).value+'_';
		}
	location.href=websiteURL+'shop/x_updatewishlist.php?pids='+pids+'&qvals='+q_vals;
}

function removebasketitem(pid){
	var rmv=0;
	if (document.getElementById('rmv_'+pid).value=='yes')
		document.getElementById('rmv_'+pid).value='no';
	else
		document.getElementById('rmv_'+pid).value='yes';
}	
	


function EmptyString(str){
		    return (AllTrim(str) == "");
		  }

function AllTrim(str2){
		  	var str;
		    for(var i = 0; i < str2.length; i++)
		      if(str2.charAt(i) != " ") break;
		    str = str2.substr(i, str2.length-i);
		
		    for(var i = str.length-1; i > 0; i--)
		      if(str.charAt(i) != " ")
		        break;
		    str = str.substr(0, i+1);
		
		    return str;
}

function submitsignup(nextlink){
	var gender;
	var fname;
	var lname;
	var bdate;
	var email;
	var val_email;
	var address;
	var zip;
	var country;
	var phone;
	var fax;
	var pass;
	var val_pass;
	var check1;
	var check2;
	var check3;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	//gender=document.suf.bill_to_gender[0].value;
	fname=document.suf.bill_to_firstname.value;
	lname=document.suf.bill_to_lastname.value;
	bdate=document.suf.bill_to_birthdate.value;
	email=document.suf.bill_to_email.value;	 
	val_email= document.suf.bill_to_validateEmail.value;
	address=document.suf.bill_to_address.value;
	zip=document.suf.bill_to_postcode.value;
	country='Ελλάδα';
	phone=document.suf.bill_to_telephone1.value;
	fax=document.suf.bill_to_telephone2.value;
	pass=document.suf.bill_to_password.value;
	val_pass=document.suf.bill_to_validatepassword.value;
	check1=document.suf.check_newsletter.checked;
	check2=document.suf.check_conf.checked;
	check3=document.suf.check_agreed.checked;
	
	if (((!(document.suf.bill_to_gender[0].checked))&&(!(document.suf.bill_to_gender[1].checked)))||(fname=='')||(lname=='')||(!isDate(bdate))||(!filter.test(email))||(email!=val_email)||(address=='')||(zip=='')||(phone=='')||(country=='')||(!check2)||(pass=='')||(val_pass!=pass)||(pass.length<6)||(pass.length>12)){
		closeallErrors();
		//document.getElementById('sign_up_error').style.display="block";
		$('#sign_up_error').show(200);
		if ((!(document.suf.bill_to_gender[0].checked))&&(!(document.suf.bill_to_gender[1].checked)))
			$('#su_error1').show(200);
		if (fname=='')
			$('#su_error2').show(200);
		if (lname=='')
			$('#su_error3').show(200);
		if (!isDate(bdate))
			$('#su_error4').show(200);
		if ((!filter.test(email)) ||(email!=val_email))
			$('#su_error5').show(200);
		if (address=='')
			$('#su_error6').show(200);
		if ((zip=='')||(country==''))
			$('#su_error7').show(200);
		if (phone=='')
			$('#su_error8').show(200);
		if ((pass=='')||(val_pass!=pass)||(pass.length<6)||(pass.length>12))
			$('#su_error9').show(200);
		if (!check2)
			$('#su_error10').show(200);	
	}
	else{
		a = new sack();
		if (document.suf.bill_to_gender[0].checked)
			a.setVar('bill_to_gender','M');
		else
			a.setVar('bill_to_gender','F');	
		a.setVar('bill_to_firstname',fname);
		a.setVar('bill_to_lastname',lname);
		a.setVar('bill_to_birthdate',bdate);
		a.setVar('bill_to_email',email);
		a.setVar('bill_to_address',address);
		a.setVar('bill_to_postcode',zip);
		a.setVar('bill_to_city',country);
		a.setVar('bill_to_telephone1',phone);
		a.setVar('bill_to_telephone2',fax);
		a.setVar('bill_to_password',pass);
		if (check1)
			a.setVar('check_news','Y');
		else 
			a.setVar('check_news','N');	
		if (check2)	
			a.setVar('check_conf','Y');
		else
			a.setVar('check_conf','N');
		if (check3)				
			a.setVar('check_agreed','Y');
		else
			a.setVar('check_agreed','N');	
		a.requestFile = websiteURL+'shop/x_storebilling.php?r='+Math.random();
		a.onCompletion = function(){ if(a.response=='OK') { 
				location.href=nextlink;
			} else if (a.response=='OK2'){location.href=websiteURL+'shop/index.php';}
			else alert(a.response); }
		a.runAJAX();				
	}
}

function closeallErrors(){
		$('#sign_up_error').hide();
		$("#su_error1").hide();
		$("#su_error2").hide(); 
		$("#su_error3").hide();
		$("#su_error4").hide(); 
		$("#su_error5").hide(); 
		$("#su_error6").hide();
		$("#su_error7").hide();
		$("#su_error8").hide(); 
		$("#su_error9").hide(); 
		$("#su_error10").hide();
}
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
	  //alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

function checkAccount(){
	var fname=document.acf.fname.value;
	var lname=document.acf.lname.value;		
	var bdate=document.acf.bdate.value;	
	var email=document.acf.email.value;
	var address=document.acf.address.value;	
	var zip=document.acf.zip.value;
	var city=document.acf.city.value;
	var country='Ελλάδα';
	var phone=document.acf.phone.value;
	var fax=document.acf.fax.value;
	var bdate_error=document.acf.bdate_error.value;
	var email_error=document.acf.email_error.value;
	var gen_error=document.acf.gen_error.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!isDate(bdate))
		alert (bdate_error);
	else if (!filter.test(email))
		alert (email_error);
	else if (((!(document.acf.gender[0].checked))&&(!(document.acf.gender[1].checked)))||(fname=='')||(lname=='')||(address=='')||(zip=='')||(city=='')||(phone==''))	
		alert (gen_error);
	else
		document.acf.submit();
}			

// Homepage Model Layers
function show_layer_a(i,cmd){
	var k;
	for (k=0; k<cmd; k++){
		$('#layer'+k).hide();
		document.getElementById('spec_model'+k).style.opacity="0.4";
		document.getElementById('spec_model'+k).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
		//document.getElementById('spec_model_img'+k).style.filter="alpha(opacity=40)";
	}	
	$('#layer'+i).show(200);	
	//document.getElementById('spec_model'+i).style.opacity="100";
}
function hide_layer_a(i,cmd){
	var k;
	for (k=0; k<cmd; k++){
		document.getElementById('spec_model'+k).style.opacity="100";
		document.getElementById('spec_model'+k).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
		//document.getElementById('spec_model_img'+k).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
	}
	$('#layer'+i).hide();
}			
function show_layer_b(i,cmd,j,gmd){
	var k,l;
	for (k=0; k<cmd; k++){
		for (l=0; l<gmd; l++){
			$('#ger_md'+k+''+l).hide();
			if (k==i){
				document.getElementById('year'+k+''+l).style.color="#aaaaaa";
				$('#md_photo'+k+''+l).hide(200);
			}
		}	
	}		
	$('#ger_md'+i+''+j).show(200);
	document.getElementById('year'+i+''+j).style.color="#000000";
	$('#md_photo'+i+''+j).show(200);
}	

						
