$(document).ready(function(){
	objFrom = document.getElementById("fromOrders");
	objTo = document.getElementById("toOrders");
	if(objTo && objFrom) {
		objTo.innerHTML = objFrom.innerHTML;
		objTo.style.display = "block";
		objFrom.innerHTML = '';
		objFrom.style.display = "none";
	}
});


	$(function(){
		$("body").append($("#out_body").html());
		$("#out_body").empty();
	})
	function show_big_pic(curr_url_big_img, curr_title_big_img){ 
		if(curr_url_big_img == '')  return false;
		//--------------------------------------------------
		$("#rep").center().show(); 
		$("#fancy_overlay").css({'width': $(window).width(), 'height': $(document).height(), 'opacity': 0.3}).show();

		//--------------------------------------------------
		var image = document.createElement("img"); 
		image.onload= function () {
			$("#name_img").html(curr_title_big_img);
			$("#rep").hide();
			$('#img_pic').html(image).show();
			$('#show_big_pic').center().fadeIn();
		}
		//--------------------------------------------------
		image.src = curr_url_big_img;
	}
	function close_pic(){
		$("#rep").hide(); 
		$('#show_big_pic').hide();
		$("#fancy_overlay").hide();
	}	


////////////////////////////////////////////////////////////////////////////////////
     function getClientWidth()  {  
          return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;  
     }  
   
     function getClientHeight(){  
          return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;  
     }  
               
      jQuery.fn.center = function()   {           
          var w = $(window);  
          this.css("position","absolute");  
          this.css("top",(getClientHeight()-this.height())/2 + getBodyScrollTop() + "px");  
          this.css("left",(getClientWidth()-this.width())/2 + getBodyScrollLeft() + "px");  
          return this;  
     }
    function getBodyScrollTop() {
        return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
    }

    function getBodyScrollLeft() {
        return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
    }
////////////////////////////////////////////////////////////////////////////////////



function pop(obj, name, width, height) {
    if (!name) {
        name = 'pop';
    }
    if (!width) {
        width = 400;
    }
    if (!height) {
        height = 600;
    }
    popupWin = window.open(obj.href, name, 'width='+width+',height='+height);
    popupWin.focus();
}

function goto_country(){
	box = document.destinations.country;
	destination = box.options[box.selectedIndex].value;
	if (destination>'') {
		window.location.href=destination;
	}
}

function preview_image(img_src) {
    pic = new Image();
    pic.src = img_src;
    setTimeout('view_image(pic.src, pic.width, pic.height);', 500);
}

function view_image(img_src, img_width, img_height){
    if (img_width>screen.availWidth-150 || img_width==0) {
        win_width = screen.availWidth-150;
    } else {
        win_width = img_width+20;
    }
    if (img_height>screen.availHeight-150 || img_height==0) {
        win_height = screen.availHeight-150;
    } else {
        win_height = img_height+20;
    }
    win_top  = Math.abs((screen.availHeight - win_height)/3);
    win_left = Math.abs((screen.availWidth -win_width)/3);
    photoWindow = window.open('', '', "resizable=yes,top=" + win_top + ',left=' + win_left + ",width="+win_width+',height='+win_height+",status=0,menubar=0,toolbar=0,scrollbars=yes");
    photoWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>');
    photoWindow.document.write('<head><title>'+img_src+'</title><style type="text/css"><!-- body {margin:0;padding:0} --></style>');
    photoWindow.document.write('<scr'+'ipt type=text/javascript>');
    photoWindow.document.write('document.onkeypress = function CloseOnEsc(key) { if(document.all) { var keyCode = window.event.keyCode; } else { if (key.which == 0) {window.close();return;}   }  if (keyCode == 27) {window.close();return;} }');
    photoWindow.document.write('</scr'+'ipt>');
    photoWindow.document.write('</head><body><img src="'+img_src+'" ');
    if ( (img_width>1) && (img_height>1) ) {
        photoWindow.document.write('width="'+img_width+'" height="'+img_height+'"');
    }
    photoWindow.document.write(' border=0 onclick="javascript:window.close();">');
    photoWindow.document.write('</body></html>');
    photoWindow.document.bgColor="#f0f0f0";
    photoWindow.document.close()
}

function igallery_image(img_src, img_width, img_height, img_title){
    if (img_width>screen.availWidth-150 || img_width==0) {
        win_width = screen.availWidth-150;
    } else {
        win_width = img_width+20;
    }
    if (img_height>screen.availHeight-150 || img_height==0) {
        win_height = screen.availHeight-150;
    } else {
        win_height = img_height+20;
    }
    win_top  = Math.abs((screen.availHeight - win_height)/3);
    win_left = Math.abs((screen.availWidth -win_width)/3);
    photoWindow = window.open('', '', "resizable=yes,top=" + win_top + ',left=' + win_left + ",width="+win_width+',height='+win_height+",status=0,menubar=0,toolbar=0,scrollbars=yes");
    photoWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>');
    photoWindow.document.write('<head><title>'+img_title+'</title><style type="text/css"><!-- body {margin:0;padding:0} --></style>');
    photoWindow.document.write('<scr'+'ipt type=text/javascript>');
    photoWindow.document.write('document.onkeypress = function CloseOnEsc(key) { if(document.all) { var keyCode = window.event.keyCode; } else { if (key.which == 0) {window.close();return;}   }  if (keyCode == 27) {window.close();return;} }');
    photoWindow.document.write('</scr'+'ipt>');
    photoWindow.document.write('</head><body><img src="'+img_src+'" ');
    if ( (img_width>1) && (img_height>1) ) {
        photoWindow.document.write('width="'+img_width+'" height="'+img_height+'"');
    }
    photoWindow.document.write(' border=0 onclick="javascript:window.close();">');
    photoWindow.document.write('</body></html>');
    photoWindow.document.bgColor="#f0f0f0";
    photoWindow.document.close()
}

function show_obj(obj_id){
obj=document.getElementById(obj_id);
remove_class(obj, 'hide');
add_class(obj, 'show');
}

function hide_obj(obj_id){
obj=document.getElementById(obj_id);
remove_class(obj, 'show');
add_class(obj, 'hide');
}

function add_class(e,c) {
  e.className=e.className+" "+c;
}

function remove_class(e,c) {
  cn=e.className;
  p=cn.indexOf(c);
  if (p>-1){e.className=cn.substr(0,p)+cn.substr(p+c.length);  }
}

function SetCookie(cookieName, cookieValue, nHours) {
 var today = new Date();
 var expire = new Date();
 if (nHours==null || nHours==0) nHours=1;
 expire.setTime(today.getTime() + 3600000*nHours);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function GetCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else  {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)  {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function DeleteCookie(name, path, domain) {
    if (getCookie(name))  {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


var fields = new Array();
fields.push('surname');
fields.push('name');
fields.push('company');
fields.push('city');
fields.push('phone');
fields.push('email');
fields.push('duration');
fields.push('period_from');
fields.push('period_to');
var fields2 = new Array();
fields2.push('advertisingType');
fields2.push('advertisingCity');
fields2.push('advertisingItems');
function checkOrderForm(sbmt) {
	var countError = 0;
	for(var i=0; i<fields.length; i++) {
//		alert($("#f_"+fields[i]).value());
		var obj = document.getElementById("f_"+fields[i]);
		if(obj) {
//			if(fields[i] == "surname") {
//				alert(obj.value);
//			}
			if(obj.value=='' || obj.value==' ') {
				obj.className = "text errText";
				countError++;
			}
			else {
				if(fields[i] == "email") {
					if(ismail(obj.value)) {
						obj.className = "text";
					}
					else {
						obj.className = "text errText";
						countError++;
					}
				}
				else {
					if(fields[i] == "period_from") {
						if(isdate(obj.value)) {
							obj.className = "text";
						}
						else {
							obj.className = "text errText";
							countError++;
						}
					}
					else {
						if(fields[i] == "period_to") {
							if(isdate(obj.value)) {
								obj.className = "text";
							}
							else {
								obj.className = "text errText";
								countError++;
							}
						}
						else {
							obj.className = "text";
						}
					}
				}
			}
		}
		else {
			countError++;
		}
	}
	for(var i=0; i<fields2.length; i++) {
//		alert($("#f_"+fields[i]).value());
		var obj = document.getElementById(fields2[i]);
		if(obj) {
			if(obj.value=='' || obj.value==' ' || obj.value==0) {
				obj.className = "errText";
				countError++;
			}
			else {
				obj.className = "";
			}
		}
		else {
			countError++;
		}
	}
	if(countError>0) {
		return false;
	}
	else {
		if(sbmt===true) {
			document.add.submit();
		}
		else {
			return true;
		}
	}
}
function ismail(val) {
//   var emailTest = "/^[_\.0-9a-z-]+[@]{1}([0-9a-z_-]+\.)+[a-z.]{2,5}[a-z]*$/i"; 
//   var emailTest = "/[0-9a-z_\.]+@[0-9a-z_^.]+.[a-z]{2,3}/i"; 
	var emailTest = "^[0-9a-z]+[-\._0-9a-z]*@[0-9a-z]+[-\._^0-9a-z]*[0-9a-z]+[\.]{1}[a-z]{2,6}$";
   var regex = new RegExp(emailTest); 
//   alert(val+' '+regex.test(val));
   if (regex.test(val)) {
	   return true;
      //разблокировать кнопку
   } else {
	   return false;
      //заблокировать
   }
}
function isdate(val) {
	var emailTest = "/[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/"; 
//	var emailTest = "\d\d\.\d\d\.\d\d\d\d"; 
//	var emailTest = "(([0-2]{1}[1-9]{1})|([3]{1}[01]{1}))(\.)([0]{1}[1-9]{1}|([1]{1}[12]{1}))(\.)(20(\d{2}))"; 
	var emailTest = "[0-3]{1}[0-9]{1}\.[0-3]{1}[0-9]{1}\.[0-9]{4}"; 
	var regex = new RegExp(emailTest); 
//	alert(val+' '+regex.test(val));
	if (regex.test(val)) {
		return true;
//		разблокировать кнопку
	}
	else {
		return false;
//		заблокировать
	}
}