﻿
function SEngine(Authority, QueryParamName){

	this.Authority		= Authority;
	this.QueryParamName	= QueryParamName;
}

function RParam(ParamName, ObjectName){

	this.ParamName	= ParamName;
	this.ObjectName	= ObjectName;
}

function OfferMiner(){

	this.SearchEngines		= new Array(new SEngine("google", "q"), new SEngine("bing", "q"), new SEngine("omreferrer", "q"));
	this.RequestParams		= new Array(new RParam("OM.siteID", "SiteID"), 
										new RParam("OM.uri", "URIPath"),
										new RParam("OM.domain", "Domain"), 
										new RParam("OM.rDomain", "ReferrerDomain"), 
										new RParam("OM.exVisitorID", "ExVisitorID"), 
										new RParam("OM.offerClick", "OfferClick"), 
										new RParam("OM.mailClick", "MailClick"), 
										new RParam("OM.pb", "ProductBasket"), 
										new RParam("OM.pp", "ProductPurchase"), 
										new RParam("OM.ppr", "ProductPrice"), 
										new RParam("OM.pv", "ProductView"), 
										new RParam("OM.q", "SEngineParam"), 
										new RParam("OM.OSB", "OnSiteBanner"), 
										new RParam("OM.OSS", "OnSiteSearch"), 
										new RParam("OM.PPC", "PPC"),
										new RParam("OM.pu", "ProductUnit"),
										new RParam("OM.cur", "Currency"),
										new RParam("OM.evt_t", "EventType"),
										new RParam("OM.inv", "InvoiceNo"),
										new RParam("OM.OSBD", "OnSiteBannerDisplay"),
										new RParam("OM.bid", "BasketID"),
										new RParam("OM.custom1", "Custom1"),
										new RParam("OM.custom2", "Custom2"),
										new RParam("OM.custom3", "Custom3"),
										new RParam("OM.custom4", "Custom4"),
										new RParam("OM.custom5", "Custom5"),
										new RParam("OM.custom6", "Custom6"),
										new RParam("OM.custom7", "Custom7"),
										new RParam("OM.custom8", "Custom8"),
										new RParam("OM.custom9", "Custom9"),
										new RParam("OM.custom10", "Custom10"),
										new RParam("OM.cat", "CategoryCode"),
										new RParam("OM.catn", "CategoryName"),
										new RParam("OM.pn", "ProductName"),
										new RParam("OM.brand", "BrandCode"),
										new RParam("OM.brandn", "BrandName"),
										new RParam("OM.CVA", "CustomVisitorAttrs"),
										new RParam("OM.goal", "Goal"),
										new RParam("OM.cparam1", "CParam1"),
										new RParam("OM.cparam2", "CParam2"),
										new RParam("OM.cparam3", "CParam3"),
										new RParam("OM.cparam4", "CParam4"),
										new RParam("OM.cparam5", "CParam5"),
										new RParam("OM.cparamValue", "CParamValue"),
										new RParam("OM.displayAd", "DisplayAd")
										);
														
	this.URI		= parseUri(document.location.href.toString());
	this.CookieID	= this.CheckCookie();
	
	if(document.referrer && document.referrer.toString() != "")
		this.ReferrerURI	= parseUri(document.referrer.toString());
	
	this.GetMETAParams();
	this.GetURIParams();
}

OfferMiner.prototype.EventType				= null;
OfferMiner.prototype.InvoiceNo				= null;
OfferMiner.prototype.OnSiteBannerDisplay	= null;
OfferMiner.prototype.BasketID				= null;
OfferMiner.prototype.SearchEngines			= null;
OfferMiner.prototype.SEngineParam			= null;
OfferMiner.prototype.Domain					= null;
OfferMiner.prototype.URIPath				= null;
OfferMiner.prototype.ReferrerDomain			= null;
OfferMiner.prototype.RequestParams			= null;
OfferMiner.prototype.Protocol				= null;
OfferMiner.prototype.SiteID					= "Ykemeklilik_Vas3gASez";
OfferMiner.prototype.CookieName				= "OfferMiner_ID";
OfferMiner.prototype.CappingCookieName		= "OfferMiner_Capping";
OfferMiner.prototype.CookieID				= null;
OfferMiner.prototype.ExVisitorID			= null;
OfferMiner.prototype.OfferClick				= null;
OfferMiner.prototype.MailClick				= null;
OfferMiner.prototype.ProductBasket			= null;
OfferMiner.prototype.ProductPurchase		= null;
OfferMiner.prototype.ProductPrice			= null;
OfferMiner.prototype.PPC					= null;
OfferMiner.prototype.ProductView			= null;
OfferMiner.prototype.DisplayAd				= null;
OfferMiner.prototype.OnSiteBanner			= null;
OfferMiner.prototype.OnSiteSearch			= null;
OfferMiner.prototype.OMServerURL			= "weblogger.visilabs.com/";
OfferMiner.prototype.OMGifName				= "om.gif";
OfferMiner.prototype.OMRuleGifName			= "com.gif";
OfferMiner.prototype.URI					= null;
OfferMiner.prototype.ReferrerURI			= null;
OfferMiner.prototype.URIParams				= "";
OfferMiner.prototype.RequestParams			= null;
OfferMiner.prototype.ProductUnit			= null;
OfferMiner.prototype.Currency				= null;
OfferMiner.prototype.DaysOfWeek				= new Array("Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi");
OfferMiner.prototype.Custom1				= null;
OfferMiner.prototype.Custom2				= null;
OfferMiner.prototype.Custom3				= null;
OfferMiner.prototype.Custom4				= null;
OfferMiner.prototype.Custom5				= null;
OfferMiner.prototype.Custom6				= null;
OfferMiner.prototype.Custom7				= null;
OfferMiner.prototype.Custom8				= null;
OfferMiner.prototype.Custom9				= null;
OfferMiner.prototype.Custom10				= null;
OfferMiner.prototype.CategoryCode			= null;
OfferMiner.prototype.CategoryName			= null;
OfferMiner.prototype.ProductName			= null;
OfferMiner.prototype.BrandCode				= null;
OfferMiner.prototype.BrandName				= null;
OfferMiner.prototype.CustomVisitorAttrs		= null;
OfferMiner.prototype.Goal					= null;
OfferMiner.prototype.CParam1				= null;
OfferMiner.prototype.CParam2				= null;
OfferMiner.prototype.CParam3				= null;
OfferMiner.prototype.CParam4				= null;
OfferMiner.prototype.CParam5				= null;
OfferMiner.prototype.CParamValue			= null;
OfferMiner.prototype.CappingTimeout			= 1;
OfferMiner.prototype.CappingTimeoutType		= "DAY";

OfferMiner.prototype.GetMETAParams = function(){

	var	METAs	= document.getElementsByTagName("meta");
		
	for(var j=0; j<METAs.length; j++){
	
		Found	= false;
	
		for(var i=0; i<this.RequestParams.length; i++){
		
			if(METAs[j].name == this.RequestParams[i].ParamName){
						
				eval("this." + this.RequestParams[i].ObjectName + "='" + METAs[j].content.split("'").join("\'") + "'");
				break;
			}
		}
	}
}

OfferMiner.prototype.GetURIParams = function(){

	var	Found;

	if(this.URI != null){
	
		for(var Key in this.URI.queryKey){
		
			Found	= false;
		
			for(var i=0; i<this.RequestParams.length; i++){
			
				if(Key == this.RequestParams[i].ParamName){
				
					Found	= true;
					eval("this." + this.RequestParams[i].ObjectName + "='" + this.URI.queryKey[Key].split("'").join("\'") + "'");
					break;
				}
			}
			
			if(!Found){
							
				this.URIParams	+= "&" + Key +"="+ encodeURIComponent(unescape(this.URI.queryKey[Key]));
			}
		}
	}
}

OfferMiner.prototype.WriteCookie = function(){

	var	cDate		= new Date();
	var	cValue		= cDate.getTime();
	var	Days		= 1000;
	var	_Domain		= this.URI.authority;

	if(this.Domain != null){
	
		_Domain	= this.Domain;
	}

	cDate.setTime(cDate.getTime() + (Days * 24 * 60 * 60 * 1000));
	document.cookie	= this.CookieName + "=" + cValue + "; expires=" + cDate.toGMTString() + "; path=/; domain=" + _Domain;
			
    var	CookieArr	= document.cookie.split(";");
    var	Value		= "";
              
    for(var i=0; i<CookieArr.length; i++){
            
        while(CookieArr[i].charAt(0) == " ")
			CookieArr[i]	= CookieArr[i].substring(1, CookieArr[i].length);

        if (CookieArr[i].indexOf(this.CookieName + "=") == 0)
            Value	= CookieArr[i].substring((this.CookieName + "=").length, CookieArr[i].length);
    }
		
	return Value;
};

OfferMiner.prototype.CheckCookie = function(){
	
    var	CookieArr	= document.cookie.split(";");
    var	Value		= null;
              
    for(var i=0; i<CookieArr.length; i++){
            
        while(CookieArr[i].charAt(0) == " ")
			CookieArr[i]	= CookieArr[i].substring(1, CookieArr[i].length);

        if (CookieArr[i].indexOf(this.CookieName + "=") == 0)
            Value	= CookieArr[i].substring((this.CookieName + "=").length, CookieArr[i].length);
    }
    
    if(Value == null || Value == ""){
    
		Value	= this.WriteCookie();
    }

    return Value;
};

OfferMiner.prototype.GetCookie = function(Name){

    var	CookieArr	= document.cookie.split(";");
    var	Val			= null;
    
    for(var i=0; i<CookieArr.length; i++){
            
        while(CookieArr[i].charAt(0) == " ")
			CookieArr[i]	= CookieArr[i].substring(1, CookieArr[i].length);

        if (CookieArr[i].indexOf(Name + "=") >= 0)
            Val	= CookieArr[i].substring((Name + "=").length, CookieArr[i].length);    
    }
    
    return Val;
};

OfferMiner.prototype.SetCookie = function(Name, Value, Timeout, TimeoutType){

	var	cDate		= new Date();
	var	cValue		= cDate.getTime();
	var	_Domain		= this.URI.authority;

	if(this.Domain != null){
	
		_Domain	= this.Domain;
	}

	if(TimeoutType == "DAY"){
		
		cDate.setTime(cDate.getTime() + (Timeout * 24 * 60 * 60 * 1000));
	}
	else{
	
		cDate.setTime(cDate.getTime() + (Timeout * 60 * 1000));
	}
		
	document.cookie	= Name + "=" + Value + "; expires=" + cDate.toGMTString() + "; path=/; domain=" + _Domain;
};

OfferMiner.prototype.CollectReferrerSearch = function(){

	var	ParamArr	= null;
	var	Value		= null;
	var	Resume		= false;
	var	ParamName	= null;
		
	for(var i=0; i<this.SearchEngines.length; i++){
	
		if(this.ReferrerURI.authority.indexOf(this.SearchEngines[i].Authority) != -1){
								
			Resume		= true;
			ParamName	= this.SearchEngines[i].QueryParamName;
			
			break;
		}
	}
				
	if(Resume && this.URI.query && this.URI.query != null){
	
		for(var Key in this.URI.queryKey){
										
			if(Key == ParamName){
			
				Value	= this.URI.queryKey[Key];
				break;
			}
		}
	}

	return Value;
}

OfferMiner.prototype.Recollect = function(Params){

	var	Img				= new Image();
	var	Dt				= new Date();
	var	Src				= null;
	
	Src	 = this.URI.protocol + "://" + this.OMServerURL + this.SiteID + "/" + this.OMGifName + "?OM.cookieID=" + this.CookieID + "&OM.siteID=" + this.SiteID;

	for(var i=0; i<Params.length; i++){
	
		Src	+= "&"+ Params[i][0] +"="+ PrepEncoded(Params[i][1]);
	}
	
	Src	+= "&OM.dat=" + Dt.toUTCString() + "-" + Dt.getMilliseconds();
	
	Img.src	= Src;	
};

OfferMiner.prototype.SendRequest = function(){

	var	Img				= new Image();
	var	Dt				= new Date();
	var	Src				= null;
	var	SEngineParam	= null;
	
	Src	 = this.URI.protocol + "://" + this.OMServerURL + this.SiteID + "/" + this.OMGifName + "?OM.cookieID=" + this.CookieID + "&OM.siteID=" + this.SiteID;
	Src	+= "&OM.resol=" + PrepEncoded(screen.width +"x"+ screen.height);
	
	if(this.CustomVisitorAttrs != null && this.CustomVisitorAttrs != "")
		Src	+= "&OM.CVA=" + PrepEncoded(this.CustomVisitorAttrs);
	
	if(this.Goal != null && this.Goal != "")
		Src	+= "&OM.goal=" + PrepEncoded(this.Goal);
	
	if(this.BrandCode != null && this.BrandCode != "")
		Src	+= "&OM.brand=" + PrepEncoded(this.BrandCode);
	
	if(this.BrandName != null && this.BrandName != "")
		Src	+= "&OM.brandn=" + PrepEncoded(this.BrandName);
	
	if(this.CategoryCode != null && this.CategoryCode != "")
		Src	+= "&OM.cat=" + PrepEncoded(this.CategoryCode);
	
	if(this.CategoryName != null && this.CategoryName != "")
		Src	+= "&OM.catn=" + PrepEncoded(this.CategoryName);
	
	if(this.ProductName != null && this.ProductName != "")
		Src	+= "&OM.pn=" + PrepEncoded(this.ProductName);
	
	if(this.Custom1 != null && this.Custom1 != "")
		Src	+= "&OM.custom1=" + PrepEncoded(this.Custom1);
	
	if(this.Custom2 != null && this.Custom2 != "")
		Src	+= "&OM.custom2=" + PrepEncoded(this.Custom2);
	
	if(this.Custom3 != null && this.Custom3 != "")
		Src	+= "&OM.custom3=" + PrepEncoded(this.Custom3);
	
	if(this.Custom4 != null && this.Custom4 != "")
		Src	+= "&OM.custom4=" + PrepEncoded(this.Custom4);
	
	if(this.Custom5 != null && this.Custom5 != "")
		Src	+= "&OM.custom5=" + PrepEncoded(this.Custom5);
	
	if(this.Custom6 != null && this.Custom6 != "")
		Src	+= "&OM.custom6=" + PrepEncoded(this.Custom6);
	
	if(this.Custom7 != null && this.Custom7 != "")
		Src	+= "&OM.custom7=" + PrepEncoded(this.Custom7);
	
	if(this.Custom8 != null && this.Custom8 != "")
		Src	+= "&OM.custom8=" + PrepEncoded(this.Custom8);
	
	if(this.Custom9 != null && this.Custom9 != "")
		Src	+= "&OM.custom9=" + PrepEncoded(this.Custom9);
	
	if(this.Custom10 != null && this.Custom10 != "")
		Src	+= "&OM.custom10=" + PrepEncoded(this.Custom10);
	
	if(this.CParam1 != null && this.CParam1 != "")
		Src	+= "&OM.cparam1=" + PrepEncoded(this.CParam1);
	
	if(this.CParam2 != null && this.CParam2 != "")
		Src	+= "&OM.cparam2=" + PrepEncoded(this.CParam2);
	
	if(this.CParam3 != null && this.CParam3 != "")
		Src	+= "&OM.cparam3=" + PrepEncoded(this.CParam3);
	
	if(this.CParam4 != null && this.CParam4 != "")
		Src	+= "&OM.cparam4=" + PrepEncoded(this.CParam4);
	
	if(this.CParam5 != null && this.CParam5 != "")
		Src	+= "&OM.cparam5=" + PrepEncoded(this.CParam5);
	
	if(this.CParamValue != null && this.CParamValue != "")
		Src	+= "&OM.cparamValue=" + PrepEncoded(this.CParamValue);
	
	if(this.ExVisitorID != null && this.ExVisitorID != "")
		Src	+= "&OM.exVisitorID=" + PrepEncoded(this.ExVisitorID);
	
	if(this.ReferrerDomain == null){
		
		if(this.ReferrerURI != null){
		
			Src	+= "&OM.rDomain=" + PrepEncoded(document.referrer);
		}
	}
	else{
	
		Src	+= "&OM.rDomain=" + PrepEncoded(this.ReferrerDomain);
	}
		
	if(this.SEngineParam == null){
	
		if(this.ReferrerURI != null){
		
			this.SEngineParam	= this.CollectReferrerSearch();
			
			if(this.SEngineParam != null && this.SEngineParam != "")
				Src	+= "&OM.q=" + PrepEncoded(this.SEngineParam);
		}
	}
	else{
	
		Src	+= "&OM.q=" + PrepEncoded(this.SEngineParam);
	}
	
	if(this.URIPath == null){
	
		if(this.URI != null)
			Src	+= "&OM.uri=" + PrepEncoded(this.URI.path);
	}
	else{
	
		Src	+= "&OM.uri=" + PrepEncoded(this.URIPath);
	}
	
	if(this.Domain == null){
	
		if(this.URI != null)
			Src	+= "&OM.domain=" + PrepEncoded(this.URI.authority);
	}
	else{
	
		Src	+= "&OM.domain=" + PrepEncoded(this.Domain);
	}
	
	if(this.OfferClick != null && this.OfferClick != "")
		Src	+= "&OM.offerClick=" + PrepEncoded(this.OfferClick);
	
	if(this.DisplayAd != null && this.DisplayAd != "")
		Src	+= "&OM.displayAd=" + PrepEncoded(this.DisplayAd);
	
	if(this.MailClick != null && this.MailClick != "")
		Src	+= "&OM.mailClick=" + PrepEncoded(this.MailClick);
	
	if(this.ProductBasket != null && this.ProductBasket != "")
		Src	+= "&OM.pb=" + PrepEncoded(this.ProductBasket);
	
	if(this.ProductPurchase != null && this.ProductPurchase != "")
		Src	+= "&OM.pp=" + PrepEncoded(this.ProductPurchase);
	
	if(this.ProductPrice != null && this.ProductPrice != "")
		Src	+= "&OM.ppr=" + PrepEncoded(this.ProductPrice);
	
	if(this.ProductUnit != null && this.ProductUnit != "")
		Src	+= "&OM.pu=" + PrepEncoded(this.ProductUnit);
	
	if(this.ProductView != null && this.ProductView != "")
		Src	+= "&OM.pv=" + PrepEncoded(this.ProductView);
	
	if(this.OnSiteBanner != null && this.OnSiteBanner != "")
		Src	+= "&OM.OSB=" + PrepEncoded(this.OnSiteBanner);
	
	if(this.OnSiteSearch != null && this.OnSiteSearch != "")
		Src	+= "&OM.OSS=" + PrepEncoded(this.OnSiteSearch);
	
	if(this.PPC != null && this.PPC != "")
		Src	+= "&OM.PPC=" + PrepEncoded(this.PPC);
	
	if(this.Currency != null && this.Currency != "")
		Src	+= "&OM.cur=" + PrepEncoded(this.Currency);
	
	if(this.EventType != null && this.EventType != "")
		Src	+= "&OM.evt_t=" + PrepEncoded(this.EventType);
	
	if(this.InvoiceNo != null && this.InvoiceNo != "")
		Src	+= "&OM.inv=" + PrepEncoded(this.InvoiceNo);
	
	if(this.OnSiteBannerDisplay != null && this.OnSiteBannerDisplay != "")
		Src	+= "&OM.OSBD=" + PrepEncoded(this.OnSiteBannerDisplay);
	
	if(this.BasketID != null && this.BasketID != "")
		Src	+= "&OM.bid=" + PrepEncoded(this.BasketID);
	
	if(document.cookie)
		Src	+= "&OM.cookie=" + PrepEncoded(document.cookie);
		
	if(this.URIParams != "")
		Src	+= this.URIParams;
			
	Src	+= "&OM.dat=" + Dt.toUTCString() + "-" + Dt.getMilliseconds();
	
	Img.src	= Src;	
};

OfferMiner.prototype.SendTargetDisplay = function(ZoneID, CampaignID, BannerID, RuleBody, RuleHead, RuleType, CappingID, Count){

	if(Count == null || Count == ""){
	
		Count	= "1";
	}

	this.SendTarget(ZoneID, CampaignID, BannerID, RuleBody, RuleHead, RuleType, "d", Count);
	
	if(CappingID != null && CappingID != ""){
	
		this.SetCapping(CappingID);
	}
};

OfferMiner.prototype.SendTargetClick = function(ZoneID, CampaignID, BannerID, RuleBody, RuleHead, RuleType){

	this.SendTarget(ZoneID, CampaignID, BannerID, RuleBody, RuleHead, RuleType, "c", "1");
};

OfferMiner.prototype.SendTarget = function(ZoneID, CampaignID, BannerID, RuleBody, RuleHead, RuleType, ActionType, Count){

	var	Img	= new Image();
	var	Dt	= new Date();
	var	Src	= null;
	
	Src	= this.URI.protocol + "://" + this.OMServerURL + this.SiteID + "/" + this.OMGifName + "?OM.cookieID="+ this.CookieID +"&OM.dat=" + Dt.toUTCString() + "-" + Dt.getMilliseconds() +"&OM."+ ActionType +"="+ Count +"&OM.uri=/om_evt.gif";
	
	if(ZoneID != null && ZoneID != "")
		Src	+= "&OM.zone=" + PrepEncoded(ZoneID);
	
	if(CampaignID != null && CampaignID != "")
		Src	+= "&OM.campaign=" + PrepEncoded(CampaignID);
	
	if(BannerID != null && BannerID != "")
		Src	+= "&OM.banner=" + PrepEncoded(BannerID);
	
	if(RuleBody != null && RuleBody != "")
		Src	+= "&OM.ruleBody=" + PrepEncoded(RuleBody);
	
	if(RuleHead != null && RuleHead != "")
		Src	+= "&OM.ruleHead=" + PrepEncoded(RuleHead);
	
	if(RuleType != null && RuleType != "")
		Src	+= "&OM.ruleType=" + PrepEncoded(RuleType);
	
	if (document.cookie)
        Src += "&OM.cookie=" + PrepEncoded(document.cookie);

    if (this.ExVisitorID != null && this.ExVisitorID != "")
        Src += "&OM.exVisitorID=" + PrepEncoded(this.ExVisitorID);
        
	Img.src	= Src;
};

OfferMiner.prototype.SetCapping = function(CappingID){

	var	CVal	= this.GetCapping();
	var	SVal	= null;
	var	Rows	= null;
	var	Cols	= null;
	var	Found	= false;
	var	TmpRow	= null;
	
	if(CVal != null && CVal != ""){
	
		Rows	= CVal.split("|");
		
		for(var i=0; i<Rows.length; i++){
		
			Cols	= Rows[i].split(",");
			
			if(Cols[0] == CappingID){
			
				Found	= true;
				Cols[1]	= (Number(Cols[1]) + 1).toString();
				TmpRow	= Cols[0] +","+ Cols[1];
			}
			else{
			
				TmpRow	= Rows[i];
			}
			
			if(SVal == null){
			
				SVal	= TmpRow;
			}
			else{
			
				SVal	+= "|"+ TmpRow;
			}
		}
		
		if(!Found){
		
			TmpRow	= CappingID +",1";
			
			if(SVal == null){
			
				SVal	= TmpRow;
			}
			else{
			
				SVal	+= "|"+ TmpRow;
			}
		}
	}
	else{
	
		SVal	= CappingID.toString() +",1";
	}
	
	if(SVal == null)
		SVal	= "";
	
	this.SetCookie(this.CappingCookieName, SVal, this.CappingTimeout, this.CappingTimeoutType);
};

OfferMiner.prototype.GetCapping = function(){

	return this.GetCookie(this.CappingCookieName);
};

OfferMiner.prototype.SendRuleClick = function(MiningRuleID, CustomRuleID){

	var	Img				= new Image();
	var	Dt				= new Date();
	var	Src				= null;
	
	Src		= this.URI.protocol + "://" + this.OMServerURL + this.SiteID + "/" + this.OMRuleGifName + "?OM.ruleID=" + MiningRuleID + "&OM.custRuleID="+ CustomRuleID +"&OM.dat=" + Dt.toUTCString() + "-" + Dt.getMilliseconds();
	Img.src	= Src;
};

OfferMiner.prototype.Collect = function(){

	this.SendRequest();
};

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

function PrepEncoded(S){

	var	_S	= S;
	
	try
	{
		_S	= decodeURIComponent(_S);
	}
	catch(Ex){}

	return encodeURIComponent(_S);
}
