﻿// JScript File
//infoWindow. iEnqType: 1 - Booking, 2 - Quote, 3 - Skype, 4 - SMS, 5 - Special1, 6 - Special2, 7 - Special3, 8 - Photo, 9 - SponsorAdd
//onclick=document.getElementById("frFace").src="../util/ServiceQuote.aspx?provid=2612&makeid=3&stype=1";jQuery.facebox({div:"#divIFrame"});
function showEnquiry(iEnqType, iProvID, iMakeID, iSType){
    var fr = document.getElementById("frFace");
    var div = document.getElementById("divIFrame");
    if (fr && div){
        switch(iEnqType)
        {
        case 1:
          fr.src = '/util/ServiceBooking.aspx?provid='+iProvID+'&makeid='+iMakeID+'&stype='+iSType;
          fr.style.width = '850px';
          fr.style.height = '400px';
          break;
        case 2:
          fr.src = '/util/ServiceQuote.aspx?provid='+iProvID+'&makeid='+iMakeID+'&stype='+iSType;
          fr.style.width = '400px';
          fr.style.height = '370px';
          break;
        case 3:
          fr.src = '/util/Skype.aspx?provid='+iProvID;
          fr.style.width = '600px';
          fr.style.height = '400px';
          break;
        case 4:
          fr.src = '/util/SMS.aspx?provid='+iProvID+'&makeid='+iMakeID+'&stype='+iSType;
          fr.style.width = '380px';
          fr.style.height = '300px';
          break;
        case 5:
          fr.src = '';
          break;  
        }
        jQuery.facebox({div:"#divIFrame"});
    }
}
//No spaces in sName
function OpenWindow(sURL, sName, iWidth, iHeght){
	var wnd=window.open(sURL,sName,'width=' + iWidth + ',height=' + iHeght,false);
	wnd.focus();
}

//No spaces in sName
function OpenWindowScroll(sURL, sName, iWidth, iHeight){
	var wnd=window.open(sURL,sName,'scrollbars=yes,top=20,left=20,width=' + iWidth + ',height=' + iHeight,false);
	wnd.focus();
}

function OpenRatingWindow(iProvID){
	var wnd=window.open('Rating2.aspx?ProvID=' + iProvID ,'Rating','scrollbars=yes,top=20,left=20,width=630,height=800',false);
	wnd.focus();
}

//Disable all elements on the form
function DisableAll()
{
	var count = document.forms[0].elements.length;
	for (i=0; i<count; i++) 
	 {
		var element = document.forms[0].elements[i]; 
	}
}

//Enable all elements on the form
function EnableAll()
{
	var count = document.forms[0].elements.length;
	for (i=0; i<count; i++) 
	 {
		var element = document.forms[0].elements[i]; 
		if (element != null) {element.disabled=false;};
	}
}

//Limit characters to enter to text field.
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
// onKeyPress="return numbersonly(this, event);"
function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789() -").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   //myfield.form.elements[dec].focus();
	   //return false;
	   }
	else
	   return false;
}

//Only digits:0-9
// onKeyPress="return digitsonly(this, event);"
function digitsonly(myfield, e, dec)
{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   //myfield.form.elements[dec].focus();
	   //return false;
	   }
	else
	   return false;
}

/*************** Client-side access to querystring name=value pairs ***************/
/* USAGE
// Parse the current page's querystring
var qs = new Querystring()
// Parse a given querystring
var qs2 = new Querystring("name1=value1&name2=value2")

var v1 = qs2.get("name1")
var v3 = qs2.get("name3", "default value")
if (qs2.contains("name1")){ alert(qs2.get("name1"));}
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}


//***Cross browser attach event function. For 'evt' pass a string value with the leading "on" omitted
//***e.g. AttachEvent(window,'load',MyFunctionNameWithoutParenthesis,false);
function AttachEvent(obj,evt,fnc,useCapture){
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 
function frameResize(width,height){
    //alert('frameResize');
    var fr = document.getElementById("frFace");
    if (fr){
        //alert('frameResize exists');
        if (width>0) fr.style.width = width + 'px';
        if (height>0) fr.style.height = height + 'px';
    }
}