// drop-down combo-box
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// drop-down country combo-box
// under construction
// seek for document file name !!!
function SelectCountryMenu(targ,selObj,restore){ 
 var s = targ.location.href + "_" + selObj.options[selObj.selectedIndex].value;
 //targ.alert(s);
 targ.location = s;
 if (restore) selObj.selectedIndex=0;
}




// getElementById corrected for different browsers
function GetDocumentElementByID(objID) {
	// specify how an html element should be obtained based on different browser
	var ie = document.all;
	var dom = document.getElementById;
  if ( ie ) {
    return document.all[objID];
  }
  else if ( dom ) {
    return document.getElementById(objID);
  }
}


// empty input field validate
function nonEmptyInputValidate (id) {
	iField = GetDocumentElementByID(id);
	if ( iField.text.value != "" ){
		return true;
	}
	else {
		alert("Please enter data!");
		return false;
	}
}



// ***********************************
// Expandable Sections (see FAQs page )

function toggle(obj) {
// Moz. or IE
var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
// hide or show
if(sibling.style.display=='' || sibling.style.display=='block') {
	sibling.style.display='none';
    obj.firstChild.firstChild.setAttribute('src','images/a_right.gif');	
    }
else {
	sibling.style.display='block';
    obj.firstChild.firstChild.setAttribute('src','images/a_down.gif')
    }
}

function sectionExpand(obj) {
// Moz. or IE
var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
//  show
sibling.style.display='block';
obj.firstChild.firstChild.src='images/a_down.gif';
}

function sectionCollapse(obj) {
// Moz. or IE
var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
//  hide
sibling.style.display='none';
obj.firstChild.firstChild.src='images/a_right.gif';	

}

function ExpandAllSections(id) {
var oDT=GetDocumentElementByID(id).getElementsByTagName('dt');
for (var i=0; i < oDT.length; i++) { sectionExpand(oDT[i]); }
oDT==null;
}

function CollapseAllSections(id) {
var oDT=GetDocumentElementByID(id).getElementsByTagName('dt');
for (var i=0; i < oDT.length; i++) { sectionCollapse(oDT[i]); }
oDT=null;
}


function initCollapse(id) {
var oDT=GetDocumentElementByID(id).getElementsByTagName('dt');
for (var i=0; i < oDT.length; i++) {
	oDT[i].onclick=function() {toggle(this)};
    var oSpan=document.createElement('span');
    var sign=document.createElement('img');
	sign.src='images/a_right.gif';
    oSpan.appendChild(sign);
    oDT[i].insertBefore(oSpan, oDT[i].firstChild);
    toggle(oDT[i]);
	}
oDT=null;
}

// end of Expandable Sections (FAQs)
// ********************************



// ***********************************
// PopUp, Floating, Expanding elements


// Moves the box object to be directly beneath an object.
function move_box(an, box)
{
    var cleft = 0;
    var ctop = 0;
    var obj = an;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}


// Popup IFRAME window with content from link an.href
// an - link object
function popupIFrame(an, width, height, borderStyle)
{
    var href = an.href;
    var boxdiv = GetDocumentElementByID(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
            move_box(an, boxdiv);
            boxdiv.style.display='block';
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { popupIFrame(an, width, height, borderStyle); }
    close_href.appendChild(document.createTextNode('Close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.

    var contents = document.createElement('iframe');
    contents.scrolling = 'yes';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.appendChild(contents);

    move_box(an, boxdiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}












////////////////////////////////////////////////////////////////////////////////
/// @name ToggleOptionGroup
/// @desc toggle a search option group <DIV> on or off depending on its current state
///
/// @param groupID string - the ID of the group <DIV>
/// @param iconID string - the ID of the open/close arrow <IMG>
/// @param auto boolean - true if the script is being automatically opened (perhaps
/// programmaticly), false if the group is being manually toggled. For manual toggles,
/// the groups "state" (opened or closed) is stored in a cookie and remembered on
/// subsequent page views.
////////////////////////////////////////////////////////////////////////////////
function ToggleOptionGroup(groupID, iconID, auto){
	groupObj = GetDocumentElementByID(groupID);
	iconObj = GetDocumentElementByID(iconID);
	if ( groupObj.style.display == 'none' || !groupObj.style.display ){
		groupObj.style.display = 'block';
		iconObj.src = 'images/a_down.gif';
		if ( !auto ){ SetSearchOptionCookie(groupID, true) };
	} else {
		groupObj.style.display = 'none';
		iconObj.src = 'images/a_right.gif';
		if ( !auto ){ SetSearchOptionCookie(groupID, false) };
	}
}







////////////////////////////////////////////////////////////////////////////////
/// @name SetSearchOptionCookie
/// @desc store the current opened/closed state of a search option group <DIV>
/// in a cookie for the benefit of subsequent page views.
/// @see ToggleOptionGroup
///
/// @param groupID string - the ID of the group <DIV>
/// @param auto state - true if the group <DIV> is open, false if it is closed
////////////////////////////////////////////////////////////////////////////////
function SetSearchOptionCookie(groupID, state) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime()+3600000*24*30);
	if ( state ){
		stateString = 'on';
	} else {
		stateString = 'off';
	}
	document.cookie = "iStock_" + groupID + "=" + stateString +
	";path=/" +
	";expires="+expire.toGMTString() +
	";domain=.istockphoto.com" +
	";"						
}


/////////////////////////////////////////////
// block show 
// placeID - object to which divID is put after  

function ShowDiv(placeID,divID)
{	
    var boxbanner = GetDocumentElementByID(divID);
	var to_obj = GetDocumentElementByID(placeID);
    if (boxbanner == null) {
        return false;
	}
    move_box(to_obj, boxbanner); 
    boxbanner.style.display='block';
	return true;
}




///////////////////////////////////////// 
// Functions used by expanding banners
////////////////////////////////////////

function expandAsset(exp_name) {
	var exp = GetDocumentElementByID(exp_name);
	exp.style.clip = "rect(auto auto auto auto)";
}

function collapseAsset(exp_name,T,R,B,L) {
	var exp = GetDocumentElementByID(exp_name);
	var cl = "rect(" + T + "px " + R + "px " + B + "px " + L + "px)";
	exp.style.clip = cl; 
//	exp.style.clip = "rect(0px 30px 300px 0px)";
}

function banner_show(placeID,divID)
{	
    var boxbanner = GetDocumentElementByID(divID);
	var to_obj = GetDocumentElementByID(placeID);
    if (boxbanner == null) {
        return false;
	}
    move_box(to_obj, boxbanner); 
    boxbanner.style.display='block';
	return true;
}

// force expanding from html container
function expandWizard(wid) {
//  GetDocumentElementByID(wid).expandWizard();
    GetWizard(wid).expandWizard();
}

function GetWizard(wid) {
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	var w = (ie) ? window[wid] : document[wid];
	return w;
}







