
// var websiteURL="http://74.54.189.219/~beautywo/";
// var websiteURL="http://localhost/stix/beautyworks.gr/";
 var websiteURL="http://www.beautyworks.gr/";

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;	
		
		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 alert(a.response); }
		a.runAJAX();				
}

function showBasketContents(scr,pid) {
		a = new sack();
		a.setVar('id',pid);
		a.requestFile = websiteURL+'shop/x_showbasket.php?r='+Math.random();
		a.onCompletion = function(){ 
				if(document.getElementById('basket_contents_div')) d=document.getElementById('basket_contents_div');
				else d='';
					if(d) {
						d.innerHTML=a.response; 
					}
			}
		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 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_updatebasket.php?qvals='+q_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 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;
}
		  

