var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
function checkImageSize(pathField, previewName)
{       
    var path = pathField.value;
    alert(path);
    if (path.search(imgRe) != -1)
    {   
        document[previewName].src = 'file://'+path;
		
	     var img = new Image();
	     img.src = 'file://'+path;
	     img.name = 'img_to_load';
		//     alert("img.name: "+ img.name);
	   	
		// BEGIN FROM: http://www.quirksmode.org/js/filesize.html
		var size = (document.fileSize)*1;
		//alert("size: "+ size);
		var y = document.images;
		var imglength = 0;
		for (i=0;i<y.length;i++)
		{
		//alert("y[i].name: "+ y[i].name);
		 	if (y[i].name == 'img_to_load') {
				imglength += (y[i].fileSize)*1;
				//alert("imglength: "+ imglength);
			}
		}
		
		var total = size + imglength;
		if (total > 200000) {
			alert("קובץ התמונה גדול מדי");
			return;
		}
		else
		{
			return ;
		}

	}
       
    else    
    {   
        alert("JPG, PNG, and GIFs only!");
        return ;
    }   
}



function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


function isEmail(str) {
// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
  		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) {supported = 1;}
	}
	if (!supported){ 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


function CheckMyForm(MyForm){

	if (!isEmail(MyForm.userName.value) )
		{
		alert("נא הכנס שם דואר אלקטרוני תקין" )
		MyForm.userName.focus();
		MyForm.userName.select();
		return;
		}

	if (MyForm.firstName.value=='' || MyForm.firstName.value=='שם פרטי' )
		{
		alert("נא למלא שם פרטי " );
		//MyForm.firstName.value = '';
		MyForm.firstName.focus();
		MyForm.firstName.select();
		return;
		}
	
	if (MyForm.lastName.value=='')
		{
			MyForm.lastName.value = 'noLastName';		
		}


	if (MyForm.vcTitle.value=='' || MyForm.vcTitle.value=='כותרת ההזמנה')
		{
		alert("נא הכנס כותרת קריאה " )
		MyForm.vcTitle.focus();
		MyForm.vcTitle.select();
		return;
		}
		
	if (MyForm.vcMessage.value=='' || MyForm.vcMessage.value=='פרוט ההזמנה')
		{
		alert("נא הכנס תוכן קריאה  מפורט ככל האפשר " )
		MyForm.vcMessage.focus();
		MyForm.vcMessage.select();
		return;
		}
		
//	if (MyForm.RegionID.value == -1)
//		{
//		alert("נא בחר איזור מהרשימה " )
//		MyForm.RegionID.focus();
//		return;
//		}
		
	if (MyForm.CityID.value == -1)
		{
		alert("נא בחר עיר מהרשימה " )
		MyForm.CityID.focus();
		return;
		}
		
	if (MyForm.fieldID != null)
	{
		if (MyForm.fieldID.value == -1)
		{
		alert("נא בחר תחום " )
		MyForm.fieldID.focus();
		return;
		}
	}
	
//	if(MyForm.phone.value == '')
//		{
//			alert("נא הכנס מספר לטלפון עדכני " )
//			MyForm.phone.focus();
//			return;
//		}
//		
//	if(MyForm.phone.value != '')
//		{
//		if( MyForm.phone.value.length< 6 || !IsNumeric(MyForm.phone.value))
//			{
//			alert("נא הכנס מספר טלפון עדכני")
//			MyForm.phone.focus();
//			return;
//			}
//		}

	if(MyForm.cellular.value == '')
		{
			alert("נא הכנס מספר סלולארי עדכני " )
			MyForm.cellular.focus();
			MyForm.cellular.select();
			return;
		}
		
	if(MyForm.cellular.value != '')
		{
		if( MyForm.cellular.value.length< 6 || !IsNumeric(MyForm.cellular.value))
			{
			alert("נא הכנס מספר סלולארי עדכני")
			MyForm.cellular.focus();
			MyForm.cellular.select();
			return;
			}
		}
	MyForm.fixedPhone.value = '0' + MyForm.areaCodePhone.value + '-' + MyForm.phone.value;
	MyForm.fixedCellular.value = '0' + MyForm.areaCodeCel.value + '-' + MyForm.cellular.value;
	//alert("כל הנתונים הוכנסו");
	MyForm.submit();
			
			//return;
		
}
