<!--
// JavaScript Document for http://www.knigi-kupibg.com ("js/js.js") //k&k/15/12/2008 
/*-----------------------------------------------------------------------*/
var popupwin = 0;
function zoom(isbn,w,h){
	try{if(popupwin){if(typeof(popupwin == Object)){if(!popupwin.closed)popupwin.close();}}}catch(error){}
	_left = (screen.width) ? (screen.width-w)/2 : 0;
    _top = (screen.height) ? (screen.height-h)/2 : 0;
	var path = 'imgpreview.php?isbn='+isbn;
	popupwin = open (path,'popupwin','status="yes",toolbar=0,location=0,directories=0,menubar=0,scrollbars=0resizable=0,copyhistory=0,width='+w+',height='+h+',left=0px, top=0px,screenX=0px,screenY=0px');
	popupwin.self.focus();
}
function openprivacy(file,w,h){
	try{if(popupwin){if(typeof(popupwin == Object)){if(!popupwin.closed)popupwin.close();}}}catch(error){}
	//_left = (screen.width) ? (screen.width-w)/2 : 0;
    //_top = (screen.height) ? (screen.height-h)/2 : 0;
	
	_left = 0;
    _top = 0;
	
	
	var path = file;
	popupwin = open (path,'popupwin','status="yes",toolbar=0,location=0,directories=0,menubar=0,scrollbars=yes,resizable=0,copyhistory=0,width='+w+',height='+h+',left='+_left+'px, top='+_top+'px,screenX='+_left+'px,screenY='+_top+'px');
	popupwin.self.focus();
}
function opencodes(img)
{
open("foto/books/"+img+".jpg", 'codes', 'width=410, height=550, location=no, toolbar=no, resizable=yes, scrollbars=yes');
//open('include/codes.htm', 'codes', 'width=440, height=600, location=no, toolbar=no, resizable=yes, scrollbars=yes');
}
function opentransport(){ open('include/delivery_bg.html', 'codes', 'width=300, height=300, location=no, toolbar=no, resizable=yes, scrollbars=yes');
}
function checkForm() 
{
        if(eval(document.all2.email).value!=''){
			var re = /^[a-zA-Z0-9_.\-]+@[a-zA-Z0-9.\-]+[a-zA-Z0-9\-]\.[a-zA-Z][a-zA-Z]+$/;
			if (!re.test(document.all2.email.value)) {
				alert('Невалиден e-mail адрес!');
				document.all2.email.focus();
				document.all2.email.select();
				return false;
			   }
		   }
		if(eval(document.all2.ship_email).value!=''){
			var re = /^[a-zA-Z0-9_.\-]+@[a-zA-Z0-9.\-]+[a-zA-Z0-9\-]\.[a-zA-Z][a-zA-Z]+$/;
			if (!re.test(document.all2.ship_email.value)) {
				alert('Невалиден e-mail адрес за доставката!');
				document.all2.ship_email.focus();
				document.all2.ship_email.select();
				return false;
			   }
		   }
	   /*	   
	   if((eval(document.all2.ship_name).value!='' || //1
		   eval(document.all2.ship_address).value!='' || //2
		   eval(document.all2.ship_city).value!='' || //3
		   //eval(document.all2.ship_state).value!='' || //4
		   eval(document.all2.ship_zip).value!='' || //5
		   eval(document.all2.ship_country).value!='' || //6
		   eval(document.all2.ship_telefon).value!='') && //7
		  (eval(document.all2.ship_name).value=='' || //1
		   eval(document.all2.ship_address).value=='' || //2
		   eval(document.all2.ship_city).value=='' || //3
		   //eval(document.all2.ship_state).value=='' || //4
		   eval(document.all2.ship_zip).value=='' || //5
		   eval(document.all2.ship_country).value=='' || //6
		   eval(document.all2.ship_telefon).value=='')//7		   
		  ){			
				alert('Попълнете и останалите полета за доставката!');				
				return false;			
		  }
		*/ 
		/* 1S */   
		if(eval(document.all2.ship_name).value!=''){
			//var re = /^[A-Za-z0-9А-Яа-яЅ\-_'.\ ]+$/;
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+[  ]+[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.ship_name.value) || onlySymbolsValidator(document.all2.ship_name.value))
			 {
				alert('Невалидни Име и Фамилия за доставката!');
				document.all2.ship_name.focus();
				document.all2.ship_name.select();
				return false;
			 }
		  }
		/* 2S */
		if(eval(document.all2.ship_address).value!=''){
			//var re = /^[A-Za-z0-9А-Яа-яЅ\-_'.\ ]+$/;
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.№,\ ]+[  ]+[A-Za-z0-9А-Яа-яЅ\-'.№,\ ]+$/;
			if (!re.test(document.all2.ship_address.value) || onlySymbolsValidator(document.all2.ship_address.value)) 
			{
				alert('Невалиден Адрес за доставката!');
				document.all2.ship_address.focus();
				document.all2.ship_address.select();
				return false;
			}
		}
		/* 3S */
		if(eval(document.all2.ship_city).value!=''){
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.ship_city.value) || onlySymbolsValidator(document.all2.ship_city.value)) {
				alert('Невалиден Град / Село за доставката!');
				document.all2.ship_city.focus();
				document.all2.ship_city.select();
				return false;
			}
		}
		/* 4S */
		if(eval(document.all2.ship_state).value!=''){
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.ship_state.value) || onlySymbolsValidator(document.all2.ship_state.value)) 
			{
				alert('Невалидна Област за доставката!');
				document.all2.ship_state.focus();
				document.all2.ship_state.select();
				return false;
			}
		}
		/* 5S */
		if(eval(document.all2.ship_zip).value!=''){
			var re = /^[0-9 ]+$/;
			if (!re.test(document.all2.ship_zip.value) || onlySymbolsValidator(document.all2.ship_zip.value))
			{
				alert('Невалиден пощенски код за доставката!');
				document.all2.ship_zip.focus();
				document.all2.ship_zip.select();
				return false;
			}
		}
		/* 6S */
		if(eval(document.all2.ship_country).value!=''){
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.ship_country.value) || onlySymbolsValidator(document.all2.ship_country.value)) 
			{
				alert('Невалидна Държава за доставката!');
				document.all2.ship_country.focus();
				document.all2.ship_country.select();
				return false;
			}
		}
		/* 7S */
		if(eval(document.all2.ship_telefon).value!=''){
			var re = /^[\+0-9]+[\+0-9 \\/]+$/;
			if (!re.test(document.all2.ship_telefon.value) || onlySymbolsValidator(document.all2.ship_telefon.value)) 
			{
				alert('Невалиден телефонен номер за доставката!');
				document.all2.ship_telefon.focus();
				document.all2.ship_telefon.select();
				return false;
			}
		}
	
//var names=new Array('name','address','city','state','zip','country','telefon');
//var names2=new Array('Име и Фамилия','Адрес','Град','Област','Пощенски код','Държава','Телефон');
	var names=new Array('name','address','city','zip','country','telefon');
	var names2=new Array('Име и Фамилия','Адрес','Град','Пощенски код','Държава','Телефон');
	//for (var i=0;i<=10;i++){
	for (var i=0;i<=7;i++){
		if (eval('document.all2.'+names[i]).value==''){
			alert('Моля, въведете '+names2[i]+'!');
			eval('document.all2.'+names[i]).focus();
			return false;
		}
		/* 1 */
		if(names[i]=='name'){
			//var re = /^[A-Za-z0-9А-Яа-яЅ\-_'.\ ]+$/;
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+[  ]+[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.name.value) || onlySymbolsValidator(document.all2.name.value))             {
				alert('Невалидни Име и Фамилия!');
				document.all2.name.focus();
				document.all2.name.select();
				return false;
			}
		}			
		/* 2 */
		if(names[i]=='address'){
			//var re = /^[A-Za-z0-9А-Яа-яЅ\-_'.\ ]+$/;
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.№,\ ]+[  ]+[A-Za-z0-9А-Яа-яЅ\-'.№,\ ]+$/;
			if (!re.test(document.all2.address.value) || onlySymbolsValidator(document.all2.address.value))     {
				alert('Невалиден Адрес!');
				document.all2.address.focus();
				document.all2.address.select();
				return false;
			}
		}		
		/* 3 */
		if(names[i]=='city'){
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.city.value) || onlySymbolsValidator(document.all2.city.value))            {
				alert('Невалиден Град / Село!');
				document.all2.city.focus();
				document.all2.city.select();
				return false;
			}
		}
		/* 4 */
		//if(names[i]=='state'){
		if(eval(document.all2.state).value!=''){	
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.state.value) || onlySymbolsValidator(document.all2.state.value))          {
				alert('Невалидна Област!');
				document.all2.state.focus();
				document.all2.state.select();
				return false;
			}
		}
		/* 5 */
		if(names[i]=='zip'){
			var re = /^[0-9 ]+$/;
			if (!re.test(document.all2.zip.value) || onlySymbolsValidator(document.all2.zip.value)) 
			{
				alert('Невалиден пощенски код!');
				document.all2.zip.focus();
				document.all2.zip.select();
				return false;
			}
		}
		/* 6 */
		if(names[i]=='country'){
			var re = /^[A-Za-z0-9А-Яа-яЅ\-'.\ ]+$/;
			if (!re.test(document.all2.country.value) || onlySymbolsValidator(document.all2.country.value))      {
				alert('Невалидна Държава!');
				document.all2.country.focus();
				document.all2.country.select();
				return false;
			}
		}
		/* 7 */
		if(names[i]=='telefon'){
			var re = /^[\+0-9]+[\+0-9 \\/]+$/;
			if (!re.test(document.all2.telefon.value) || onlySymbolsValidator(document.all2.telefon.value))     {
				alert('Невалиден телефонен номер!');
				document.all2.telefon.focus();
				document.all2.telefon.select();
				return false;
			}
		}
			
	}//for (var i=0;i<=8;i++){		   
		
}

function onlySymbolsValidator(field)
{//k&k 11.05 - 1
 var field2 = trimAll(field);//k&k 17.05 - 1
 var simbols =/[^-0\~\`\!\@\$\%\^\&\*\_\+\=\?\:\;\|\,\.\<\>\"\'\№\§\°\/\\]/;
 if(field2.match(simbols) == null)
 {return true;}
 else return false;  
}
function trim(inputString) {//k&k 12.05 - 1
//Kills double spaces and spaces inside string.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user 	
}

function trimAll(inputString) {//k&k 17.05 - 1
//Kills double spaces and spaces inside string.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf(" ") != -1) { // Note that there are spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user 	
}	
/*Copyright 2008 JavaScript-azplus.eu All rights reserved.*/
// -->