function getBrowserType()
{
	if (document.all)
		var version=/MSIE \d+.\d+/

	if (!document.all){
		return "ff";
	}
	else
	{
		return 'ie';
	}
}

function OpenWin(Num)
{
  var div_obj = document.getElementById(Num)
  if (div_obj.style.display=='') 
  {
   div_obj.style.display='none'; 
  }
  else
  {
   div_obj.style.display=''; 
  }  
}

function DoUrl(GetUrl)
{
	window.location = GetUrl;
}

function DoUrlAlert(GetUrl,GetMessage)
{
	var statusmessage;
		statusmessage = confirm(GetMessage);
		if(statusmessage){
			window.location = GetUrl;
		}
}

function DoAlert(GetMessage)
{
	alert(GetMessage);
}


function if_equal(GetObj1,GetObj2,message){
	if(GetObj1.value != GetObj2.value){
		GetObj2.focus();
		GetObj2.select();
		DoAlert(message);
		return false;
	}
	return true;
}


function if_lenght(GetObj,GetNum,message){
	var InnerValue = GetObj.value;
	if(InnerValue.length < GetNum){
		GetObj.focus();
		GetObj.select();
		DoAlert(message);
		return false;
	}
	return true;
}


function if_empty_text(GetObj,message){
	if(GetObj.value == ""){
		GetObj.focus();
		GetObj.select();
		DoAlert(message);
		return false;
	}
	return true;
}


function if_checked(GetObj,message){
	if(!GetObj.checked){
		DoAlert(message);
		return false;
	}
	return true;
}

function if_empty_select(GetObj,message){
	if(GetObj.value == ""){
		GetObj.focus();
		DoAlert(message);
		return false;
	}
	return true;
}


function if_email(GetObj,message){
	var reEmail = /^[-\w\d\.]+@[-\w\d\.]+\.[-\w\d\.]+$/;
	if(!(reEmail.test(GetObj.value))){
		GetObj.focus();
		GetObj.select();
		DoAlert(message);
		return false;
	}
	
	for( var i=0; i < GetObj.length; i++ ) {
		if(!(GetObj.charAt(i)>='a' && GetObj.charAt(i)<='z' || 
		GetObj.charAt(i)>='A' && GetObj.charAt(i)<='Z' || 
		GetObj.charAt(i)>='0' && GetObj.charAt(i)<='9' ||
		GetObj.charAt(i) == '.' || GetObj.charAt(i) == '@') ||
		s.charAt(i) == ' ') {
			
		GetObj.focus();
		GetObj.select();
		DoAlert(message);
		return false;
		}

	}
	
	return true;
}

function if_url(GetObj,message){
		/*
	var reUrl = /^[-\w\d\.]+@[-\w\d\.]+\.[-\w\d\.]+$/;
	var ObVal = GetObj.value;
	if(!(reUrl.test(ObVal)) && ObVal.length>=5){
		GetObj.focus();
		GetObj.select();
		DoAlert(message);
		return false;
	}
	*/
	return true;
}

function PreAddTag(GetFrmName)
{
	var GetObject = document.getElementById(GetFrmName);
		
		if(check_tag_exist_on_db_by_ajax("wtag")) {
			alert("התגית כבר תפוסה על-ידי בעל אתר אחר, נסו לבדוק תגית אחרת ");
			GetObject.wtag.focus();
			return false;
		}
		
		GetObject.submit();
}


function checkUrl(s) {
    
    if ( ( (s.charAt(0) == "h") || (s.charAt(0) == "H") ) &&
		 ( (s.charAt(1) == "t") || (s.charAt(1) == "T") ) &&
		 ( (s.charAt(2) == "t") || (s.charAt(2) == "T") ) &&
		 ( (s.charAt(3) == "p") || (s.charAt(3) == "P") ) &&
		 (s.charAt(4) == ":") &&
		 (s.charAt(5) == "/") &&
		 (s.charAt(6) == "/") )
		  return false;

	return true;
}

function checkUrl1(s) {
    
	for( var i=0; i < s.length; i++ ) {
		if(!(s.charAt(i)>='a' && s.charAt(i)<='z' || 
		s.charAt(i)>='A' && s.charAt(i)<='Z' || 
		s.charAt(i)>='0' && s.charAt(i)<='9' ||
		s.charAt(i) == '.' ||
		s.charAt(i) == '-' ||
		s.charAt(i) == '_') ||
		s.charAt(i) == ' ') {
		return false;
		}

	}
	var pos = s.indexOf('.');
	if(pos != -1)
		return true;
	else
		return false;
}

function check_tag_exist_on_db_by_ajax(tag)
{
	var GetObj = document.getElementById(tag);

		var SentToPage="free_tags.php";
		var browsertype = getBrowserType();
			//xmlStr="?tagname="+encodeURIComponent(GetObj.value);
			xmlStr="?tagname="+GetObj.value;
			SentToPageInner = SentToPage+xmlStr;
			if(browsertype=='ff'){
				xmlObj = new XMLHttpRequest();
			} else {
				xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
				
			}
	
			xmlObj.open ("POST", SentToPageInner ,false);
			xmlObj.send(null);	
			
			var responseText = xmlObj.responseText;
			xmlObj.Close;
			xmlObj = null;
			switch(responseText)
			{
				case "exist":
					return true;
					break;
				case "free":
					return false;
					break;
			}
}
	
function AddTag(GetFrmName)
{
	var GetObject = document.getElementById(GetFrmName);
		if(!if_empty_text(GetObject.global___wantedlink,"מלאו כתובת האתר שלכם")){ return false; }
//		if(!if_url(GetObject.global___wantedlink,"כתובת האתר אינה תקינה")){ return false; }
		if(!checkUrl(GetObject.global___wantedlink.value)) {
		alert("(www.tagiyot.co.il) נא לכתוב כתובת ראשית בלבד ");
		GetObject.global___wantedlink.focus();
		return false;
		}
		
		/*if(!checkUrl1(GetObject.global___wantedlink.value)) {
		alert("כתובת האתר אינה תקינה");
		GetObject.global___wantedlink.focus();
		return false;
		}*/
	
		if(!if_empty_text(GetObject.global___wantedtag,"מלאו תגית רצוייה")){ return false; }
		
		if(check_tag_exist_on_db_by_ajax("global___wantedtag")) {
			alert("התגית כבר תפוסה על-ידי בעל אתר אחר, נסו לבדוק תגית אחרת ");
			GetObject.global___wantedtag.focus();
			return false;
		}
		
		if(!if_empty_select(GetObject.global___id_category,"נא לבחור קטגוריה רצויה")){ return false; }
		if(!if_url(GetObject.global___wantedbacklink,"כתובת הקישורים אינה תקינה")){ return false; }
		
		if(!if_empty_text(GetObject.global___name,"מלאו שם פרטי")){ return false; }
		if(!if_empty_text(GetObject.global___email,"מלאו דואר אלקטרוני")){ return false; }
		if(!if_email(GetObject.global___email,"דואר אלקטרוני לא תקין, נסו שנית")){ return false; }
		if(!if_checked(GetObject.iftrue,"נא לאשר תנאי שימוש")){ return false; }		
		GetObject.submit();
}

function ContactUs(GetFrmName)
{
	var GetObject = document.getElementById(GetFrmName);
		if(!if_empty_text(GetObject.contact_name,"נא לרשום שם איש קשר / בעל האתר")){ return false; }	
		//if(!if_empty_text(GetObject.contact_site,"נא לרשום כתובת האתר")){ return false; }	
		//if(!if_empty_text(GetObject.contact_phone,"נא לרשום טלפון להתקשרות")){ return false; }	
		if(!if_empty_text(GetObject.contact_email,"נא לרשום דואר אלקטרוני")){ return false; }
		if(!if_email(GetObject.contact_email,"דואר אלקטרוני לא תקין, נסו שנית")){ return false; }
		if(!if_empty_text(GetObject.contact_body,"נא לרשום תוכן פנייה")){ return false; }	
		GetObject.submit();
}



function Advertising(GetFrmName)
{
	var GetObject = document.getElementById(GetFrmName);
		if(!if_empty_text(GetObject.contact_name,"נא לרשום שם איש קשר / בעל האתר")){ return false; }	
		//if(!if_empty_text(GetObject.contact_site,"נא לרשום כתובת האתר")){ return false; }	
		if(!if_empty_text(GetObject.contact_phone,"נא לרשום טלפון להתקשרות")){ return false; }	
		if(!if_empty_text(GetObject.contact_email,"נא לרשום דואר אלקטרוני")){ return false; }
		if(!if_email(GetObject.contact_email,"דואר אלקטרוני לא תקין, נסו שנית")){ return false; }
		if(!if_empty_text(GetObject.contact_tag,"נא לרשום תגית אשר אתם מעוניינים לפרסם")){ return false; }
		if(!if_empty_text(GetObject.contact_body,"נא לרשום תוכן פנייה")){ return false; }	
		GetObject.submit();
}


function if_tag_exist_on_db_by_ajax()
{
	var GetObj = document.getElementById("if_free_tagname");
	if(GetObj.value!="")
	{
		var SentToPage="free_tags.php";
		var browsertype = getBrowserType();
			//xmlStr="?tagname="+encodeURIComponent(GetObj.value);
			xmlStr="?tagname="+GetObj.value;
			SentToPageInner = SentToPage+xmlStr;
			if(browsertype=='ff'){
				xmlObj = new XMLHttpRequest();
			} else {
				xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
				
			}
	
			xmlObj.open ("POST", SentToPageInner ,false);
			xmlObj.send(null);	
			
			var responseText = xmlObj.responseText;
			xmlObj.Close;
			xmlObj = null;
			switch(responseText)
			{
				case "exist":
					GetObj.focus();
					GetObj.select();
					DoAlert("התגית כבר תפוסה על-ידי בעל אתר אחר, נסו לבדוק תגית אחרת");
					GetObj.value = '';
					return false;
					break;
				case "free":
					GetObj.focus();
					GetObj.select();
					DoUrlAlert("add_tag.php?wtag="+GetObj.value,"תג שחיפשתם פנוי, האם אתם מעוניינים להוסיף אותו ?");
					return false;
					break;
			}
		return true;
	} else {
		DoAlert("נא לרשום תג לחיפוש");
		return false;
	}
} // End :: Function
