//**********************************************************************//
//Java Script Code for SBIIA 2.9

//Dynamic Menu popi Error fix
function popmenu(smenu){
try
{
	popi('show-menu='+smenu,'menu1',1);
 }
 catch(e){}
}

//Open a pop up
function OpenWindow(sURL) {
	var sFeatures;
	sFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=616,height=600, top=" + ( screen.width / 2 - 370 ) + ",left=" + ( screen.height / 2 - 100 ) ;
	if (!window.popWindow) {
		popWindow = window.open(sURL,"generic",sFeatures);
	}
	else {
		if (!popWindow.closed) {
			popWindow.focus();
			popWindow.location = sURL
		}
		else {
			popWindow = window.open(sURL,"generic",sFeatures);
		}
	}
}


/* Opens a new window where to show the image.
 * sName		- Image title.
 * sCode		- Product or category code.
 * sImage		- Image name.
 * sImageType	- Image type.
 */
function showLargerPhoto(sName, sCode, sImage, sImageType, sAltImageText) {
var w, h;

	if (showLargerPhoto.arguments.length == 6) {
			w = parseInt(showLargerPhoto.arguments[4]) + 60;
			h = parseInt(showLargerPhoto.arguments[5]) + 90;
		} else {
			w = 550;
			h = 550;
		}

		sImagePath = ((sImageType=="p") ? "prodimages/" : "catimages/") + sImage;
		open(
			"picviewer.asp?name=" + escape(sName) + "&code=" + escape(sCode) + "&Image=" + escape(sImagePath) + "&AltText=" + escape(sAltImageText),
			"picviewer",
			"directories=no,location=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes,width=" + w + ",height=" + h,
			true);
}

//Validate Email
function isFieldEmailAddress(psCaption, poField) {
		re = /.+@.+\..+/ ;

		if (!re.test(poField.value)) {
			alert(psCaption);
			poField.focus();
			return false;
		} else
			return true;
	}

//Validate Empty Field
function isFieldEmpty(psCaption, pField) {
		if (pField.value=="") {
			alert(psCaption);
			pField.focus();
			return false;
		} else
			return true;
	}

//Intranet Upload File
function UploadFile( psField, psPath ) {
		var sFeatures;
		sFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=no,resizeable=no,width=450,height=200,top=" + ( screen.width / 2 - 215 ) + ",left=" + ( screen.height / 2 - 85 ) ;
		open("intranetuploadformI.asp?Field=" + psField + "&Path=" + escape( psPath ) , "Upload", sFeatures );
	}

/* getFileType
 *	Extracts file type (extension) of a filename.
 *
 *	@param	psFile	Filename.
 *	@return	Filename extension.
 */
function getFileType( psFile ) {
	index = psFile.lastIndexOf( "." ) ;
	if ( index >= 0 ) {
		return psFile.substr( index+1 ) ;
	} else {
			return "" ;
		}
}
//Gallery
function showImage( sFileName ) {
	var sFeatures;
	sFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=yes,width=616,height=600, top=" + ( screen.width / 2 - 370 ) + ",left=" + ( screen.height / 2 - 100 ) ;
	window.open( "showImage.asp?image=" + sFileName , "Image", sFeatures );
}

/*
Used for: Dynamic Menu.
Usage: To retrieve the position of a given element,
compatible with browsers that support W3C DOM element-referencing syntax.
*/
function getElementPosition(elemID) {
	  var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}


			function isFieldNumber(psCaption, poField) {
				if (isNaN(poField.value)) {
					alert(psCaption);
					poField.focus();
					return false;
				} else
					return true;
			}
			function isFieldInteger(psCaption, poField) {
				if (!isNaN(poField.value)) {
					if(!poField.value.indexOf(".")<0) {
						alert(psCaption);
						poField.focus();
						return false ;
					} else
						return true ;
				} else {
					alert(psCaption);
					poField.focus();
					return false;
				}
			}


			function isDate(psMessage, poDate) {
				var arrayOfStrings, sDelimiter,  bReturn;
				var iYear, iMonth, iDay;

				if ( poDate.value.indexOf( "/" ) != "-1" )
					sDelimiter = "/";
				else
					sDelimiter = "-";

				if (poDate.value.length == 0) return true;
				bReturn = true;
				// Parse yyyy, mm, dd from string
				arrayOfStrings = poDate.value.split( sDelimiter )
				iMonth = parseInt(arrayOfStrings[0], 10);
				iDay   = parseInt(arrayOfStrings[1], 10);
				iYear  = parseInt(arrayOfStrings[2], 10);

				if (iYear == 0){
				  iYear =2000
				}

				if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay)) {
					bReturn = false;
				}
				if (iDay > 31 || iDay < 1 || iMonth < 1 || iMonth > 12 || iYear < 1) {
					bReturn = false;
				}
				if (iDay == 31 && "_1_3_5_7_8_10_12_".indexOf("_"+iMonth+"_") == -1 ) {
					bReturn = false;
				}
				if (iDay == 30 && iMonth == 2) {
					bReturn = false;
				}
				if (iDay == 29 && iMonth == 2 && !isLeapYear(iYear)) {
					bReturn = false;
				}
				if (!bReturn && trim(psMessage).length > 0){
					alert(psMessage);
					poDate.focus();
					poDate.select();
				}
				return bReturn;
			}

			function isTime(psCaption, poField) {
				var sTimeValue, iHour, iMinute;
				sTimeValue = poField.value;

				switch( sTimeValue.length ) {
					// Create a valid Regular Expression and get hour and minute data
					case 8:
						re = /((\d\d:\d\d)\b am|pm)/i ;
						iHour	= sTimeValue.charAt(0) + sTimeValue.charAt(1);
						iMinute = sTimeValue.charAt(3) + sTimeValue.charAt(4);
						break;
					case 7:
						re = /((\d:\d\d)\b am|pm)/i ;
						iHour	= sTimeValue.charAt(0)
						iMinute = sTimeValue.charAt(2) + sTimeValue.charAt(3);
						break;
					default:
						alert(psCaption);
						poField.focus();
						return false;
				}

				if (!re.test(poField.value)) {
					alert(psCaption);
					poField.focus();
					return false;
				} else {
					if(iHour>23 || iMinute>59 )
					{
						alert(psCaption);
						poField.focus();
						return false;
					}
					else
						return true;
				}
			}


			function isLeapYear(piYear) {
				if (((piYear % 4 == 0) && piYear % 100 != 0) || piYear % 400 == 0)
					return true;
				else
					return false;
			}
			function trim(pString){
			  var iStart, iEnd;
			  var sTrimmed = "";
			  var cChar;

			  // Return empty sting if parameter is undefined
			  if (pString==null)
				return sTrimmed;

			  iEnd = pString.length - 1;
			  iStart = 0;
			  bLoop = true;
			  cChar = pString.charAt(iStart);
			  while ((iStart < iEnd) && ((cChar == "\n") || (cChar == "\r") ||
			                            (cChar == "\t") || (cChar == " ") || (cChar == "'")  )){
			     iStart ++;
			     cChar = pString.charAt(iStart);
			  }
			  cChar = pString.charAt(iEnd);
			  while ((iEnd >= 0) && ((cChar == "\n") || (cChar == "\r") ||
			                        (cChar == "\t") || (cChar == " ") || (cChar == "'")  )){
			     iEnd-=1;
			     cChar = pString.charAt(iEnd);
			  }
			  if (iStart <= iEnd){
			     sTrimmed = pString.substring(iStart, iEnd + 1);
			  } else {
			     sTrimmed = "";
			  }
				return sTrimmed;
			}
			function isUSPhone(psCaption, poField) {
				re = /\(?\d{3}\)?([-\/\. ])\d{3}\1|[-\/\. ]\d{4}/ ;
				if (!re.test(poField.value)) {
					alert(psCaption);
					poField.focus();
					return false;
				} else
					return true;
			}
			

	//-----------------------------------------------------------
	// Validation for Checkout4.asp
	//-----------------------------------------------------------
	function funValidarCC()
	{
		if (document.getElementById('methodCC').checked == true)
		{
			document.getElementById('cctype').className = 'inputcolor1';
			document.getElementById('ccardno').className = 'inputcolor1';
			document.getElementById('cccode').className = 'inputcolor1';
			document.getElementById('expmonth').className = 'inputcolor1';
			document.getElementById('expyear').className = 'inputcolor1';
			document.getElementById('ccnoc').className = 'inputcolor1';
			
			document.getElementById('cctype').disabled = false;
			document.getElementById('ccardno').disabled = false;
			document.getElementById('cccode').disabled = false;
			document.getElementById('expmonth').disabled = false;
			document.getElementById('expyear').disabled = false;
			document.getElementById('ccnoc').disabled = false;
			
			document.getElementById('cctype').focus();
		}
		else
		{
			document.getElementById('cctype').className = 'inputcolor2';
			document.getElementById('ccardno').className = 'inputcolor2';
			document.getElementById('cccode').className = 'inputcolor2';
			document.getElementById('expmonth').className = 'inputcolor2';
			document.getElementById('expyear').className = 'inputcolor2';
			document.getElementById('ccnoc').className = 'inputcolor2';
			
			document.getElementById('cctype').disabled = true;
			document.getElementById('ccardno').disabled = true;
			document.getElementById('cccode').disabled = true;
			document.getElementById('expmonth').disabled = true;
			document.getElementById('expyear').disabled = true;
			document.getElementById('ccnoc').disabled = true;
		}
	}