function IR_IsDateMinorOrEqual(IR_cDate, IR_cThresholdDate)
{
	var IR_bResult;
	var IR_nYear;
	var IR_nDay;
	var IR_nMonth;
	var IR_nThresholdYear;
	var IR_nThresholdDay;
	var IR_nThresholdMonth;
	var IR_cThresholdDateAsString;

	IR_bResult = false;

	IR_cThresholdDateAsString = IR_cThresholdDate;
	IR_nYear = IR_cDate.substr(6,4);
	IR_nThresholdYear = IR_cThresholdDateAsString.substr(6,4);

	if(IR_nYear <= IR_nThresholdYear)
	{
		IR_bResult = true;

		if(IR_nYear == IR_nThresholdYear)
		{
			IR_bResult = false;

			IR_nMonth = IR_cDate.substr(3,2);
			IR_nThresholdMonth = IR_cThresholdDateAsString.substr(3,2);

			if(IR_nMonth <= IR_nThresholdMonth)
			{
				IR_bResult = true;

				if(IR_nMonth == IR_nThresholdMonth)
				{
					IR_bResult = false;

					IR_nDay = IR_cDate.substr(0,2);
					IR_nThresholdDay = IR_cThresholdDateAsString.substr(0,2);

					if(IR_nDay <= IR_nThresholdDay)
						IR_bResult = true;
				}
			}
		}
	}

	return IR_bResult;
}



function IR_IsDateMinor(IR_cDate, IR_cThresholdDate)
{
	var IR_bResult;
	var IR_nYear;
	var IR_nDay;
	var IR_nMonth;
	var IR_nThresholdYear;
	var IR_nThresholdDay;
	var IR_nThresholdMonth;
	var IR_cThresholdDateAsString;

	IR_bResult = false;

	IR_cThresholdDateAsString = IR_cThresholdDate;
	IR_nYear = IR_cDate.substr(6,4);
	IR_nThresholdYear = IR_cThresholdDateAsString.substr(6,4);

	if(IR_nYear < IR_nThresholdYear)
		IR_bResult = true;
	else
	{
		if(IR_nYear == IR_nThresholdYear)
		{
			IR_bResult = false;

			IR_nMonth = IR_cDate.substr(3,2);
			IR_nThresholdMonth = IR_cThresholdDateAsString.substr(3,2);

			if(IR_nMonth < IR_nThresholdMonth)
				IR_bResult = true;
			else
			{
				if(IR_nMonth == IR_nThresholdMonth)
				{
					IR_bResult = false;

					IR_nDay = IR_cDate.substr(0,2);
					IR_nThresholdDay = IR_cThresholdDateAsString.substr(0,2);

					if(IR_nDay < IR_nThresholdDay)
						IR_bResult = true;
					else
					{
						if(IR_nDay == IR_nThresholdDay)
							IR_bResult = false;
					}
				}
			}
		}
	}
//alert("ret da minor : " + IR_bResult);
	return IR_bResult;
}



function IR_fcgGetComboBoxSelectedItemValue(IR_oComboBox)
{
	var IR_cValue = '';

	if(IR_oComboBox.selectedIndex != -1)
		IR_cValue = IR_oComboBox.options[IR_oComboBox.selectedIndex].value;
			
	return IR_cValue;
}

function IR_fcgGetRadioButtonSelectedItemValue(IR_oRadioButton)
{
	var IR_x;
	var IR_cValue = '';

	for(IR_x = 0; IR_x < IR_oRadioButton.length; IR_x++)
	{
		if(IR_oRadioButton[IR_x].checked == true)
			IR_cValue = IR_oRadioButton[IR_x].value;
	}

	return IR_cValue;
}

function IR_fcgGetComboBoxSelectedItemText(IR_oComboBox)
{
	var IR_cValue = '';

	if(IR_oComboBox.selectedIndex != -1)
		IR_cValue = IR_oComboBox.options[IR_oComboBox.selectedIndex].text;
		
	return IR_cValue;
}

function IR_LeftTrimExtended(IR_cString, IR_cChar)
{
	var IR_x;
	var IR_nLength;
	var IR_cTrimmed;

	IR_x = 0;
	IR_cTrimmed = '';

	IR_nLength = IR_cString.length;

	while((IR_x < IR_nLength) && (IR_cString.charAt(IR_x) == IR_cChar))
		IR_x++;

	if(IR_x < IR_nLength)
		IR_cTrimmed = IR_cString.substring(IR_x, IR_nLength);

	return IR_cTrimmed;
}

function IR_IsValidString(IR_cString, IR_nFrom, IR_nTo, IR_cMask)
{
	var IR_i;
	var IR_j;
	var IR_ch;
	var IR_bIsValid;
	IR_bIsValid = true;
	for(IR_i = IR_nFrom;  IR_i < IR_nTo;  IR_i++)
	{
		IR_ch = IR_cString.charAt(IR_i);
		for(IR_j = 0;  IR_j < IR_cMask.length;  IR_j++)
		{
			if(IR_ch == IR_cMask.charAt(IR_j))
				break;
		}
		if(IR_j == IR_cMask.length)
		{
			IR_bIsValid = false;
			break;
		}
	}
	return IR_bIsValid;
}

function IR_IsStringOfDigits(IR_cString, IR_nFrom, IR_nTo)
{
	return IR_IsValidString(IR_cString, IR_nFrom, IR_nTo, '1234567890');
}


function IR_IsValidDate(IR_cDate)
{
	var IR_bIsValid;
	var IR_cStr;
	var IR_nDay;
	var IR_nMonth;
	var IR_nYear;
	var IR_nMaximumDays;

	IR_bIsValid = false;
	
	if(IR_cDate.length == 10)
	{
		IR_bIsValid = IR_IsStringOfDigits(IR_cDate, 0, 2);

		if(IR_bIsValid)
			IR_bIsValid = IR_IsValidString(IR_cDate, 2, 3, '/-');

		if(IR_bIsValid)
			IR_bIsValid = IR_IsStringOfDigits(IR_cDate, 3, 5);

		if(IR_bIsValid)
			IR_bIsValid = IR_IsValidString(IR_cDate, 5, 6, '/-');

		if(IR_bIsValid)
			IR_bIsValid = IR_IsStringOfDigits(IR_cDate, 6, 10);

		if(IR_bIsValid)
		{
			IR_bIsValid = false;

			IR_cStr = IR_LeftTrimExtended(IR_cDate.substring(6, 10), '0');
			IR_nYear = parseInt(IR_cStr, 10);

			if(IR_nYear > 1899)
			{
				IR_cStr = IR_LeftTrimExtended(IR_cDate.substring(3, 5), '0');
				IR_nMonth = parseInt(IR_cStr, 10);

				if((IR_nMonth > 0) && (IR_nMonth < 13))
				{
					IR_cStr = IR_LeftTrimExtended(IR_cDate.substring(0, 2), '0');
					IR_nDay = parseInt(IR_cStr, 10);

					if(IR_nDay > 0)
					{
						switch(IR_nMonth)
						{
							case 2:
								if(IR_IsLeapYear(IR_nYear))
									IR_nMaximumDays = 29;
								else
									IR_nMaximumDays = 28;
							break;
							case 4:
							case 6:
							case 9:
							case 11:
								IR_nMaximumDays = 30;
							break;
							default:
								IR_nMaximumDays = 31;
							break;
						}

						if(IR_nDay <= IR_nMaximumDays)
							IR_bIsValid = true;
					}
				}
			}
		}
	}

	return IR_bIsValid;
}

function IR_IsLeapYear(IR_nYear)
{
	var IR_bIsLeapYear;

	IR_bIsLeapYear = false;

  if((IR_nYear % 4) == 0)
  {
    IR_bIsLeapYear = true;

    if((IR_nYear % 100) == 0)
    {
      if(IR_nYear % 400)
      {
        IR_bIsLeapYear = false;
      }
    }
  }

  return IR_bIsLeapYear;
}


function IR_IsNumericString(IR_cString, IR_nFrom, IR_nTo)
{
	return IR_IsValidString(IR_cString, IR_nFrom, IR_nTo, '1234567890');
}


function IR_fngGetRadioButtonSelectedItemIndex(IR_oRadioButton)
{
	var IR_x;
	var IR_nIndex = -1;

	for(IR_x = 0; IR_x < IR_oRadioButton.length; IR_x++)
	{
		if(IR_oRadioButton[IR_x].checked == true)
			IR_nIndex = IR_x;
	}

	return IR_nIndex;
}

function IR_fcgGetRadioButtonSelectedItemValue(IR_oRadioButton)
{
	var IR_x;
	var IR_cValue = '';

	for(IR_x = 0; IR_x < IR_oRadioButton.length; IR_x++)
	{
		if(IR_oRadioButton[IR_x].checked == true)
			IR_cValue = IR_oRadioButton[IR_x].value;
	}

	return IR_cValue;
}

function validate_required(field,alerttxt) {
  with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_check(field,alerttxt) {
  with (field)
  {
  if (checked==false)
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_number(field,alerttxt) {
  with (field)
  {
  if (value=="-1")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_email(field,alerttxt) {
  var strCompare='1234567890abcdefghijklmnopqrstuvwxyz.-_@';
  with (field)
  {
  if (isEmail(value)==false)
    {alert(alerttxt);return false}
  else if (stringOfCharPermitted(value,strCompare)==false)
    {alert(alerttxt);return false}
  else if (value.indexOf("@mybazar.") > 0)
    {alert(alerttxt);return false}
  else {return true}
  }
}

function isEmail(str) {
  var pass = 0;
  if (window.RegExp) {
   var tempStr = "a";
   var tempReg = new RegExp(tempStr);
   if (tempReg.test(tempStr)) pass = 1;
  }
  if (!pass)
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function stringOfCharPermitted(str,strCompare) {
	var i;
	var bIsValid=true;
	str.toLowerCase();
	for(i=0;i<str.length;i++)
	{
		if(strCompare.indexOf(str.charAt(i))==-1)
			//alert(str.charAt(i)+':'+strCompare.indexOf(str.charAt(i)));
			{bIsValid=false;return bIsValid;}
	}
	return bIsValid;
}

function validate_userpass(field,alerttxt) {
  //var strCompare='1234567890abcdefghijklmnopqrstuvwxyz.-_';
  var fieldlength;
  if (field.name=='userID')
  	{fieldlength=5}
  else
  	{fieldlength=6}
  with (field)
  {
  if (value==null||value==""||value.length<fieldlength)
    {alert(alerttxt);return false}
  /*else if (field.name=='userID'&&stringOfCharPermitted(value,strCompare)==false)
    {alert(alerttxt);return false}*/
  else {return true}
  }
}

function isUserAvailable(thisform,alerttxt) {
	with (thisform)
	{
		if(userAvailable.value==0)
			{alert(alerttxt);return false}
		else
			{return true}
	}
}

function validate_descrObj(thisform,alerttxt,txt) {
	with (thisform)
	{
		if (description.value==null||description.value==""||description.value==txt||description.value==('<p>'+txt+'</p>')||description.value.length<20)
			{alert(alerttxt);return false}
		else
			{return true}
	}
}

function validate_date(field,alerttxt) {
	if(IR_IsValidDate(field.value)==false)
		{alert(alerttxt);return false}
	else
		{
			dateCompare=field.value;
			newYear=dateCompare.substr(6,4);
			newYear=Number(newYear)+18;
			dateCompare=dateCompare.substr(0,6)+String(newYear);
			if(IR_IsDateMinorOrEqual(dateCompare, dateNow)==false)
				{alert(alertAge);return false}
			else
				{return true}
		}
}

function validate_form(thisform,alerttxt) {
  with (thisform)
  {
	  if (thisform.name=='frmLogin') {
		  //----------LOGIN---------------------------------
		  if (validate_userpass(userID,alerttxt)==false)
		    {userID.focus();return false}
		  else if (validate_userpass(passID,alerttxt)==false)
		    {passID.focus();return false}
	  }
	  else if (thisform.name=='frmComments') {
		  //----------COMMENTS------------------------------
		  if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
		  else if (validate_required(comments,alerttxt)==false)
		    {comments.focus();return false}
	  }
	  else if (thisform.name=='frmRegister') {
		  //----------REGISTER------------------------------
		  if (validate_required(firstname,alerttxt)==false)
		    {firstname.focus();return false}
		  else if (validate_required(lastname,alerttxt)==false)
		    {lastname.focus();return false}
		  else if (validate_required(address,alerttxt)==false)
		    {address.focus();return false}
		  else if (validate_required(city,alerttxt)==false)
		    {city.focus();return false}
		  else if (validate_required(zip,alerttxt)==false)
		    {zip.focus();return false}
		  else if (validate_required(province,alerttxt)==false)
		    {province.focus();return false}
		  else if (validate_number(country,alerttxt)==false)
		    {country.focus();return false}
		  else if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
		  else if (validate_date(birthdate,alerttxt)==false)
		    {yyyy_birthdate.focus();return false}
		  else if (validate_check(chk_declare,alerttxt)==false)
		    {chk_declare.focus();return false}
		  else if (validate_check(chk_regulation,alerttxt)==false)
		    {chk_regulation.focus();return false}
		  else if (validate_check(chk_privacy,alerttxt)==false)
		    {chk_privacy.focus();return false}
	  }
	  else if (thisform.name=='frmRegister2') {
		  //----------REGISTER2-----------------------------
		  if (validate_userpass(userID,alerttxt)==false)
		    {userID.focus();return false}
		  else if (validate_userpass(passID,alerttxt)==false)
		    {passID.focus();return false}
		  else if (validate_userpass(passConfirm,alerttxt)==false)
		    {passConfirm.focus();return false}
		  else if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
	  }
	  else if (thisform.name=='frmActivateUser') {
		  //----------ACTIVATE USER-------------------------
		  if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
		  else if (validate_required(guid,alerttxt)==false)
		    {guid.focus();return false}
	  }
	  else if (thisform.name=='frmForgotten') {
	  	  //----------FORGOTTEN LOGIN-----------------------
		  if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
	  }
	  else if (thisform.name=='frmChangePsw') {
	  	  //----------CHANGE PASSWORD-----------------------
	  	  if (validate_userpass(passOLD,alerttxt)==false)
		    {passOLD.focus();return false}
		  else if (validate_userpass(passID,alerttxt)==false)
		    {passID.focus();return false}
		  else if (validate_userpass(passConfirm,alerttxt)==false)
		    {passConfirm.focus();return false}
	  }
	  else if (thisform.name=='frmPersonalID') {
		  //----------PERSONAL ID---------------------------
		  if (validate_required(firstname,alerttxt)==false)
		    {firstname.focus();return false}
		  else if (validate_required(lastname,alerttxt)==false)
		    {lastname.focus();return false}
		  else if (validate_required(address,alerttxt)==false)
		    {address.focus();return false}
		  else if (validate_required(city,alerttxt)==false)
		    {city.focus();return false}
		  else if (validate_required(zip,alerttxt)==false)
		    {zip.focus();return false}
		  else if (validate_required(province,alerttxt)==false)
		    {province.focus();return false}
		  else if (validate_email(email,alerttxt)==false)
		    {email.focus();return false}
	  }
	  else if (thisform.name=='frmObject') {
		  //----------OBJECT MANAGEMENT---------------------
		  if (validate_required(categoryObj,alerttxt)==false)
		    {category.focus();return false}
		  else if (validate_required(title,alerttxt)==false)
		    {title.focus();return false}
		  //else if (validate_descrObj(description,alerttxt)==false)
		  //  {setFocus();return false}
	  }
	  else if (thisform.name=='frmMessage') {
		  //----------MAIL BAZAR----------------------------
		  if (validate_required(objectM,alerttxt)==false)
		    {objectM.focus();return false}
		  else if (validate_required(textM,alerttxt)==false)
		    {textM.focus();return false}
	  }
	  else if (thisform.name=='frmSubmitToFriend') {
		  //----------SUBMIT PAGE TO A FRIEND---------------
		  if (validate_required(sName,alerttxt)==false)
		    {sName.focus();return false}
		  else if (validate_email(sEmail,alerttxt)==false)
		    {sEmail.focus();return false}
		  else if (validate_required(sFriendName,alerttxt)==false)
		    {sFriendName.focus();return false}
		  else if (validate_email(sFriendEmail,alerttxt)==false)
		    {sFriendEmail.focus();return false}
	  }
  }
}

function validate_all(thisform,alerttxt1,alerttxt2) {
	if(validate_form(thisform, alerttxt1)==false)
		{return false}
	else
		{
			if(isUserAvailable(thisform, alerttxt2)==false)
				{return false}
			else
				{return true}
		}
}

function CheckAvailability(thisform,alerttxt) {
	with (thisform)
	{
		if (validate_userpass(userID,alerttxt)==false)
			{userID.focus()}
		else
			{userAvailable.value=0;submit()}
	}
}

function validate_formObj(thisform,alerttxt,txt) {
	if(validate_form(thisform, alerttxt)==false)
		{return false}
	else
		{
			if(validate_descrObj(thisform, alerttxt, txt)==false)
				{setFocus();return false}
			else
				{return true}
		}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function startPreload() {
	MM_preloadImages('/images/mybazar-Africa.gif','/images/mybazaar-Africa.gif','/images/mybazar-Americas.gif','/images/mybazaar-Americas.gif','/images/mybazar-Asia.gif','/images/mybazaar-Asia.gif','/images/mybazar-Europe.gif','/images/mybazaar-Europe.gif','/images/mybazar-Oceania.gif','/images/mybazaar-Oceania.gif');
}

function show(x) {
	hideAll();
	document.getElementById(x).style.display='inline';
}
                
function hideAll() {
	document.getElementById('mybazar_menu').style.display='none';
	document.getElementById('favourite_menu').style.display='none';
	document.getElementById('account_menu').style.display='none';
}

function createBirthDate() {
	document.frmRegister.birthdate.value=document.frmRegister.dd_birthdate.value+"/"+document.frmRegister.mm_birthdate.value+"/"+document.frmRegister.yyyy_birthdate.value;
}

function DisplayMail(Server, Login, Display){
	if ((Display.length == 0) || (Display.indexOf('@')+1)) {
		document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>"); }
	else {
		document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>"); }
}

function bookmarkpage(){
	if (document.all)
		window.external.AddFavorite(vUrl, vTitle);
	else if (window.sidebar)
		window.sidebar.addPanel(vTitle, vUrl, "");
}

function goSelectedCountry(thisform,IR_oComboBox) {
	var URLredirect=IR_fcgGetComboBoxSelectedItemValue(IR_oComboBox);
	if(URLredirect!="-1")
		{thisform.action=URLredirect;thisform.submit();}
}

function goRefresh(thisform) {
	eval(thisform).submit();
}

function photoPopup(photoURL) {
	if(typeof(photoURL)!="object"){
		window.golarge = window.open("","","top=100,left=100,scrollbars=auto,resizable=yes");
		window.golarge.document.open();
		window.golarge.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.mybazar.com/xhtml1/DTD/xhtml1-transitional.dtd">\n');
		window.golarge.document.write('<html xmlns="http://www.w3.org/1999/xhtml">\n');
		window.golarge.document.write('<head>\n');
		window.golarge.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n');
		window.golarge.document.write('<link href="/common/css/main.css" rel="stylesheet" type="text/css" />\n');
		window.golarge.document.write('<title>Zoom</title>\n');
		window.golarge.document.write('</head>\n');
		window.golarge.document.write('<body style="background: #ffffff;">\n');
		window.golarge.document.write('<img src="'+photoURL+'" onLoad="opener.photoPopup(this);" style="border: 1px solid #666666;" />\n');
		window.golarge.document.write('</body>\n');
		window.golarge.document.write('</html>\n');
		window.golarge.document.close();
	}
	else{
		if(document.all)
			window.golarge.resizeTo(photoURL.width+14,photoURL.height+33);
		else
			window.golarge.resizeTo(photoURL.width+10,photoURL.height+52);
	}
}

function showPreview(URLLocation) {
	window.open('myb_ShowPreview.asp'+URLLocation,'ShowPreview','toolbar=no,status=no,menubar=no,scrollbars=no,width=580,height=320,left=100,top=100');
}
