﻿// Common Function

<!--



///////////////////////////////////////////////////

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function RegularTitle( FsTitle, FiWordCount )
{
    if (FsTitle == null ) return "";
    if (FsTitle.length <= FiWordCount) return FsTitle; else return FsTitle.substring(0, FiWordCount) + "...";
}

function RegularTitleWithNoDot( FsTitle, FiWordCount )
{
    if (FsTitle == null ) return "";
    if (FsTitle.length <= FiWordCount) return FsTitle; else return FsTitle.substring(0, FiWordCount);
}

function getXMLProperty( FDoc, FSectionName )
{
    var sReturn;
    var AKeyArray = FSectionName.split('.');
    var ANode = FDoc.documentElement;
    
    for( var i = 0; i < AKeyArray.length; i++ )
    {
        for( var j = 0; j < ANode.childNodes.length; j++ )
        {
            if( ANode.childNodes[ j ].nodeName == AKeyArray[ i ] )
            {
                if( ANode.childNodes[ j ].childNodes.length == 1 )
                {
                    sReturn = ANode.childNodes[ j ].text;

                }
                else
                {
                    ANode = ANode.childNodes[ j ];
                    break;
                }
            }
        }
    }
        
    return sReturn;
}

function FormatFloat( FValue, FSize ) 
{ 
    var AValue = FValue * Math.pow( 10, FSize ); 
    AValue = Math.round( AValue + 0.000000001 ); 
    AValue = AValue / Math.pow( 10, FSize ); 
    return AValue; 
}

function FillString( FString, FChar, FCount, FIsLeft )
{
    FString = FString.toString();
    if ( FString.length == FCount ) return FString;
    while( FString.length < FCount )
    {
        if ( FIsLeft == 1 )
            FString = FChar + FString;
        else
            FString = FString + FChar;
    }
    return FString;
}

function MakeOneRandomNum( FiUp, FiLow )
{
    var iResult = 0;
    
    iResult = parseInt( ( FiUp - FiLow + 1 ) * Math.random() + FiLow );
    return iResult;
}

String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
    return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
    return this.replace(/(\s*$)/g, ""); 
}

function BeginWaiting( iLeft, iTop, sTitle )
{
    document.getElementById( "divWait" ).style.left=iLeft;
    document.getElementById( "divWait" ).style.top=iTop;
    document.getElementById( "divMessageCaption" ).innerHTML=sTitle;    
    document.getElementById( "divWait" ).style.display="block";
}

function EndWaiting( )
{    
    document.getElementById( "divWait" ).style.display="none";
}

function PopupWin( FWidth, FHeight, FURL, FName )
{
	var AWidth = screen.width;
	var AHeight = screen.height;
	var ALeft = ( AWidth - FWidth - 10 ) * .5;
	var ATop = ( AHeight - FHeight - 30 ) * .5;
	var AFeatures = "location=no, menubar=no, resizable=yes, status=no, toolbar=no, scrollbars=no, " + 
					"width=" + FWidth + ", " + "height=" + FHeight + ", " + 
					"left=" + ALeft + ", " + "top=" + ATop;
	
	window.open( FURL, FName, AFeatures );
}

function isWhiteWpace ( s )
{
	var whitespace = " |*,\t\n\r";
	var i;
	for ( i = 0; i < s.length; i++ ){   
		var c = s.charAt( i );
		if ( whitespace.indexOf( c ) >= 0 ) {
			return true;
		}
	}
	return false;
}

String.prototype.IsValidEmail = function()   
    {   
  return (/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(this.Trim()));     
    }   
function searchs(){
	_s=document.getElementById("search");
	if(_s.value.Trim()!=""&&_s.value.Trim()!="No Input"){
 	window.location.href="shop.php?search="+_s.value.Trim();
	}else{
	_s.value="No Input";
	}
}
function clearinput( s ){
	if(s.value=="No Input"){
		s.value="";
	}
}
function newsletter(){
	_s=document.getElementById("Newsletter");
	if(_s == null)
	_s=document.getElementById("newsletter");	
	if(_s.value.Trim()!=""&&_s.value.Trim()!="No Input"){
		    if(!_s.value.Trim().IsValidEmail()){
		        alert("Please input the correct email address!");
		        _s.focus();
		        return;
	        }
 			var _XH = GetXmlHttpObject();
				if (_XH==null)
				{
					alert ("Your browser does not support AJAX!");
					return;
				} 

            var _URL = "setnewsletter.php?search=" + _s.value.Trim();
            try
            {
	           _XH.open( "GET", _URL, false ); 
		       _XH.send( null );
		       var _RstText = unescape(_XH.responseText);
			   var _RstArray = _RstText.split( "|" );
			   
			   if(_RstArray[1]=="success"){
				   alert('You have been successfully subscribed for our newsletter!');
				   suset(_RstArray[0]);
				   return;
			   }else{
				   alert('You have not been subscribed for our newsletter!');
				   unsuset(_RstArray[0])
				   return;
			   }
			   
			}catch( e ) 
            {
				alert(e);
            }
	}else{
	_s.value="No Input";
	}
}
function suset(s){
	alert(s);
	 return;
}
function unsuset(s){
	alert(s);
	 return;
}
-->
